}
});
-/**
- * Loads notification for the user panel.
- *
- * @see WCF.UserPanel
- */
-WCF.Notification.UserPanel = WCF.UserPanel.extend({
- /**
- * Favico object
- * @var Favico
- */
- _favico: null,
-
- /**
- * action proxy
- * @var WCF.Action.Proxy
- */
- _proxy: null,
-
- /**
- * link to show all notifications
- * @var string
- */
- _showAllLink: '',
-
- /**
- * @see WCF.UserPanel.init()
- */
- init: function(showAllLink) {
- this._favico = null;
-
- try {
- this._favico = new Favico({
- animation: 'none',
- type: 'circle',
- });
- }
- catch (e) { /* ignore for now */ }
-
- this._noItems = 'wcf.user.notification.noMoreNotifications';
- this._proxy = new WCF.Action.Proxy({
- success: $.proxy(this._success, this)
- });
- this._showAllLink = showAllLink;
-
- this._super('userNotifications');
-
- // update page title
- if (this._container.data('count') && this._favico !== null) {
- this._favico.badge(this._container.data('count'));
- }
-
- WCF.System.PushNotification.addCallback('userNotificationCount', $.proxy(this.updateUserNotificationCount, this));
- },
-
- /**
- * @see WCF.UserPanel._addDefaultItems()
- */
- _addDefaultItems: function(dropdownMenu) {
- this._addDivider(dropdownMenu);
- $('<li><a href="' + this._showAllLink + '">' + WCF.Language.get('wcf.user.notification.showAll') + '</a></li>').appendTo(dropdownMenu);
- this._addDivider(dropdownMenu);
- $('<li id="userNotificationsMarkAllAsConfirmed"><a>' + WCF.Language.get('wcf.user.notification.markAllAsConfirmed') + '</a></li>').click($.proxy(this._markAllAsConfirmed, this)).appendTo(dropdownMenu);
- },
-
- /**
- * @see WCF.UserPanel._getParameters()
- */
- _getParameters: function() {
- return {
- actionName: 'getOutstandingNotifications',
- className: 'wcf\\data\\user\\notification\\UserNotificationAction'
- };
- },
-
- /**
- * @see WCF.UserPanel._click()
- */
- _click: function(event) {
- if (this._didLoad) {
- var $badge = this._container.find('.badge');
- if ($badge.length && parseInt($badge.text()) > 0) {
- var $dropdownMenu = WCF.Dropdown.getDropdownMenu(this._container.wcfIdentify());
-
- // check if there is at least one unconfirmed item
- var $count = $dropdownMenu.children('li.notificationUnconfirmed').length;
- if (!$count && $count != $badge.text() && !$dropdownMenu.is(':visible')) {
- this._resetList();
-
- this._super(event);
- }
- }
- }
- else {
- this._super(event);
- }
- },
-
- /**
- * @see WCF.UserPanel._after()
- */
- _after: function(dropdownMenu) {
- var $items = WCF.Dropdown.getDropdownMenu(this._container.wcfIdentify()).children('li.jsNotificationItem');
-
- var $insertAfter = null;
- $items.each((function(index, item) {
- var $item = $(item);
- var $isConfirmed = $item.data('isConfirmed');
-
- if (!$.browser.msie) {
- $item.addClass('notificationItemLink');
- $('<a href="' + ($isConfirmed ? $item.data('link') : $item.data('confirmLink')) + '" />').appendTo($item);
- }
-
- if (!$isConfirmed) {
- $item.find('a:not(.userLink)').prop('href', $item.data('confirmLink'));
-
- if (!$.browser.mobile) {
- var $markAsConfirmed = $('<a href="#" class="icon icon24 fa-check green notificationItemMarkAsConfirmed jsTooltip" title="' + WCF.Language.get('wcf.user.notification.markAsConfirmed') + '" />').prependTo($item.find('> span.box24 > .framed'));
- $markAsConfirmed.click($.proxy(this._markAsConfirmed, this));
- }
- }
-
- if (!$item.data('isConfirmed')) {
- $insertAfter = $item;
- }
-
- $item.click(function(event) {
- if (event.target.tagName !== 'A') {
- window.location = $item.data('link');
- }
- });
- }).bind(this));
-
- if ($insertAfter !== null) {
- // check if it is followed by a confirmed item
- if ($insertAfter.next('.notificationItem').length) {
- $('<li class="dropdownDivider" />').insertAfter($insertAfter);
- }
- }
-
- var $badge = this._container.find('.badge');
- if (!$badge.length) {
- this._removeMarkAllAsConfirmed();
- }
- },
-
- /**
- * Marks a notification as confirmed.
- *
- * @param object event
- */
- _markAsConfirmed: function(event) {
- event.preventDefault();
-
- var $notificationID = $(event.currentTarget).parents('.notificationItem:eq(0)').data('notificationID');
-
- this._proxy.setOption('data', {
- actionName: 'markAsConfirmed',
- className: 'wcf\\data\\user\\notification\\UserNotificationAction',
- objectIDs: [ $notificationID ]
- });
- this._proxy.sendRequest();
-
- return false;
- },
-
- /**
- * Marks all notifications as confirmed.
- */
- _markAllAsConfirmed: function() {
- WCF.System.Confirmation.show(WCF.Language.get('wcf.user.notification.markAllAsConfirmed.confirmMessage'), $.proxy(function(action) {
- if (action === 'confirm') {
- this._proxy.setOption('data', {
- actionName: 'markAllAsConfirmed',
- className: 'wcf\\data\\user\\notification\\UserNotificationAction'
- });
- this._proxy.sendRequest();
- }
- }, this));
- },
-
- /**
- * @see WCF.UserPanel._success()
- */
- _success: function(data, textStatus, jqXHR) {
- switch (data.actionName) {
- case 'markAsConfirmed':
- WCF.Dropdown.getDropdownMenu(this._container.wcfIdentify()).children('li.jsNotificationItem').each(function(index, item) {
- var $item = $(item);
- if ($item.data('notificationID') == data.returnValues.notificationID) {
- $item.data('isConfirmed', true);
- $item.find('.notificationItemMarkAsConfirmed').remove();
- $item.find('.newContentBadge').remove();
- $item.removeClass('notificationUnconfirmed');
-
- return false;
- }
- });
-
- this._updateBadge(data.returnValues.totalCount);
- break;
-
- case 'markAllAsConfirmed':
- this._resetList();
-
- this._updateBadge(0);
- this._removeMarkAllAsConfirmed();
- break;
-
- case 'getOutstandingNotifications':
- if (!data.returnValues || !data.returnValues.template) {
- this._removeMarkAllAsConfirmed();
- }
-
- this._super(data, textStatus, jqXHR);
- break;
- }
- },
-
- /**
- * @see WCF.UserPanel._updateBadge()
- */
- _updateBadge: function(count) {
- count = parseInt(count) || 0;
-
- this._super(count);
-
- if (this._favico !== null) {
- this._favico.badge(count);
- }
-
- if (count === 0) {
- this._removeMarkAllAsConfirmed();
- }
- },
-
- /**
- * Resets the notification list to its initial state.
- */
- _resetList: function() {
- var $dropdownMenu = WCF.Dropdown.getDropdownMenu(this._container.wcfIdentify());
- $dropdownMenu.children('li.jsNotificationItem').remove();
-
- $('<li class="jsDropdownPlaceholder"><span>' + WCF.Language.get('wcf.global.loading') + '</span></li>').prependTo($dropdownMenu);
-
- // remove double separators
- $dropdownMenu.children('.dropdownDivider + .dropdownDivider').remove();
-
- this._didLoad = false;
- },
-
- _removeMarkAllAsConfirmed: function() {
- $('#userNotificationsMarkAllAsConfirmed').hide().prev('.dropdownDivider').hide();
- },
-
- /**
- * Updates user notification count.
- *
- * @param integer count
- */
- updateUserNotificationCount: function(count) {
- // close dropdown
- WCF.Dropdown.close('userNotifications');
-
- // revert dropdown to initial state
- this._resetList();
-
- // update badge
- this._updateBadge(count);
-
- if (parseInt(count) > 0) {
- $('#userNotificationsMarkAllAsConfirmed').show().prev('.dropdownDivider').show();
- }
- }
-});
-
/**
* Signature preview.
*