(function ($, document, Dashboard, LibraryBrowser) { function notifications() { var self = this; self.getNotificationsSummaryPromise = null; self.total = 0; self.getNotificationsSummary = function () { var apiClient = window.ApiClient; if (!apiClient) { return; } self.getNotificationsSummaryPromise = self.getNotificationsSummaryPromise || apiClient.getNotificationSummary(Dashboard.getCurrentUserId()); return self.getNotificationsSummaryPromise; }; self.updateNotificationCount = function () { if (!Dashboard.getCurrentUserId()) { return; } var promise = self.getNotificationsSummary(); if (!promise) { return; } promise.done(function (summary) { var item = $('.btnNotificationsInner').removeClass('levelNormal').removeClass('levelWarning').removeClass('levelError').html(summary.UnreadCount); if (summary.UnreadCount) { item.addClass('level' + summary.MaxUnreadNotificationLevel); } }); }; self.showNotificationsFlyout = function () { Dashboard.getCurrentUser().done(function (user) { var html = '
' + Globalize.translate('LabelNoUnreadNotifications') + '
'); if (btn) { btn.hide(); } return; } Notifications.total = totalRecordCount; if (btn) { if (list.filter(function (n) { return !n.IsRead; }).length) { btn.show(); } else { btn.hide(); } } var html = ''; if (totalRecordCount > limit && showPaging === true) { var query = { StartIndex: startIndex, Limit: limit }; html += LibraryBrowser.getPagingHtml(query, totalRecordCount, false, limit, false); } for (var i = 0, length = list.length; i < length; i++) { var notification = list[i]; html += getNotificationHtml(notification); } elem.html(html).trigger('create'); } function getNotificationHtml(notification) { var html = ''; var cssClass = notification.IsRead ? "flyoutNotification" : "flyoutNotification unreadFlyoutNotification"; html += ''; if (notification.Url) { html += '' + notification.Name + ''; } else { html += notification.Name; } html += '
'; html += '' + humane_date(notification.Date) + '
'; if (notification.Description) { html += ' '; } html += '