mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-09-24 18:59:40 +00:00
Hygiene: Break out _buildNotificationList
Make various properties of the overlay properties of EchoOverlay to reduce need for function parameters Change-Id: I70ec0c650d58322aad93d71292a836d7cf7e7474
This commit is contained in:
parent
3e9ae71dcd
commit
4470d91e54
|
@ -11,6 +11,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
EchoOverlay.prototype = {
|
EchoOverlay.prototype = {
|
||||||
|
/**
|
||||||
|
* @var array a list of unread notification ids that are visible in the UI
|
||||||
|
*/
|
||||||
|
unread: [],
|
||||||
|
/**
|
||||||
|
* @var object current count status of notification types
|
||||||
|
*/
|
||||||
|
notificationCount: {
|
||||||
|
/* @var integer length of all notifications (both unread and read) that will be visible in the overlay */
|
||||||
|
all: 0,
|
||||||
|
/* @var string a string representation the current number of unread notifications (1, 99, 99+) */
|
||||||
|
unread: '0',
|
||||||
|
/* @var integer the total number of all unread notifications including those not in the overlay */
|
||||||
|
unreadRaw: 0
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @param newCount formatted count
|
* @param newCount formatted count
|
||||||
* @param rawCount unformatted count
|
* @param rawCount unformatted count
|
||||||
|
@ -24,6 +39,8 @@
|
||||||
} else {
|
} else {
|
||||||
$badge.removeClass( 'mw-echo-unread-notifications' );
|
$badge.removeClass( 'mw-echo-unread-notifications' );
|
||||||
}
|
}
|
||||||
|
this.notificationCount.unread = newCount;
|
||||||
|
this.notificationCount.unreadRaw = rawCount;
|
||||||
},
|
},
|
||||||
|
|
||||||
configuration: mw.config.get( 'wgEchoOverlayConfiguration' ),
|
configuration: mw.config.get( 'wgEchoOverlayConfiguration' ),
|
||||||
|
@ -100,17 +117,13 @@
|
||||||
return $overlayFooter;
|
return $overlayFooter;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
_getTitleElement: function() {
|
||||||
* 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,
|
var titleText, includeMarkAsReadButton, overflow,
|
||||||
|
counter = this.notificationCount,
|
||||||
|
notificationsCount = counter.all,
|
||||||
|
unreadRawTotalCount = counter.unreadRaw,
|
||||||
|
unreadTotalCount = counter.unread,
|
||||||
|
unreadCount = this.unread.length,
|
||||||
$title = $( '<div>' ).addClass( 'mw-echo-overlay-title' );
|
$title = $( '<div>' ).addClass( 'mw-echo-overlay-title' );
|
||||||
|
|
||||||
if ( notificationsCount > 0 ) {
|
if ( notificationsCount > 0 ) {
|
||||||
|
@ -159,17 +172,18 @@
|
||||||
return $title;
|
return $title;
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildOverlay: function ( notifications ) {
|
/**
|
||||||
var $overlay = $( '<div>' ).addClass( 'mw-echo-overlay' ),
|
* Builds an Echo notifications list
|
||||||
self = this,
|
* @method
|
||||||
unread = [],
|
* @param object as returned by the api of notification items
|
||||||
unreadTotalCount = notifications.count,
|
* @return jQuery element
|
||||||
unreadRawTotalCount = notifications.rawcount,
|
*/
|
||||||
$ul = $( '<ul>' ).addClass( 'mw-echo-notifications' );
|
_buildNotificationList: function( notifications ) {
|
||||||
|
var self = this,
|
||||||
|
$ul = $( '<ul>' ).addClass( 'mw-echo-notifications' )
|
||||||
|
.css( 'max-height', $( window ).height() - 134 );
|
||||||
|
|
||||||
|
|
||||||
if ( unreadTotalCount !== undefined ) {
|
|
||||||
self.updateCount( unreadTotalCount, unreadRawTotalCount );
|
|
||||||
}
|
|
||||||
$.each( notifications.index, function ( index, id ) {
|
$.each( notifications.index, function ( index, id ) {
|
||||||
var $wrapper,
|
var $wrapper,
|
||||||
data = notifications.list[id],
|
data = notifications.list[id],
|
||||||
|
@ -185,9 +199,8 @@
|
||||||
|
|
||||||
if ( !data.read ) {
|
if ( !data.read ) {
|
||||||
$li.addClass( 'mw-echo-unread' );
|
$li.addClass( 'mw-echo-unread' );
|
||||||
unread.push( id );
|
self.unread.push( id );
|
||||||
}
|
}
|
||||||
$ul.css( 'max-height', $( window ).height() - 134 );
|
|
||||||
|
|
||||||
if ( !data['*'] ) {
|
if ( !data['*'] ) {
|
||||||
return;
|
return;
|
||||||
|
@ -234,7 +247,21 @@
|
||||||
mw.echo.setUpDismissability( $li );
|
mw.echo.setUpDismissability( $li );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
self._getTitleElement( notifications.index.length, unreadRawTotalCount, unreadTotalCount, unread.length ).
|
return $ul;
|
||||||
|
},
|
||||||
|
|
||||||
|
_buildOverlay: function ( notifications ) {
|
||||||
|
var $ul,
|
||||||
|
$overlay = $( '<div>' ).addClass( 'mw-echo-overlay' ),
|
||||||
|
self = this;
|
||||||
|
|
||||||
|
this.notificationCount.all = notifications.index.length;
|
||||||
|
if ( this.notificationCount.all !== undefined ) {
|
||||||
|
self.updateCount( notifications.count, notifications.rawcount );
|
||||||
|
}
|
||||||
|
|
||||||
|
$ul = self._buildNotificationList( notifications );
|
||||||
|
self._getTitleElement().
|
||||||
appendTo( $overlay );
|
appendTo( $overlay );
|
||||||
|
|
||||||
if ( $ul.find( 'li' ).length ) {
|
if ( $ul.find( 'li' ).length ) {
|
||||||
|
@ -242,22 +269,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$overlay.append( self._getFooterElement() );
|
$overlay.append( self._getFooterElement() );
|
||||||
self.markAsRead( unread );
|
self.markAsRead();
|
||||||
|
|
||||||
this.$el = $overlay;
|
this.$el = $overlay;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Mark a list of notifications as read
|
* Mark a list of notifications as read
|
||||||
* @method
|
* @method
|
||||||
* @param {array} unread a list of unread ids
|
|
||||||
*/
|
*/
|
||||||
markAsRead: function( unread ) {
|
markAsRead: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
// only need to mark as read if there is unread item
|
// only need to mark as read if there is unread item
|
||||||
if ( unread.length > 0 ) {
|
if ( this.unread.length ) {
|
||||||
this.api.post( mw.echo.desktop.appendUseLang( {
|
this.api.post( mw.echo.desktop.appendUseLang( {
|
||||||
'action' : 'echomarkread',
|
'action' : 'echomarkread',
|
||||||
'list' : unread.join( '|' ),
|
'list' : this.unread.join( '|' ),
|
||||||
'token': mw.user.tokens.get( 'editToken' )
|
'token': mw.user.tokens.get( 'editToken' )
|
||||||
} ) ).done( function ( result ) {
|
} ) ).done( function ( result ) {
|
||||||
var count;
|
var count;
|
||||||
|
|
Loading…
Reference in a new issue