diff --git a/src/scripts/tutti/5_notifications.js b/src/scripts/tutti/5_notifications.js index e1831ee4..e1f19982 100644 --- a/src/scripts/tutti/5_notifications.js +++ b/src/scripts/tutti/5_notifications.js @@ -2,125 +2,102 @@ // Store the title, to later append notifications count var page_title = document.title; -var unread_on_load = 0; -var unread_new = 0; -var first_load = false; +/** + * Adds a new notification to the top of the notification list. + */ +function addNotification(no) { + var $notifications_list = $('#notifications-list'); -// getNotifications by fetching json every X seconds -function getNotifications(){ - $.getJSON( "/notifications/", function( data ) { + // There is a notification to be shown, so remove any "no notifications yet" message. + $notifications_list.find('li.nc-item-empty').remove(); - if (!first_load) { - unread_on_load = data['items'].length; - first_load = true; - } - - var items = []; - unread_new = 0; - - // Only if there's actual data - if (data['items'][0]){ - - // Loop through each item - $.each(data['items'], function(i, no){ - - // Increase the unread_new counter - if (!no['is_read']){ unread_new++ }; - - // Check if the current item has been read, to style it - var is_read = no['is_read'] ? 'is_read' : ''; - - var read_info = 'data-id="'+ no['_id'] + '" data-read="' + no['is_read'] + '"'; - - // Notification list item - var content = '