src/pyams_notify/skin/resources/js/pyams_notify.js
changeset 14 1c9f8ee7c072
parent 4 9698e6853781
child 39 c9faf9e5a2d8
--- a/src/pyams_notify/skin/resources/js/pyams_notify.js	Wed Jul 12 12:11:25 2017 +0200
+++ b/src/pyams_notify/skin/resources/js/pyams_notify.js	Wed Jul 12 12:11:43 2017 +0200
@@ -128,19 +128,29 @@
 		},
 
 		showNotifications: function(data) {
+			var timestamp = data.timestamp,
+				notifications_data = data.notifications;
+			/* create notifications */
 			var badge = $('.badge', '#user-activity >span');
-			badge.text(data.length);
 			var notifications = $('.notification-body', '#user-activity');
+			var old_length = $('li', notifications).length;
 			notifications.empty();
-			if (data.length > 0) {
+			if (notifications_data.length > 0) {
 				notifications.prev('p').hide();
-				for (var index = 0; index < data.length; index++) {
-					var notification = data[index];
+				for (var index = 0; index < notifications_data.length; index++) {
+					var notification = notifications_data[index];
 					PyAMS_notify.createNotification(notification).appendTo(notifications);
 				}
+				var new_length = $('li', notifications).length;
+				badge.text(new_length - old_length);
 			} else {
 				notifications.prev('p').show();
+				badge.text('');
 			}
+			/* update timestamp */
+			var last_update = $('#activity-update');
+			last_update.text(last_update.data('ams-base-label').replace(/\{0\}/, timestamp));
+			/* check notifications badge */
 			MyAMS.skin.checkNotification();
 		},