mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
refactor
to only have one read state updater js codeblock
This commit is contained in:
parent
93f9fe9684
commit
d34aa04c7d
@ -216,19 +216,7 @@ function openNotificationPanel() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$(center_ref).on('click', '.notification-read', function() {
|
$(center_ref).on('click', '.notification-read', function() {
|
||||||
caller = $(this);
|
updateNotificationReadState($(this), true);
|
||||||
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()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,3 +224,33 @@ function openNotificationPanel() {
|
|||||||
function closeNotificationPanel() {
|
function closeNotificationPanel() {
|
||||||
$('#notification-center').html(`<p class='text-muted'>{% trans "Notifications will load here" %}</p>`);
|
$('#notification-center').html(`<p class='text-muted'>{% trans "Notifications will load here" %}</p>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -98,24 +98,7 @@ function loadNotificationTable(table, options={}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(table).on('click', '.notification-read', function() {
|
$(table).on('click', '.notification-read', function() {
|
||||||
var url = `/api/notifications/${$(this).attr('pk')}/${$(this).attr('target')}/`;
|
updateNotificationReadState($(this));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user