Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/151984

Change subject: Hygiene: Move code for header into _getTitleElement
......................................................................

Hygiene: Move code for header into _getTitleElement

Change-Id: Ic53933189bf51772a88689794a7633ba8ba0ac2c
---
M modules/overlay/ext.echo.overlay.js
1 file changed, 63 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/84/151984/1

diff --git a/modules/overlay/ext.echo.overlay.js 
b/modules/overlay/ext.echo.overlay.js
index c724e1e..70b8c8f 100644
--- a/modules/overlay/ext.echo.overlay.js
+++ b/modules/overlay/ext.echo.overlay.js
@@ -122,6 +122,66 @@
                        );
                        return $overlayFooter;
                },
+
+               /**
+                * Builds an Echo overlay header element
+                * @method
+                * @param integer length of all notifications (both unread and 
read) that will be visible in the overlay
+                * @param integer the total number of all unread notifications 
including those not in the overlay
+                * @param string a string representation the current number of 
unread notifications (1, 99, 99+)
+                * @param integer the number of unread notifications in the 
current overlay
+                * @return jQuery element
+                */
+               _getTitleElement: function( notificationsCount, 
unreadRawTotalCount, unreadTotalCount, unreadCount ) {
+                       var titleText, includeMarkAsReadButton, overflow,
+                               $title = $( '<div>' ).addClass( 
'mw-echo-overlay-title' );
+
+                       if ( notificationsCount > 0 ) {
+                               if ( unreadRawTotalCount > unreadCount ) {
+                                       titleText = mw.msg(
+                                               'echo-overlay-title-overflow',
+                                               mw.language.convertNumber( 
unreadCount ),
+                                               mw.language.convertNumber( 
unreadTotalCount )
+                                       );
+                                       overflow = true;
+                               } else {
+                                       titleText = mw.msg( 
'echo-overlay-title' );
+                                       overflow = false;
+                               }
+                       } else {
+                               titleText = mw.msg( 'echo-none' );
+                       }
+                       // If there are more unread notifications than can fit 
in the overlay,
+                       // but fewer than the maximum count, show the 'mark all 
as read' button.
+                       // The only reason we limit it to the maximum is to 
prevent expensive
+                       // database updates. If the count is more than the 
maximum, it could
+                       // be thousands.
+                       includeMarkAsReadButton = overflow &&
+                               unreadRawTotalCount < 
mw.echo.overlay.configuration[ 'max-notification-count' ];
+                       if ( includeMarkAsReadButton ) {
+                               // Add the 'mark all as read' button to the 
title area
+                               $title.append( this._getMarkAsReadButton() );
+                       }
+
+                       // Add the header to the title area
+                       $( '<div>' )
+                       .attr( 'id', 'mw-echo-overlay-title-text' )
+                       .html( titleText )
+                       .appendTo( $title );
+
+                       // Add help button
+                       $( '<a>' )
+                               .attr( 'href', mw.config.get( 'wgEchoHelpPage' 
) )
+                               .attr( 'title', mw.msg( 'echo-more-info' ) )
+                               .attr( 'id', 'mw-echo-overlay-moreinfo-link' )
+                               .attr( 'target', '_blank' )
+                               .click( function () {
+                                       mw.echo.logInteraction( 
'ui-help-click', 'flyout' );
+                               } )
+                               .appendTo( $title );
+                       return $title;
+               },
+
                /**
                 * Builds an overlay element
                 * @method
@@ -146,10 +206,7 @@
                                        unread = [],
                                        unreadTotalCount = 
result.query.notifications.count,
                                        unreadRawTotalCount = 
result.query.notifications.rawcount,
-                                       $title = $( '<div>' ).addClass( 
'mw-echo-overlay-title' ),
-                                       $ul = $( '<ul>' ).addClass( 
'mw-echo-notifications' ),
-                                       titleText,
-                                       overflow;
+                                       $ul = $( '<ul>' ).addClass( 
'mw-echo-notifications' );
 
                                if ( unreadTotalCount !== undefined ) {
                                        mw.echo.overlay.updateCount( 
unreadTotalCount, unreadRawTotalCount );
@@ -218,53 +275,8 @@
                                                mw.echo.setUpDismissability( 
$li );
                                        }
                                } );
-
-                               if ( notifications.index.length > 0 ) {
-                                       if ( unreadRawTotalCount > 
unread.length ) {
-                                               titleText = mw.msg(
-                                                       
'echo-overlay-title-overflow',
-                                                       
mw.language.convertNumber( unread.length ),
-                                                       
mw.language.convertNumber( unreadTotalCount )
-                                               );
-                                               overflow = true;
-                                       } else {
-                                               titleText = mw.msg( 
'echo-overlay-title' );
-                                               overflow = false;
-                                       }
-                               } else {
-                                       titleText = mw.msg( 'echo-none' );
-                               }
-
-                               // If there are more unread notifications than 
can fit in the overlay,
-                               // but fewer than the maximum count, show the 
'mark all as read' button.
-                               // The only reason we limit it to the maximum 
is to prevent expensive
-                               // database updates. If the count is more than 
the maximum, it could
-                               // be thousands.
-                               if ( overflow && unreadRawTotalCount < 
mw.echo.overlay.configuration['max-notification-count']
-                               ) {
-                                       // Add the 'mark all as read' button to 
the title area
-                                       $title.append( 
self._getMarkAsReadButton() );
-                               }
-
-                               // Add the header to the title area
-                               $( '<div>' )
-                               .attr( 'id', 'mw-echo-overlay-title-text' )
-                               .html( titleText )
-                               .appendTo( $title );
-
-                               // Add help button
-                               $( '<a>' )
-                                       .attr( 'href', mw.config.get( 
'wgEchoHelpPage' ) )
-                                       .attr( 'title', mw.msg( 
'echo-more-info' ) )
-                                       .attr( 'id', 
'mw-echo-overlay-moreinfo-link' )
-                                       .attr( 'target', '_blank' )
-                                       .click( function () {
-                                               mw.echo.logInteraction( 
'ui-help-click', 'flyout' );
-                                       } )
-                                       .appendTo( $title );
-
-                               // Insert the title area into the overlay
-                               $title.appendTo( $overlay );
+                               self._getTitleElement( 
notifications.index.length, unreadRawTotalCount, unreadTotalCount, 
unread.length ).
+                                       appendTo( $overlay );
 
                                if ( $ul.find( 'li' ).length ) {
                                        $ul.appendTo( $overlay );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic53933189bf51772a88689794a7633ba8ba0ac2c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to