src/pyams_notify/skin/resources/js/pyams_notify.js
changeset 14 1c9f8ee7c072
parent 4 9698e6853781
child 39 c9faf9e5a2d8
equal deleted inserted replaced
13:c05c7737c8da 14:1c9f8ee7c072
   126 			PyAMS_notify.createNotification(data).prependTo(notifications);
   126 			PyAMS_notify.createNotification(data).prependTo(notifications);
   127 			MyAMS.skin.checkNotification();
   127 			MyAMS.skin.checkNotification();
   128 		},
   128 		},
   129 
   129 
   130 		showNotifications: function(data) {
   130 		showNotifications: function(data) {
       
   131 			var timestamp = data.timestamp,
       
   132 				notifications_data = data.notifications;
       
   133 			/* create notifications */
   131 			var badge = $('.badge', '#user-activity >span');
   134 			var badge = $('.badge', '#user-activity >span');
   132 			badge.text(data.length);
       
   133 			var notifications = $('.notification-body', '#user-activity');
   135 			var notifications = $('.notification-body', '#user-activity');
       
   136 			var old_length = $('li', notifications).length;
   134 			notifications.empty();
   137 			notifications.empty();
   135 			if (data.length > 0) {
   138 			if (notifications_data.length > 0) {
   136 				notifications.prev('p').hide();
   139 				notifications.prev('p').hide();
   137 				for (var index = 0; index < data.length; index++) {
   140 				for (var index = 0; index < notifications_data.length; index++) {
   138 					var notification = data[index];
   141 					var notification = notifications_data[index];
   139 					PyAMS_notify.createNotification(notification).appendTo(notifications);
   142 					PyAMS_notify.createNotification(notification).appendTo(notifications);
   140 				}
   143 				}
       
   144 				var new_length = $('li', notifications).length;
       
   145 				badge.text(new_length - old_length);
   141 			} else {
   146 			} else {
   142 				notifications.prev('p').show();
   147 				notifications.prev('p').show();
       
   148 				badge.text('');
   143 			}
   149 			}
       
   150 			/* update timestamp */
       
   151 			var last_update = $('#activity-update');
       
   152 			last_update.text(last_update.data('ams-base-label').replace(/\{0\}/, timestamp));
       
   153 			/* check notifications badge */
   144 			MyAMS.skin.checkNotification();
   154 			MyAMS.skin.checkNotification();
   145 		},
   155 		},
   146 
   156 
   147 		refreshNotifications: function() {
   157 		refreshNotifications: function() {
   148 			return function() {
   158 			return function() {