/*global window:false */ ( function ( $, mw ) { 'use strict'; // backwards compatibility <= MW 1.21 var getUrl = mw.util.getUrl || mw.util.wikiGetlink; function EchoOverlay( apiResultNotifications ) { this.api = mw.echo.overlay.api; // set internal properties this.tabs = []; this._buildOverlay( apiResultNotifications ); } function EchoOverlayTab( options, notifications ) { this.api = mw.echo.overlay.api; this.markOnView = options.markOnView; this.markAsReadCallback = options.markAsReadCallback; this.name = options.name; this.unread = []; this._buildList( notifications[this.name] ); } EchoOverlayTab.prototype = { unread: [], getUnreadIds: function() { return this.unread; }, /** * Mark all existing notifications as read * @method * @param integer id of a notification to mark as read * @return jQuery.Deferred */ markAsRead: function( id ) { var self = this, data; // only need to mark as read if there is unread item if ( this.unread.length ) { data = { 'action' : 'echomarkread', 'token': mw.user.tokens.get( 'editToken' ) }; if ( id ) { // If id is given mark that as read otherwise use all unread messages data.list = id; } else { data.all = 1; } return this.api.post( mw.echo.desktop.appendUseLang( data ) ).then( function ( result ) { return result.query.echomarkread; } ).done( function( result ) { // reset internal state of unread messages if ( id ) { if ( self.unread.indexOf( id ) > -1 ) { self.unread.splice( self.unread.indexOf( id ), 1 ); } } else { self.unread = []; } self.markAsReadCallback( result, id ); } ); } else { return new $.Deferred(); } }, /** * Builds an Echo notifications list * @method * @param string tabName the tab * @param object notifications as returned by the api of notification items * @return jQuery element */ _buildList: function( notifications ) { var self = this, $container = $( '
' ) .data( 'tab', this ) .css( 'max-height', $( window ).height() - 134 ), $ul = $( '