2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-03-16 22:56:47 +00:00
|
|
|
/**
|
2016-04-15 19:45:48 +00:00
|
|
|
* Wrapper for the notifications widget, for view outside the popup.
|
2016-03-16 22:56:47 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Widget
|
|
|
|
* @mixins OO.ui.mixin.PendingElement
|
|
|
|
*
|
|
|
|
* @constructor
|
2016-04-10 13:31:02 +00:00
|
|
|
* @param {mw.echo.Controller} controller Echo controller
|
|
|
|
* @param {mw.echo.dm.ModelManager} model Notifications model manager
|
2016-03-16 22:56:47 +00:00
|
|
|
* @param {Object} [config] Configuration object
|
2018-05-22 14:57:23 +00:00
|
|
|
* @cfg {jQuery} [$overlay] A jQuery element functioning as an overlay
|
|
|
|
* for popups.
|
2016-03-16 22:56:47 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationsWrapper = function MwEchoUiNotificationsWrapper( controller, model, config ) {
|
2016-03-16 22:56:47 +00:00
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.NotificationsWrapper.super.call( this, config );
|
2016-03-16 22:56:47 +00:00
|
|
|
|
|
|
|
// Mixin constructor
|
|
|
|
OO.ui.mixin.PendingElement.call( this, config );
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
this.controller = controller;
|
2016-03-16 22:56:47 +00:00
|
|
|
this.model = model;
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
this.notificationsWidget = new mw.echo.ui.NotificationsListWidget(
|
|
|
|
this.controller,
|
2016-03-16 22:56:47 +00:00
|
|
|
this.model,
|
|
|
|
{
|
|
|
|
$overlay: config.$overlay,
|
2016-04-10 13:31:02 +00:00
|
|
|
types: this.controller.getTypes(),
|
2016-03-16 22:56:47 +00:00
|
|
|
label: mw.msg( 'notifications' ),
|
|
|
|
icon: 'bell'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Initialize
|
|
|
|
this.$element
|
2016-05-19 20:38:46 +00:00
|
|
|
.addClass( 'mw-echo-notificationsWrapper' )
|
2016-03-16 22:56:47 +00:00
|
|
|
.append( this.notificationsWidget.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.NotificationsWrapper, OO.ui.Widget );
|
|
|
|
OO.mixinClass( mw.echo.ui.NotificationsWrapper, OO.ui.mixin.PendingElement );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event finishLoading
|
|
|
|
* Notifications have successfully finished being processed and are fully loaded
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the notifications panel
|
|
|
|
*
|
|
|
|
* @return {jQuery.Promise} A promise that is resolved when all notifications
|
|
|
|
* were fetched from the API and added to the model and UI.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationsWrapper.prototype.populate = function () {
|
|
|
|
var widget = this;
|
|
|
|
|
|
|
|
this.pushPending();
|
2016-04-10 13:31:02 +00:00
|
|
|
return this.controller.fetchLocalNotifications( true )
|
2018-02-10 10:43:11 +00:00
|
|
|
.catch( function ( errorObj ) {
|
2016-08-29 19:56:56 +00:00
|
|
|
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' ) );
|
|
|
|
}
|
|
|
|
} )
|
2016-03-16 22:56:47 +00:00
|
|
|
.always( function () {
|
|
|
|
widget.popPending();
|
|
|
|
widget.emit( 'finishLoading' );
|
|
|
|
widget.promiseRunning = false;
|
|
|
|
} );
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|