2016-03-16 22:47:20 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
/**
|
|
|
|
* An inbox-type widget that encompases a dated notifications list with pagination
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Widget
|
|
|
|
* @mixins OO.ui.mixin.PendingElement
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {mw.echo.Controller} controller Echo controller
|
|
|
|
* @param {mw.echo.dm.ModelManager} manager Model manager
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
* @cfg {number} [limit=25] Limit the number of notifications per page
|
|
|
|
* @cfg {jQuery} [$overlay] An overlay for the popup menus
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget = function MwEchoUiNotificationsInboxWidget( controller, manager, config ) {
|
2016-05-31 22:32:16 +00:00
|
|
|
var $main, $sidebar;
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.parent.call( this, config );
|
|
|
|
// Mixin constructors
|
|
|
|
OO.ui.mixin.PendingElement.call( this, config );
|
|
|
|
|
|
|
|
this.controller = controller;
|
|
|
|
this.manager = manager;
|
|
|
|
|
|
|
|
this.$overlay = config.$overlay || this.$element;
|
|
|
|
this.limit = config.limit || 25;
|
|
|
|
|
2016-08-29 19:56:56 +00:00
|
|
|
this.error = false;
|
|
|
|
|
2016-05-31 00:12:31 +00:00
|
|
|
// A notice or error message widget
|
|
|
|
this.noticeMessageWidget = new OO.ui.LabelWidget( {
|
|
|
|
classes: [ 'mw-echo-ui-notificationsInboxWidget-notice' ]
|
|
|
|
} );
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
// Notifications list
|
|
|
|
this.datedListWidget = new mw.echo.ui.DatedNotificationsWidget(
|
|
|
|
this.controller,
|
|
|
|
this.manager,
|
|
|
|
{
|
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.$overlay,
|
|
|
|
animateSorting: false
|
2016-03-16 22:47:20 +00:00
|
|
|
}
|
|
|
|
);
|
2016-05-31 00:24:12 +00:00
|
|
|
this.setPendingElement( this.datedListWidget.$element );
|
2016-03-16 22:47:20 +00:00
|
|
|
|
|
|
|
// Pagination
|
2016-05-27 20:39:15 +00:00
|
|
|
this.topPaginationWidget = new mw.echo.ui.PaginationWidget(
|
|
|
|
this.manager.getPaginationModel(),
|
|
|
|
{
|
|
|
|
itemsPerPage: this.limit
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.bottomPaginationWidget = new mw.echo.ui.PaginationWidget(
|
|
|
|
this.manager.getPaginationModel(),
|
|
|
|
{
|
|
|
|
itemsPerPage: this.limit
|
|
|
|
}
|
|
|
|
);
|
2016-03-16 22:47:20 +00:00
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
// Settings menu
|
|
|
|
this.settingsMenu = new mw.echo.ui.SpecialHelpMenuWidget(
|
|
|
|
this.manager,
|
|
|
|
{
|
|
|
|
framed: true,
|
|
|
|
helpLink: config.helpLink,
|
2018-03-11 22:18:24 +00:00
|
|
|
prefLink: config.prefLink,
|
|
|
|
$overlay: this.$overlay
|
2016-06-29 23:36:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-05-20 04:22:41 +00:00
|
|
|
// Filter by read state
|
|
|
|
this.readStateSelectWidget = new mw.echo.ui.ReadStateButtonSelectWidget();
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
// Sidebar filters
|
|
|
|
this.xwikiUnreadWidget = new mw.echo.ui.CrossWikiUnreadFilterWidget(
|
|
|
|
this.controller,
|
|
|
|
this.manager.getFiltersModel()
|
|
|
|
);
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
// Events
|
2016-05-20 04:22:41 +00:00
|
|
|
this.readStateSelectWidget.connect( this, { filter: 'onReadStateFilter' } );
|
2016-05-31 22:32:16 +00:00
|
|
|
this.xwikiUnreadWidget.connect( this, { filter: 'onSourcePageFilter' } );
|
2016-06-29 23:36:03 +00:00
|
|
|
this.manager.connect( this, {
|
|
|
|
modelItemUpdate: 'updatePaginationLabels',
|
|
|
|
localCountChange: 'updatePaginationLabels'
|
|
|
|
} );
|
2016-05-20 04:22:41 +00:00
|
|
|
this.manager.getFiltersModel().connect( this, { update: 'updateReadStateSelectWidget' } );
|
2016-06-29 23:36:03 +00:00
|
|
|
this.manager.getPaginationModel().connect( this, { update: 'updatePaginationLabels' } );
|
2016-05-27 20:39:15 +00:00
|
|
|
this.topPaginationWidget.connect( this, { change: 'populateNotifications' } );
|
|
|
|
this.bottomPaginationWidget.connect( this, { change: 'populateNotifications' } );
|
2016-06-29 23:36:03 +00:00
|
|
|
this.settingsMenu.connect( this, { markAllRead: 'onSettingsMarkAllRead' } );
|
2016-05-27 20:39:15 +00:00
|
|
|
|
|
|
|
this.topPaginationWidget.setDisabled( true );
|
|
|
|
this.bottomPaginationWidget.setDisabled( true );
|
2016-03-16 22:47:20 +00:00
|
|
|
|
2016-09-30 19:16:28 +00:00
|
|
|
this.$topToolbar =
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-top' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-row' )
|
|
|
|
.append(
|
2017-10-17 12:53:08 +00:00
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' )
|
|
|
|
.append( this.readStateSelectWidget.$element ),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell-placeholder' ),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-pagination' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' )
|
|
|
|
.append( this.topPaginationWidget.$element ),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-settings' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' )
|
|
|
|
.append( this.settingsMenu.$element )
|
|
|
|
)
|
2016-09-30 19:16:28 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
this.$toolbarWrapper =
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-toolbarWrapper' )
|
|
|
|
.append( this.$topToolbar );
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
$sidebar = $( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-sidebar' )
|
|
|
|
.append( this.xwikiUnreadWidget.$element );
|
|
|
|
|
|
|
|
$main = $( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-main' )
|
2016-03-16 22:47:20 +00:00
|
|
|
.append(
|
2017-10-17 12:53:08 +00:00
|
|
|
this.$toolbarWrapper,
|
|
|
|
this.noticeMessageWidget.$element,
|
|
|
|
this.datedListWidget.$element
|
2016-03-16 22:47:20 +00:00
|
|
|
);
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-row' )
|
|
|
|
.append(
|
|
|
|
$sidebar
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' ),
|
|
|
|
$main
|
|
|
|
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2016-05-20 04:22:41 +00:00
|
|
|
this.updateReadStateSelectWidget();
|
2016-05-31 22:32:16 +00:00
|
|
|
this.xwikiUnreadWidget.populateSources();
|
2016-03-16 22:47:20 +00:00
|
|
|
this.populateNotifications();
|
2016-09-30 19:16:28 +00:00
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.NotificationsInboxWidget, OO.ui.Widget );
|
|
|
|
OO.mixinClass( mw.echo.ui.NotificationsInboxWidget, OO.ui.mixin.PendingElement );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2016-05-20 04:22:41 +00:00
|
|
|
/**
|
|
|
|
* Respond to filters update
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.updateReadStateSelectWidget = function () {
|
|
|
|
this.readStateSelectWidget
|
2017-12-14 08:05:54 +00:00
|
|
|
.findItemFromData( this.manager.getFiltersModel().getReadState() )
|
2016-05-20 04:22:41 +00:00
|
|
|
.setSelected( true );
|
|
|
|
};
|
|
|
|
|
2016-07-14 00:03:57 +00:00
|
|
|
/**
|
2016-06-29 23:36:03 +00:00
|
|
|
* Update pagination messages
|
2016-07-14 00:03:57 +00:00
|
|
|
*/
|
2016-06-29 23:36:03 +00:00
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.updatePaginationLabels = function () {
|
2016-07-14 00:03:57 +00:00
|
|
|
this.resetMessageLabel();
|
2016-06-29 23:36:03 +00:00
|
|
|
// Update the pagination label
|
|
|
|
this.topPaginationWidget.updateLabel();
|
|
|
|
this.bottomPaginationWidget.updateLabel();
|
2016-07-14 00:03:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-06-29 23:36:03 +00:00
|
|
|
* Respond to mark all read for selected wiki
|
2016-07-14 00:03:57 +00:00
|
|
|
*/
|
2016-06-29 23:36:03 +00:00
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.onSettingsMarkAllRead = function () {
|
|
|
|
this.pushPending();
|
|
|
|
this.controller.markAllRead()
|
|
|
|
.always( this.popPending.bind( this ) );
|
2016-07-14 00:03:57 +00:00
|
|
|
};
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
/**
|
|
|
|
* Respond to unread page filter
|
|
|
|
*
|
|
|
|
* @param {string} source Source symbolic name
|
2016-06-23 13:51:05 +00:00
|
|
|
* @param {string} page Page name
|
2016-05-31 22:32:16 +00:00
|
|
|
*/
|
2016-06-23 13:51:05 +00:00
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.onSourcePageFilter = function ( source, page ) {
|
|
|
|
this.controller.setFilter( 'sourcePage', source, page );
|
2016-05-31 22:32:16 +00:00
|
|
|
this.populateNotifications();
|
|
|
|
};
|
|
|
|
|
2016-05-20 04:22:41 +00:00
|
|
|
/**
|
|
|
|
* Respond to read state filter event
|
|
|
|
*
|
|
|
|
* @param {string} readState Read state 'all', 'read' or 'unread'
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.onReadStateFilter = function ( readState ) {
|
|
|
|
this.controller.setFilter( 'readState', readState );
|
|
|
|
this.populateNotifications();
|
|
|
|
};
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
/**
|
|
|
|
* Populate the notifications list
|
|
|
|
*
|
|
|
|
* @param {string} [direction] Direction to fetch from. 'prev' for previous page
|
|
|
|
* or 'next' for the next page. If not given, the first page of results will be fetched.
|
|
|
|
* @return {jQuery.Promise} A promise that is resolved when the results
|
|
|
|
* have been fetched.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.populateNotifications = function ( direction ) {
|
2016-07-08 22:56:01 +00:00
|
|
|
var fetchPromise,
|
|
|
|
widget = this;
|
2016-03-16 22:47:20 +00:00
|
|
|
|
|
|
|
if ( direction === 'prev' ) {
|
|
|
|
fetchPromise = this.controller.fetchPrevPageByDate();
|
|
|
|
} else if ( direction === 'next' ) {
|
|
|
|
fetchPromise = this.controller.fetchNextPageByDate();
|
|
|
|
} else {
|
|
|
|
fetchPromise = this.controller.fetchFirstPageByDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pushPending();
|
2016-08-29 19:56:56 +00:00
|
|
|
this.error = false;
|
2016-03-16 22:47:20 +00:00
|
|
|
return fetchPromise
|
2016-07-08 22:56:01 +00:00
|
|
|
.then(
|
|
|
|
// Success
|
|
|
|
function () {
|
2016-09-26 17:08:43 +00:00
|
|
|
// Fire initialization hook
|
|
|
|
mw.hook( 'ext.echo.special.onInitialize' ).fire( widget.controller.manager.getTypeString(), widget.controller );
|
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
widget.popPending();
|
|
|
|
// Update seen time
|
2016-09-13 23:18:29 +00:00
|
|
|
widget.controller.updateSeenTime();
|
2016-07-08 22:56:01 +00:00
|
|
|
},
|
|
|
|
// Failure
|
2016-08-29 19:56:56 +00:00
|
|
|
function ( errObj ) {
|
|
|
|
var msg;
|
|
|
|
if ( errObj.errCode === 'notlogin-required' ) {
|
|
|
|
// Login required message
|
|
|
|
msg = mw.msg( 'echo-notification-loginrequired' );
|
|
|
|
} else {
|
|
|
|
// Generic API failure message
|
|
|
|
msg = mw.msg( 'echo-api-failure' );
|
|
|
|
}
|
|
|
|
widget.error = true;
|
|
|
|
widget.noticeMessageWidget.setLabel( msg );
|
|
|
|
widget.displayMessage( true );
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.always( this.popPending.bind( this ) );
|
2016-03-16 22:47:20 +00:00
|
|
|
};
|
2016-05-31 00:12:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the pushPending method to disable UI elements
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.pushPending = function () {
|
|
|
|
this.noticeMessageWidget.toggle( false );
|
|
|
|
this.topPaginationWidget.setDisabled( true );
|
|
|
|
this.bottomPaginationWidget.setDisabled( true );
|
|
|
|
|
|
|
|
// Mixin method
|
|
|
|
OO.ui.mixin.PendingElement.prototype.pushPending.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the popPending method to enable UI elements
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.popPending = function () {
|
2016-08-29 19:56:56 +00:00
|
|
|
if ( !this.error ) {
|
|
|
|
this.resetMessageLabel();
|
|
|
|
}
|
|
|
|
|
2016-05-31 00:12:31 +00:00
|
|
|
this.topPaginationWidget.setDisabled( false );
|
|
|
|
this.bottomPaginationWidget.setDisabled( false );
|
|
|
|
|
|
|
|
// Mixin method
|
|
|
|
OO.ui.mixin.PendingElement.prototype.popPending.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the the text of the error message that displays in place of the list
|
|
|
|
* in case the list is empty.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.resetMessageLabel = function () {
|
|
|
|
var label,
|
2016-07-14 00:03:57 +00:00
|
|
|
count = this.manager.getPaginationModel().getCurrentPageItemCount();
|
2016-05-31 00:12:31 +00:00
|
|
|
|
|
|
|
if ( count === 0 ) {
|
|
|
|
label = this.manager.getFiltersModel().getReadState() === 'all' ?
|
|
|
|
mw.msg( 'echo-notification-placeholder' ) :
|
|
|
|
mw.msg( 'echo-notification-placeholder-filters' );
|
|
|
|
|
|
|
|
this.noticeMessageWidget.setLabel( label );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.displayMessage( count === 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the error/notice message instead of the notifications list or vise versa.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} displayMessage Display error message
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsInboxWidget.prototype.displayMessage = function ( displayMessage ) {
|
|
|
|
this.noticeMessageWidget.toggle( displayMessage );
|
|
|
|
this.datedListWidget.toggle( !displayMessage );
|
|
|
|
};
|
2016-09-30 19:16:28 +00:00
|
|
|
|
2016-11-18 21:16:43 +00:00
|
|
|
}( jQuery, mediaWiki ) );
|