2015-08-13 00:54:16 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
/**
|
|
|
|
* Notification badge button widget for echo popup.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.ButtonWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
2016-04-10 13:31:02 +00:00
|
|
|
* @param {mw.echo.Controller} controller Echo notifications controller
|
|
|
|
* @param {mw.echo.dm.ModelManager} manager Model manager
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
* @cfg {string|string[]} [type='message'] The type or array of types of
|
|
|
|
* notifications that are in this model. They can be 'alert', 'message' or
|
|
|
|
* an array of both. Defaults to 'message'
|
2016-07-20 00:24:17 +00:00
|
|
|
* @cfg {number} [numItems=0] The number of items that are in the button display
|
|
|
|
* @cfg {string} [badgeLabel=0] The initial label for the badge. This is the
|
|
|
|
* formatted version of the number of items in the badge.
|
2015-09-03 21:24:03 +00:00
|
|
|
* @cfg {boolean} [hasUnseen=false] Whether there are unseen items
|
2015-09-09 20:18:52 +00:00
|
|
|
* @cfg {number} [popupWidth=450] The width of the popup
|
2016-07-20 00:24:17 +00:00
|
|
|
* @cfg {string} [badgeIcon] Icon to use for the popup header
|
2015-09-24 01:13:37 +00:00
|
|
|
* @cfg {string} [href] URL the badge links to
|
2015-11-21 01:54:12 +00:00
|
|
|
* @cfg {jQuery} [$overlay] A jQuery element functioning as an overlay
|
|
|
|
* for popups.
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationBadgeWidget = function MwEchoUiNotificationBadgeButtonPopupWidget( controller, manager, config ) {
|
2016-03-18 00:00:05 +00:00
|
|
|
var buttonFlags, allNotificationsButton, preferencesButton, footerButtonGroupWidget, $footer,
|
2017-04-04 18:40:09 +00:00
|
|
|
notice, adjustedTypeString;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
config = config || {};
|
|
|
|
config.links = config.links || {};
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
// Parent constructor
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.parent.call( this, config );
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
// Mixin constructors
|
|
|
|
OO.ui.mixin.PendingElement.call( this, config );
|
|
|
|
|
2015-11-21 01:54:12 +00:00
|
|
|
this.$overlay = config.$overlay || this.$element;
|
2015-10-16 23:18:25 +00:00
|
|
|
// Create a menu overlay
|
|
|
|
this.$menuOverlay = $( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-NotificationBadgeWidget-overlay-menu' );
|
|
|
|
this.$overlay.append( this.$menuOverlay );
|
2015-11-21 01:54:12 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
// Controller
|
|
|
|
this.controller = controller;
|
|
|
|
this.manager = manager;
|
|
|
|
|
2017-04-04 18:40:09 +00:00
|
|
|
adjustedTypeString = this.controller.getTypeString() === 'message' ? 'notice' : this.controller.getTypeString();
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
// Properties
|
|
|
|
this.types = this.manager.getTypes();
|
2015-10-26 22:23:22 +00:00
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
this.numItems = config.numItems || 0;
|
|
|
|
this.hasRunFirstTime = false;
|
|
|
|
|
2016-07-20 00:24:17 +00:00
|
|
|
buttonFlags = [];
|
2016-11-18 21:16:43 +00:00
|
|
|
if ( config.hasUnseen ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
buttonFlags.push( 'unseen' );
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
this.badgeButton = new mw.echo.ui.BadgeLinkWidget( {
|
2017-09-02 00:08:21 +00:00
|
|
|
convertedNumber: config.convertedNumber,
|
2016-09-26 17:08:43 +00:00
|
|
|
type: this.manager.getTypeString(),
|
2016-07-20 00:24:17 +00:00
|
|
|
numItems: this.numItems,
|
2015-09-17 00:05:52 +00:00
|
|
|
flags: buttonFlags,
|
|
|
|
// The following messages can be used here:
|
|
|
|
// tooltip-pt-notifications-alert
|
2016-07-07 22:05:56 +00:00
|
|
|
// tooltip-pt-notifications-notice
|
2016-07-22 18:59:10 +00:00
|
|
|
title: mw.msg( 'tooltip-pt-notifications-' + adjustedTypeString ),
|
2015-09-24 01:13:37 +00:00
|
|
|
href: config.href
|
2015-09-17 00:05:52 +00:00
|
|
|
} );
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
// Notifications list widget
|
|
|
|
this.notificationsWidget = new mw.echo.ui.NotificationsListWidget(
|
|
|
|
this.controller,
|
|
|
|
this.manager,
|
2015-08-13 00:54:16 +00:00
|
|
|
{
|
2016-04-10 13:31:02 +00:00
|
|
|
type: this.types,
|
Fix fade-in/out animation in sorting
The fade in/out animation is asynchronous. This means that if we are
sorting multiple items one after the other, by the time the item faded
out, it will be reinserted back into the wrong position, breaking the
sorting.
This also broke the promise of OO.SortedEmitterList whereby all its items
are always in order.
The way to fix this was to force a better synchronization with the item
order while we hide and show the item in its new place. To do that,
a new widget is created as a fake clone of the old one, in the original
position of the old one. The original item is then reinserted (while hidden)
to the proper location -- preserving order. The fake clone is then faded
out, and the real item is then faded in.
For this to work properly, the cloned item had to preserve some of the
original item's information, like timestamp, foreigness and id. However,
since both the real item and the fake new clone have the same details,
the clone fakes its ID by adding a fraction to it - promising that the
fallback in case of equal timestamps (which happens on the real and
cloned items) will still resolve with some decision about the placement
of the items rather than (falsely but understandably) decide they are
both the same.
Since this whole animation is somewhat of a hack, the list now has a
configuration parameter to turn the animation on.
The animation is on in the popups, but off in the special page.
Bug: T141419
Change-Id: Ic7c35e5ddefc51bf7fde497eab36414b4dddcd9e
2016-07-29 23:35:29 +00:00
|
|
|
$overlay: this.$menuOverlay,
|
|
|
|
animated: true
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Footer
|
|
|
|
allNotificationsButton = new OO.ui.ButtonWidget( {
|
|
|
|
icon: 'next',
|
|
|
|
label: mw.msg( 'echo-overlay-link' ),
|
|
|
|
href: config.links.notifications,
|
|
|
|
classes: [ 'mw-echo-ui-notificationBadgeButtonPopupWidget-footer-allnotifs' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
preferencesButton = new OO.ui.ButtonWidget( {
|
|
|
|
icon: 'advanced',
|
|
|
|
label: mw.msg( 'mypreferences' ),
|
|
|
|
href: config.links.preferences,
|
|
|
|
classes: [ 'mw-echo-ui-notificationBadgeButtonPopupWidget-footer-preferences' ]
|
|
|
|
} );
|
|
|
|
|
2015-09-09 20:18:52 +00:00
|
|
|
footerButtonGroupWidget = new OO.ui.ButtonGroupWidget( {
|
2016-03-18 00:00:05 +00:00
|
|
|
items: [ allNotificationsButton, preferencesButton ],
|
|
|
|
classes: [ 'mw-echo-ui-notificationBadgeButtonPopupWidget-footer-buttons' ]
|
2015-09-09 20:18:52 +00:00
|
|
|
} );
|
2015-08-13 00:54:16 +00:00
|
|
|
$footer = $( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationBadgeButtonPopupWidget-footer' )
|
2015-09-09 20:18:52 +00:00
|
|
|
.append( footerButtonGroupWidget.$element );
|
2015-09-17 00:05:52 +00:00
|
|
|
|
2016-03-18 00:00:05 +00:00
|
|
|
// Footer notice
|
|
|
|
if (
|
2016-08-01 22:09:24 +00:00
|
|
|
mw.config.get( 'wgEchoShowSpecialPageInvitation' ) &&
|
|
|
|
!mw.user.options.get( 'echo-dismiss-special-page-invitation' )
|
2016-03-18 00:00:05 +00:00
|
|
|
) {
|
|
|
|
notice = new mw.echo.ui.FooterNoticeWidget( {
|
|
|
|
// This is probably not the right way of doing this
|
|
|
|
iconUrl: mw.config.get( 'wgExtensionAssetsPath' ) + '/Echo/modules/icons/feedback.svg',
|
2016-08-01 22:09:24 +00:00
|
|
|
message: mw.message(
|
|
|
|
'echo-popup-footer-special-page-invitation',
|
2017-10-17 12:53:08 +00:00
|
|
|
// Text
|
|
|
|
mw.msg( 'echo-popup-footer-special-page-invitation-link' ),
|
|
|
|
// Link
|
|
|
|
mw.util.getUrl( 'Special:Notifications' )
|
|
|
|
).parse()
|
2016-03-18 00:00:05 +00:00
|
|
|
} );
|
|
|
|
// Event
|
|
|
|
notice.connect( this, { dismiss: 'onFooterNoticeDismiss' } );
|
|
|
|
// Prepend to the footer
|
|
|
|
$footer.prepend( notice.$element );
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
this.popup = new OO.ui.PopupWidget( {
|
|
|
|
$content: this.notificationsWidget.$element,
|
|
|
|
$footer: $footer,
|
2016-01-13 03:36:47 +00:00
|
|
|
width: config.popupWidth || 500,
|
2015-09-17 00:05:52 +00:00
|
|
|
autoClose: true,
|
2016-07-20 00:24:17 +00:00
|
|
|
containerPadding: 20,
|
2015-10-16 23:18:25 +00:00
|
|
|
// Also ignore clicks from the nested action menu items, that
|
|
|
|
// actually exist in the overlay
|
|
|
|
$autoCloseIgnore: this.$element.add( this.$menuOverlay ),
|
2015-09-17 00:05:52 +00:00
|
|
|
head: true,
|
2015-09-10 22:17:11 +00:00
|
|
|
// The following messages can be used here:
|
2015-09-17 00:05:52 +00:00
|
|
|
// echo-notification-alert-text-only
|
2016-07-14 12:45:23 +00:00
|
|
|
// echo-notification-notice-text-only
|
2016-07-07 22:05:56 +00:00
|
|
|
label: mw.msg(
|
2016-07-22 18:59:10 +00:00
|
|
|
'echo-notification-' + adjustedTypeString +
|
2016-07-07 22:05:56 +00:00
|
|
|
'-text-only'
|
|
|
|
),
|
2015-09-25 21:17:54 +00:00
|
|
|
classes: [ 'mw-echo-ui-notificationBadgeButtonPopupWidget-popup' ]
|
2015-09-17 00:05:52 +00:00
|
|
|
} );
|
2015-08-13 00:54:16 +00:00
|
|
|
// HACK: Add an icon to the popup head label
|
2016-07-20 00:24:17 +00:00
|
|
|
this.popupHeadIcon = new OO.ui.IconWidget( { icon: config.badgeIcon } );
|
2015-09-03 21:24:03 +00:00
|
|
|
this.popup.$head.prepend( this.popupHeadIcon.$element );
|
|
|
|
|
2015-09-10 22:24:21 +00:00
|
|
|
this.setPendingElement( this.popup.$head );
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
// Mark all as read button
|
|
|
|
this.markAllReadButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
label: mw.msg( 'echo-mark-all-as-read' ),
|
|
|
|
classes: [ 'mw-echo-ui-notificationsWidget-markAllReadButton' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Hide the close button
|
|
|
|
this.popup.closeButton.toggle( false );
|
|
|
|
// Add the 'mark all as read' button to the header
|
|
|
|
this.popup.$head.append( this.markAllReadButton.$element );
|
2015-09-28 20:21:37 +00:00
|
|
|
this.markAllReadButton.toggle( false );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.markAllReadButton.connect( this, { click: 'onMarkAllReadButtonClick' } );
|
2016-04-10 13:31:02 +00:00
|
|
|
this.manager.connect( this, {
|
2016-07-08 22:56:01 +00:00
|
|
|
update: 'updateBadge'
|
2015-08-13 00:54:16 +00:00
|
|
|
} );
|
2016-07-08 22:56:01 +00:00
|
|
|
this.manager.getSeenTimeModel().connect( this, { update: 'onSeenTimeModelUpdate' } );
|
2016-04-10 13:31:02 +00:00
|
|
|
this.manager.getUnreadCounter().connect( this, { countChange: 'updateBadge' } );
|
2015-09-08 00:11:31 +00:00
|
|
|
this.popup.connect( this, { toggle: 'onPopupToggle' } );
|
2015-09-17 00:05:52 +00:00
|
|
|
this.badgeButton.connect( this, {
|
|
|
|
click: 'onBadgeButtonClick'
|
|
|
|
} );
|
2017-03-07 22:35:42 +00:00
|
|
|
this.notificationsWidget.connect( this, { modified: 'onNotificationsListModified' } );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
this.$element
|
2016-07-22 18:59:10 +00:00
|
|
|
.prop( 'id', 'pt-notifications-' + adjustedTypeString )
|
2015-09-17 00:05:52 +00:00
|
|
|
// The following classes can be used here:
|
|
|
|
// mw-echo-ui-notificationBadgeButtonPopupWidget-alert
|
|
|
|
// mw-echo-ui-notificationBadgeButtonPopupWidget-message
|
2015-08-13 00:54:16 +00:00
|
|
|
.addClass(
|
|
|
|
'mw-echo-ui-notificationBadgeButtonPopupWidget ' +
|
2016-07-22 18:59:10 +00:00
|
|
|
'mw-echo-ui-notificationBadgeButtonPopupWidget-' + adjustedTypeString
|
2015-09-17 00:05:52 +00:00
|
|
|
)
|
|
|
|
.append(
|
|
|
|
this.badgeButton.$element,
|
|
|
|
this.popup.$element
|
2015-08-13 00:54:16 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
OO.inheritClass( mw.echo.ui.NotificationBadgeWidget, OO.ui.Widget );
|
2015-08-13 00:54:16 +00:00
|
|
|
OO.mixinClass( mw.echo.ui.NotificationBadgeWidget, OO.ui.mixin.PendingElement );
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
/* Static properties */
|
|
|
|
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.static.tagName = 'li';
|
|
|
|
|
2015-09-17 20:47:23 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event allRead
|
|
|
|
* All notifications were marked as read
|
|
|
|
*/
|
|
|
|
|
2016-01-15 22:11:33 +00:00
|
|
|
/**
|
|
|
|
* @event finishLoading
|
|
|
|
* Notifications have successfully finished being processed and are fully loaded
|
|
|
|
*/
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2017-03-07 22:35:42 +00:00
|
|
|
/**
|
|
|
|
* Respond to list widget modified event.
|
|
|
|
*
|
|
|
|
* This means the list's actual DOM was modified and we should make sure
|
|
|
|
* that the popup resizes itself.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.onNotificationsListModified = function () {
|
|
|
|
this.popup.clip();
|
|
|
|
};
|
|
|
|
|
2016-03-18 00:00:05 +00:00
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.onFooterNoticeDismiss = function () {
|
|
|
|
// Clip again to recalculate height
|
|
|
|
this.popup.clip();
|
|
|
|
|
|
|
|
// Save the preference in general
|
2016-08-01 22:09:24 +00:00
|
|
|
new mw.Api().saveOption( 'echo-dismiss-special-page-invitation', 1 );
|
2016-03-18 00:00:05 +00:00
|
|
|
// Save the preference for this session
|
2016-08-01 22:09:24 +00:00
|
|
|
mw.user.options.set( 'echo-dismiss-special-page-invitation', 1 );
|
2016-03-18 00:00:05 +00:00
|
|
|
};
|
|
|
|
|
2015-09-17 00:05:52 +00:00
|
|
|
/**
|
|
|
|
* Respond to badge button click
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.onBadgeButtonClick = function () {
|
2015-09-30 00:02:48 +00:00
|
|
|
this.popup.toggle();
|
2015-09-17 00:05:52 +00:00
|
|
|
};
|
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
/**
|
|
|
|
* Respond to SeenTime model update event
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.onSeenTimeModelUpdate = function () {
|
2016-09-13 23:18:29 +00:00
|
|
|
this.updateBadgeSeenState( false );
|
2016-07-08 22:56:01 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Update the badge style to match whether it contains unseen notifications.
|
|
|
|
*
|
2016-09-13 23:18:29 +00:00
|
|
|
* @param {boolean} [hasUnseen=false] There are unseen notifications
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.updateBadgeSeenState = function ( hasUnseen ) {
|
2016-09-13 23:18:29 +00:00
|
|
|
hasUnseen = hasUnseen === undefined ? false : !!hasUnseen;
|
2016-07-08 22:56:01 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
this.badgeButton.setFlags( { unseen: !!hasUnseen } );
|
|
|
|
};
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
/**
|
|
|
|
* Update the badge state and label based on changes to the model
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () {
|
2017-04-04 18:40:09 +00:00
|
|
|
var unreadCount, cappedUnreadCount, badgeLabel;
|
2015-09-23 00:04:14 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
unreadCount = this.manager.getUnreadCounter().getCount();
|
2016-09-12 21:06:49 +00:00
|
|
|
cappedUnreadCount = this.manager.getUnreadCounter().getCappedNotificationCount( unreadCount );
|
2016-03-15 21:13:19 +00:00
|
|
|
cappedUnreadCount = mw.language.convertNumber( cappedUnreadCount );
|
2016-09-12 21:06:49 +00:00
|
|
|
badgeLabel = mw.message( 'echo-badge-count', mw.language.convertNumber( cappedUnreadCount ) ).text();
|
2015-09-08 20:46:57 +00:00
|
|
|
|
2017-04-04 18:40:09 +00:00
|
|
|
this.badgeButton.setLabel( badgeLabel );
|
2016-07-20 00:24:17 +00:00
|
|
|
this.badgeButton.setCount( unreadCount, badgeLabel );
|
2016-04-10 13:31:02 +00:00
|
|
|
// Update seen state only if the counter is 0
|
|
|
|
// so we don't run into inconsistencies and have an unseen state
|
|
|
|
// for the badge with 0 unread notifications
|
|
|
|
if ( unreadCount === 0 ) {
|
|
|
|
this.updateBadgeSeenState( false );
|
|
|
|
}
|
|
|
|
|
2015-09-08 20:46:57 +00:00
|
|
|
// Check if we need to display the 'mark all unread' button
|
2016-06-10 13:06:04 +00:00
|
|
|
this.markAllReadButton.toggle( this.manager.hasLocalUnread() );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to 'mark all as read' button click
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.onMarkAllReadButtonClick = function () {
|
2016-08-04 20:46:46 +00:00
|
|
|
// Log the click action
|
|
|
|
mw.echo.logger.logInteraction(
|
|
|
|
mw.echo.Logger.static.actions.markAllReadClick,
|
|
|
|
mw.echo.Logger.static.context.popup,
|
|
|
|
null, // Event id isn't relevant
|
|
|
|
this.manager.getTypeString() // The type of the list
|
|
|
|
);
|
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
this.controller.markLocalNotificationsRead();
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
/**
|
|
|
|
* Extend the response to button click so we can also update the notification list.
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2016-11-18 21:16:43 +00:00
|
|
|
* @param {boolean} isVisible The popup is visible
|
2016-01-15 22:11:33 +00:00
|
|
|
* @fires finishLoading
|
2015-09-15 06:13:51 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationBadgeWidget.prototype.onPopupToggle = function ( isVisible ) {
|
2015-09-24 21:23:23 +00:00
|
|
|
var widget = this;
|
|
|
|
|
2016-01-15 22:11:33 +00:00
|
|
|
if ( this.promiseRunning ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-15 06:13:51 +00:00
|
|
|
if ( !isVisible ) {
|
2016-04-10 13:31:02 +00:00
|
|
|
widget.notificationsWidget.resetInitiallyUnseenItems();
|
2015-09-15 06:13:51 +00:00
|
|
|
return;
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
2015-09-15 06:13:51 +00:00
|
|
|
|
|
|
|
// Log the click event
|
|
|
|
mw.echo.logger.logInteraction(
|
|
|
|
'ui-badge-link-click',
|
2015-10-08 22:20:31 +00:00
|
|
|
mw.echo.Logger.static.context.badge,
|
2015-09-15 06:13:51 +00:00
|
|
|
null,
|
2016-04-10 13:31:02 +00:00
|
|
|
this.controller.getTypeString()
|
2015-09-15 06:13:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( this.hasRunFirstTime ) {
|
|
|
|
// HACK: Clippable doesn't resize the clippable area when
|
|
|
|
// it calculates the new size. Since the popup contents changed
|
|
|
|
// and the popup is "empty" now, we need to manually set its
|
|
|
|
// size to 1px so the clip calculations will resize it properly.
|
|
|
|
// See bug report: https://phabricator.wikimedia.org/T110759
|
|
|
|
this.popup.$clippable.css( 'height', '1px' );
|
|
|
|
this.popup.clip();
|
|
|
|
}
|
2016-01-15 22:11:33 +00:00
|
|
|
|
|
|
|
this.pushPending();
|
|
|
|
this.markAllReadButton.toggle( false );
|
|
|
|
this.promiseRunning = true;
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2015-09-16 20:42:17 +00:00
|
|
|
// Always populate on popup open. The model and widget should handle
|
|
|
|
// the case where the promise is already underway.
|
2016-04-10 13:31:02 +00:00
|
|
|
this.controller.fetchLocalNotifications( this.hasRunFirstTime )
|
|
|
|
.then(
|
|
|
|
// Success
|
|
|
|
function () {
|
|
|
|
if ( widget.popup.isVisible() ) {
|
2016-09-26 17:08:43 +00:00
|
|
|
// Fire initialization hook
|
|
|
|
mw.hook( 'ext.echo.popup.onInitialize' ).fire( widget.manager.getTypeString(), widget.controller );
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
// Update seen time
|
2016-09-13 23:18:29 +00:00
|
|
|
return widget.controller.updateSeenTime();
|
2015-09-30 18:42:53 +00:00
|
|
|
}
|
2016-04-10 13:31:02 +00:00
|
|
|
},
|
|
|
|
// Failure
|
2016-08-29 19:56:56 +00:00
|
|
|
function ( errorObj ) {
|
|
|
|
if ( errorObj.errCode === 'notlogin-required' ) {
|
|
|
|
// Login required message
|
|
|
|
widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-notification-loginrequired' ) );
|
|
|
|
} else {
|
|
|
|
// Generic API failure message
|
|
|
|
widget.notificationsWidget.resetLoadingOption( mw.msg( 'echo-api-failure' ) );
|
|
|
|
}
|
2015-09-24 21:23:23 +00:00
|
|
|
}
|
2016-04-10 13:31:02 +00:00
|
|
|
)
|
|
|
|
.then( this.emit.bind( this, 'finishLoading' ) )
|
2016-01-15 22:11:33 +00:00
|
|
|
.always( function () {
|
2017-03-07 22:35:42 +00:00
|
|
|
widget.popup.clip();
|
2016-01-15 22:11:33 +00:00
|
|
|
// Pop pending
|
|
|
|
widget.popPending();
|
|
|
|
widget.promiseRunning = false;
|
2015-09-24 21:23:23 +00:00
|
|
|
} );
|
2015-09-16 20:42:17 +00:00
|
|
|
this.hasRunFirstTime = true;
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
2016-11-18 21:16:43 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|