jenkins-bot has submitted this change and it was merged.

Change subject: Initialize notifications model outside of the widget
......................................................................


Initialize notifications model outside of the widget

Change-Id: I19c239326b04eaa07b62e0b06f181c86ff0a0ef8
---
M modules/ext.echo.init.js
M modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
2 files changed, 32 insertions(+), 20 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ext.echo.init.js b/modules/ext.echo.init.js
index a40f819..0d84e4f 100644
--- a/modules/ext.echo.init.js
+++ b/modules/ext.echo.init.js
@@ -53,10 +53,22 @@
 
                        // Load the ui
                        mw.loader.using( 'ext.echo.ui', function () {
+                               var messageNotificationsModel, 
alertNotificationsModel;
+
                                // Load message button and popup if messages 
exist
                                if ( $existingMessageLink.length ) {
-                                       mw.echo.ui.messageWidget = new 
mw.echo.ui.NotificationBadgeWidget( {
-                                               type: 'message',
+                                       messageNotificationsModel = new 
mw.echo.dm.NotificationsModel(
+                                               new mw.echo.dm.APIHandler( {
+                                                       type: 'message',
+                                                       limit: 25,
+                                                       userLang: 
mw.config.get( 'wgUserLanguage' ),
+                                                       baseParams: 
mw.echo.apiCallParams
+                                               } ),
+                                               {
+                                                       type: 'message'
+                                               }
+                                       );
+                                       mw.echo.ui.messageWidget = new 
mw.echo.ui.NotificationBadgeWidget( messageNotificationsModel, {
                                                markReadWhenSeen: false,
                                                numItems: numMessages,
                                                hasUnseen: hasUnseenMessages,
@@ -78,8 +90,18 @@
                                }
 
                                // Load alerts popup and button
-                               mw.echo.ui.alertWidget = new 
mw.echo.ui.NotificationBadgeWidget( {
-                                       type: 'alert',
+                               alertNotificationsModel = new 
mw.echo.dm.NotificationsModel(
+                                       new mw.echo.dm.APIHandler( {
+                                               type: 'alert',
+                                               limit: 25,
+                                               userLang: mw.config.get( 
'wgUserLanguage' ),
+                                               baseParams: 
mw.echo.apiCallParams
+                                       } ),
+                                       {
+                                               type: 'alert'
+                                       }
+                               );
+                               mw.echo.ui.alertWidget = new 
mw.echo.ui.NotificationBadgeWidget( alertNotificationsModel, {
                                        markReadWhenSeen: true,
                                        numItems: numAlerts,
                                        hasUnseen: hasUnseenAlerts,
diff --git a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js 
b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
index 3d764f6..34961b0 100644
--- a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
@@ -6,8 +6,8 @@
         * @extends OO.ui.ButtonWidget
         *
         * @constructor
+        * @param {mw.echo.dm.NotificationsModel} model Notifications view model
         * @param {Object} [config] Configuration object
-        * @cfg {string} [type='alert'] Notification type 'alert' or 'message'
         * @cfg {number} [numItems=0] How many items are in the button display
         * @cfg {boolean} [hasUnseen=false] Whether there are unseen items
         * @cfg {boolean} [markReadWhenSeen=false] Mark all notifications as 
read on open
@@ -22,7 +22,7 @@
         *  } }
         * @cfg {string} [href] URL the badge links to
         */
-       mw.echo.ui.NotificationBadgeWidget = function 
MwEchoUiNotificationBadgeButtonPopupWidget( config ) {
+       mw.echo.ui.NotificationBadgeWidget = function 
MwEchoUiNotificationBadgeButtonPopupWidget( model, config ) {
                var buttonFlags, allNotificationsButton, preferencesButton, 
footerButtonGroupWidget, $footer;
 
                config = config || {};
@@ -34,7 +34,10 @@
                // Mixin constructors
                OO.ui.mixin.PendingElement.call( this, config );
 
-               this.type = config.type || 'alert';
+               // View model
+               this.notificationsModel = model;
+               this.type = this.notificationsModel.getType();
+
                this.numItems = config.numItems || 0;
                this.markReadWhenSeen = !!config.markReadWhenSeen;
                this.badgeIcon = config.badgeIcon || {};
@@ -56,19 +59,6 @@
                        title: mw.msg( 'tooltip-pt-notifications-' + this.type 
),
                        href: config.href
                } );
-
-               // View model
-               this.notificationsModel = new mw.echo.dm.NotificationsModel(
-                       new mw.echo.dm.APIHandler( {
-                               type: this.type,
-                               limit: 25,
-                               userLang: mw.config.get( 'wgUserLanguage' ),
-                               baseParams: mw.echo.apiCallParams
-                       } ),
-                       {
-                               type: this.type
-                       }
-               );
 
                // Notifications widget
                this.notificationsWidget = new mw.echo.ui.NotificationsWidget(

-- 
To view, visit https://gerrit.wikimedia.org/r/249008
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I19c239326b04eaa07b62e0b06f181c86ff0a0ef8
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to