Skip to content

Commit

Permalink
Merge pull request #912 from josaphatim/countdown-for-servers
Browse files Browse the repository at this point in the history
Fix servers count on server deletion
  • Loading branch information
kroky authored Feb 20, 2024
2 parents a8ebf9b + 262710e commit 700204e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,13 @@ var reset_default_value_input = function() {
}
};

var decrease_servers = function(section) {
const element = document.querySelector(`.${section}_server_setup .server_count`);
const parts = element.innerHTML.split(' ');
parts[0] = Number(parts[0]) - 1;
element.innerHTML = parts.join(' ');
};

/* create a default message list object */
var Hm_Message_List = new Message_List();

Expand Down
2 changes: 1 addition & 1 deletion modules/feeds/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
'feed_msg_text' => array(FILTER_UNSAFE_RAW, false),
),
'allowed_post' => array(
'feed_id' => FILTER_VALIDATE_INT,
'feed_id' => FILTER_DEFAULT,
'delete_feed' => FILTER_VALIDATE_INT,
'feed_connect' => FILTER_VALIDATE_INT,
'feed_server_ids' => FILTER_DEFAULT,
Expand Down
5 changes: 3 additions & 2 deletions modules/feeds/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ var feed_delete_action = function(event) {
Hm_Ajax.request(
form.serializeArray(),
function(res) {
if (res.deleted_server_id > -1 ) {
if (res.deleted_server_id) {
Hm_Utils.set_unsaved_changes(1);
Hm_Folders.reload_folders(true);
form.parent().remove();
form.parent().parent().remove();
decrease_servers('feed');
}
},
{'delete_feed': 1}
Expand Down
7 changes: 5 additions & 2 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ var imap_delete_action = function(event) {
Hm_Ajax.request(
form.serializeArray(),
function(res) {
if (res.deleted_server_id > -1 ) {
form.parent().remove();
if (res.deleted_server_id) {
const configured_server = form.closest('.configured_server');
const section = configured_server.parent().parent()[0].classList.contains('imap_section') ? 'imap': 'jmap';
decrease_servers(section);
configured_server.remove();
Hm_Utils.set_unsaved_changes(1);
Hm_Folders.reload_folders(true);
}
Expand Down
5 changes: 3 additions & 2 deletions modules/smtp/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ var smtp_delete_action = function(event) {
form.serializeArray(),
function(res) {
Hm_Notices.show(res.router_user_msgs);
if (res.deleted_server_id > -1 ) {
form.parent().remove();
if (res.deleted_server_id) {
form.parent().parent().remove();
Hm_Utils.set_unsaved_changes(1);
Hm_Folders.reload_folders(true);
decrease_servers('smtp');
}
},
{'smtp_delete': 1}
Expand Down

0 comments on commit 700204e

Please sign in to comment.