diff --git a/InvenTree/InvenTree/static/script/inventree/notification.js b/InvenTree/InvenTree/static/script/inventree/notification.js index 5f9b35c9e2..00ce07afb3 100644 --- a/InvenTree/InvenTree/static/script/inventree/notification.js +++ b/InvenTree/InvenTree/static/script/inventree/notification.js @@ -216,19 +216,7 @@ function openNotificationPanel() { ); $(center_ref).on('click', '.notification-read', function() { - caller = $(this); - var url = `/api/notifications/${caller.attr('pk')}/${caller.attr('target')}/`; - - inventreePut(url, {}, { - method: 'POST', - success: function() { - // update the notification tables if they exsist - if (window.updateNotifications) { - window.updateNotifications(); - } - caller.parent().parent().remove() - } - }); + updateNotificationReadState($(this), true); }); } @@ -236,3 +224,33 @@ function openNotificationPanel() { function closeNotificationPanel() { $('#notification-center').html(`
{% trans "Notifications will load here" %}
`); } + + +function updateNotificationReadState(btn, panel_caller=false) { + var url = `/api/notifications/${btn.attr('pk')}/${btn.attr('target')}/`; + + inventreePut(url, {}, { + method: 'POST', + success: function() { + // update the notification tables if they exsist + if (window.updateNotifications) { + window.updateNotifications(); + } + + // update current notification count + var count = parseInt($("#notification-counter").html()); + if (btn.attr('target') == 'read') { + count = count - 1; + } else { + count = count + 1; + } + // update notification indicator now + updateNotificationIndicator(count); + + // remove notification if in panel + if (panel_caller) { + btn.parent().parent().remove() + } + } + }); +}; diff --git a/InvenTree/templates/InvenTree/notifications/notifications.html b/InvenTree/templates/InvenTree/notifications/notifications.html index e6f73db356..e6b15a9ff0 100644 --- a/InvenTree/templates/InvenTree/notifications/notifications.html +++ b/InvenTree/templates/InvenTree/notifications/notifications.html @@ -98,24 +98,7 @@ function loadNotificationTable(table, options={}) { }); $(table).on('click', '.notification-read', function() { - var url = `/api/notifications/${$(this).attr('pk')}/${$(this).attr('target')}/`; - - inventreePut(url, {}, { - method: 'POST', - success: function() { - updateNotificationTables(); - - // update current notification count - var count = parseInt($("#notification-counter").html()); - if ($(this).attr('target') == 'read') { - count = count - 1; - } else { - count = count + 1; - } - // update notification indicator now - updateNotificationIndicator(count); - } - }); + updateNotificationReadState($(this)); }); }