Skip to content

Commit

Permalink
Merge pull request cypht-org#927 from josaphatim/fixed-notifications-…
Browse files Browse the repository at this point in the history
…from-ajax-not-showing

Notifications not showing from ajax requests
  • Loading branch information
kroky authored Mar 18, 2024
2 parents 02bbabc + 16a8171 commit 9594cd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
29 changes: 15 additions & 14 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ var Hm_Notices = {
clearTimeout(Hm_Notices.hide_id);
}
if (now) {
$('.sys_messages').hide();
$('.sys_messages').html('');
$('.sys_messages').addClass('d-none');
Hm_Utils.clear_sys_messages();
}
else {
Hm_Notices.hide_id = setTimeout(function() {
$('.sys_messages').hide();
$('.sys_messages').html('');
$('.sys_messages').addClass('d-none');
Hm_Utils.clear_sys_messages();
}, 5000);
}
}
Expand Down Expand Up @@ -1603,15 +1603,19 @@ var Hm_Utils = {
/**
*
* @param {*} msg : The alert message to display
* @param {*} type : The type of message to display, depending on the type of boostrap5 alert (primary, secondary, success, danger, warning, info, light, dark )
* @param {*} pending : Defined if the added message must be displayed directly, or be pending until the show_sys_messages method is called
* @param {*} type : The type of message to display, depending on the type of boostrap5 alert (primary, secondary, success, danger, warning, info, light, dark )
*/
add_sys_message: function(msg, type = 'info', pending = false) {
if (pending) $('.sys_messages').addClass('d-none');
else Hm_Utils.show_sys_messages();
if (!msg || msg == '') return $('.sys_messages').html('');
add_sys_message: function(msg, type = 'info') {
if (!msg) {
return;
}
const icon = type == 'success' ? 'bi-check-circle' : 'bi-exclamation-circle';
return $('.sys_messages').append('<div class="alert alert-'+type+' alert-dismissible fade show" role="alert"><i class="bi '+icon+' me-2"></i><span class="' + type + '">'+msg+'</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>');
$('.sys_messages').append('<div class="alert alert-'+type+' alert-dismissible fade show" role="alert"><i class="bi '+icon+' me-2"></i><span class="' + type + '">'+msg+'</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>');
this.show_sys_messages();
},

clear_sys_messages: function () {
$('.sys_messages').html('');
},

cancel_logout_event: function() {
Expand Down Expand Up @@ -1868,9 +1872,6 @@ $(function() {
/* check for folder reload */
var reloaded = Hm_Folders.reload_folders();

/* show any pending notices */
Hm_Utils.show_sys_messages();

/* setup a few page wide event handlers */
Hm_Utils.cancel_logout_event();
Hm_Folders.toggle_folders_event();
Expand Down
2 changes: 1 addition & 1 deletion modules/sievefilters/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ $(function () {
return false;
}

Hm_Utils.add_sys_message();
Hm_Utils.clear_sys_messages();
conditions.forEach(function (elem, key) {
if (conditions_value[idx] === "" && conditions_value[idx] !== 'none') {
let order = ordinal_number(key + 1);
Expand Down
7 changes: 4 additions & 3 deletions modules/smtp/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ var smtp_test_action = function(event) {
Hm_Notices.hide(true);
Hm_Ajax.request(
form.serializeArray(),
function(res) {
Hm_Notices.show(res.router_user_msgs);
},
false,
{'smtp_connect': 1}
);
};
Expand Down Expand Up @@ -423,6 +421,9 @@ var force_send_message = function() {
}

$(function () {
if (!hm_is_logged()) {
return;
}
if (hm_page_name() === 'settings') {
$('#clear_chunks_button').on('click', function(e) {
e.preventDefault();
Expand Down

0 comments on commit 9594cd2

Please sign in to comment.