ntopng/httpdocs/js/utils/blog-notification-utils.js
gabryon99 24f054f009 add missing username for blog notifications (#5422)
The notifications backend it worked fine, but the frontend was missing the username variable to be in able to display the 'New' badge correctly
2021-05-31 10:25:54 +02:00

34 lines
No EOL
979 B
JavaScript

/* Handle Blog Notifications */
$(function () {
function blogNotifcationClick(e) {
if (e.type == "mousedown" && (e.metaKey || e.ctrlKey || e.which !== 2)) return;
const id = $(this).data('id');
$.post(`${http_prefix}/lua/update_blog_posts.lua`, {
blog_notification_id: id,
csrf: window.__BLOG_NOTIFICATION_CSRF__
},
(data) => {
if (data.success) {
$(this).off('click').off('mousedown').attr('data-read', 'true').data('read', 'true').find('.badge').remove();
const count = $(`.blog-notification[data-read='false']`).length;
if (count == 0) {
$('.notification-bell').remove();
}
else {
$('.notification-bell').html(count);
}
}
});
}
// on the notifications not yet read delegate the click event
$(`.blog-notification[data-read='false']`).on('click', blogNotifcationClick).on('mousedown', blogNotifcationClick);
});