diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index 8bbb2aa918..1182552bf8 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -220,11 +220,13 @@ function inventreeDocReady() { // Start notification background worker to check every 5 seconds if notifications are available setInterval(notificationCheck, 5000); - // also run when the focus returns $(document).on('focus', function(e){ notificationCheck(); }); + + $('#offcanvasRight').on('show.bs.offcanvas', openNotificationPanel) // listener for opening the notification panel + $('#offcanvasRight').on('hidden.bs.offcanvas', closeNotificationPanel) // listener for closing the notification panel } diff --git a/InvenTree/InvenTree/static/script/inventree/notification.js b/InvenTree/InvenTree/static/script/inventree/notification.js index 6c8ab623ac..a2ef25f6ab 100644 --- a/InvenTree/InvenTree/static/script/inventree/notification.js +++ b/InvenTree/InvenTree/static/script/inventree/notification.js @@ -143,4 +143,53 @@ function showMessage(message, options={}) { } ); } -} \ No newline at end of file +} + + +function openNotificationPanel() { + var html = ''; + + inventreeGet( + '/api/notifications/', + { + read: false, + }, + { + success: function(response) { + if (response.length == 0) { + html = `

{% trans "No unread notifications" %}

`; + } else { + // build up items + response.forEach(function(item, index) { + html += '
  • '; + // d-flex justify-content-between align-items-start + html += '
    '; + html += `${item.category}${item.name}`; + html += '
    '; + if (item.target) { + var link_text = `${item.target.model}: ${item.target.name}`; + if (item.target.link) { + link_text = `${link_text}`; + } + html += link_text + } + html += '
    '; + html += `${item.age_human}`; + html += "
  • "; + }); + + // package up + html = `` + } + + // set html + $('#notification-center').html(html); + } + } + ); +} + + +function closeNotificationPanel() { + $('#notification-center').html(`

    {% trans "Notifications will load here" %}

    `); +}