Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.NotificationsWrapper.js

raw symbols SCIP
1 ( function () {
2 /**
3 * Wrapper for the notifications widget, for view outside the popup.
4 *
5 * @class
6 * @extends OO.ui.Widget
7 * @mixes OO.ui.mixin.PendingElement
8 *
9 * @constructor
10 * @param {mw.echo.Controller} controller Echo controller
11 * @param {mw.echo.dm.ModelManager} model Notifications model manager
12 * @param {Object} [config] Configuration object
13 * @param {jQuery} [config.$overlay] A jQuery element functioning as an overlay
14 * for popups.
15 */
16 mw.echo.ui.NotificationsWrapper = function MwEchoUiNotificationsWrapper( controller, model, config ) {
17 config = config || {};
18
19 // Parent constructor
20 mw.echo.ui.NotificationsWrapper.super.call( this, config );
21
22 // Mixin constructor
23 OO.ui.mixin.PendingElement.call( this, config );
24
25 this.controller = controller;
26 this.model = model;
27
28 this.notificationsWidget = new mw.echo.ui.NotificationsListWidget(
29 this.controller,
30 this.model,
31 {
32 $overlay: config.$overlay,
33 types: this.controller.getTypes(),
34 label: mw.msg( 'notifications' ),
35 icon: 'bell'
36 }
37 );
38
39 // Initialize
40 this.$element
41 .addClass( 'mw-echo-notificationsWrapper skin-invert' )
42 .append( this.notificationsWidget.$element );
43 };
44
45 /* Initialization */
46
47 OO.inheritClass( mw.echo.ui.NotificationsWrapper, OO.ui.Widget );
48 OO.mixinClass( mw.echo.ui.NotificationsWrapper, OO.ui.mixin.PendingElement );
49
50 /* Events */
51
52 /**
53 * Notifications have successfully finished being processed and are fully loaded
54 *
55 * @event mw.echo.ui.NotificationsWrapper#finishLoading
56 */
57
58 /* Methods */
59
60 /**
61 * Populate the notifications panel
62 *
63 * @return {jQuery.Promise} A promise that is resolved when all notifications
64 * were fetched from the API and added to the model and UI.
65 * @fires mw.echo.ui.NotificationsWrapper#finishLoading
66 */
67 mw.echo.ui.NotificationsWrapper.prototype.populate = function () {
68 this.pushPending();
69 return this.controller.fetchLocalNotifications( true )
70 .catch( ( errorObj ) => {
71 if ( errorObj.errCode === 'notlogin-required' ) {
72 // Login required message
73 this.notificationsWidget.resetLoadingOption( mw.msg( 'echo-notification-loginrequired' ) );
74 } else {
75 // Generic API failure message
76 this.notificationsWidget.resetLoadingOption( mw.msg( 'echo-api-failure' ) );
77 }
78 } )
79 .always( () => {
80 this.popPending();
81 this.emit( 'finishLoading' );
82 this.promiseRunning = false;
83 } );
84 };
85 }() );