2013-06-18 15:23:35 +00:00
|
|
|
( function ( $, mw ) {
|
2012-12-07 01:08:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
mw.echo.special = {
|
|
|
|
|
2013-06-12 00:44:01 +00:00
|
|
|
notcontinue: null,
|
|
|
|
header: '',
|
|
|
|
processing: false,
|
2013-01-14 23:52:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the property in special notification page.
|
2012-12-07 01:08:33 +00:00
|
|
|
*/
|
2013-06-18 15:23:35 +00:00
|
|
|
initialize: function () {
|
2013-06-12 01:01:41 +00:00
|
|
|
var skin = mw.config.get('skin');
|
2013-06-02 20:04:29 +00:00
|
|
|
|
2013-04-09 22:38:36 +00:00
|
|
|
// Convert more link into a button
|
|
|
|
$( '#mw-echo-more' )
|
2013-09-09 22:28:39 +00:00
|
|
|
.addClass( 'mw-ui-button mw-ui-primary' )
|
2013-04-09 22:38:36 +00:00
|
|
|
.css( 'margin', '0.5em 0 0 0' )
|
2013-06-18 15:23:35 +00:00
|
|
|
.click( function ( e ) {
|
2012-12-07 01:08:33 +00:00
|
|
|
e.preventDefault();
|
2013-06-12 01:01:41 +00:00
|
|
|
if ( !mw.echo.special.processing ) {
|
|
|
|
mw.echo.special.processing = true;
|
|
|
|
mw.echo.special.loadMore();
|
2012-12-15 01:44:07 +00:00
|
|
|
}
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
|
|
|
);
|
2013-06-12 01:01:41 +00:00
|
|
|
mw.echo.special.notcontinue = mw.config.get( 'wgEchoNextContinue' );
|
|
|
|
mw.echo.special.header = mw.config.get( 'wgEchoDateHeader' );
|
2013-01-04 21:56:30 +00:00
|
|
|
|
2013-06-05 20:44:06 +00:00
|
|
|
// Set up each individual notification with eventlogging, a close
|
|
|
|
// box and dismiss interface if it is dismissable.
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '.mw-echo-notification' ).each( function () {
|
2013-06-05 20:44:06 +00:00
|
|
|
mw.echo.setupNotificationLogging( $( this ), 'archive' );
|
2013-01-14 23:52:46 +00:00
|
|
|
if ( $( this ).find( '.mw-echo-dismiss' ).length ) {
|
2013-02-13 02:08:36 +00:00
|
|
|
mw.echo.setUpDismissability( this );
|
2013-01-14 23:52:46 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '#mw-echo-moreinfo-link' ).click( function () {
|
2013-06-05 20:44:06 +00:00
|
|
|
mw.echo.logInteraction( 'ui-help-click', 'archive' );
|
|
|
|
} );
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '#mw-echo-pref-link' ).click( function () {
|
2013-06-05 20:44:06 +00:00
|
|
|
mw.echo.logInteraction( 'ui-prefs-click', 'archive' );
|
|
|
|
} );
|
|
|
|
|
2013-08-04 12:28:25 +00:00
|
|
|
// Convert subtitle links into header icons for Vector and Monobook skins
|
2013-06-02 20:04:29 +00:00
|
|
|
if ( skin === 'vector' || skin === 'monobook' ) {
|
2013-08-04 12:28:25 +00:00
|
|
|
$( '#mw-echo-moreinfo-link, #mw-echo-pref-link' )
|
|
|
|
.empty()
|
2013-06-02 20:04:29 +00:00
|
|
|
.appendTo( '#firstHeading' );
|
|
|
|
$( '#contentSub' ).empty();
|
|
|
|
}
|
2013-04-12 18:52:34 +00:00
|
|
|
|
2012-12-07 01:08:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-01-14 23:52:46 +00:00
|
|
|
* Load more notification records.
|
2012-12-07 01:08:33 +00:00
|
|
|
*/
|
2013-06-18 15:23:35 +00:00
|
|
|
loadMore: function () {
|
2013-09-25 00:18:02 +00:00
|
|
|
var api = new mw.Api( { ajax: { cache: false } } ),
|
2013-08-27 00:55:45 +00:00
|
|
|
notifications, data, container, $li, that = this, unread = [], apiData;
|
2013-06-18 15:23:35 +00:00
|
|
|
|
2013-08-27 00:55:45 +00:00
|
|
|
apiData = {
|
2013-06-18 15:23:35 +00:00
|
|
|
'action' : 'query',
|
|
|
|
'meta' : 'notifications',
|
|
|
|
'notformat' : 'html',
|
|
|
|
'notprop' : 'index|list',
|
|
|
|
'notcontinue': this.notcontinue,
|
|
|
|
'notlimit': mw.config.get( 'wgEchoDisplayNum' )
|
2013-08-27 00:55:45 +00:00
|
|
|
};
|
|
|
|
|
2013-09-25 00:18:02 +00:00
|
|
|
api.get( mw.echo.desktop.appendUseLang( apiData ) ).done( function ( result ) {
|
2013-06-18 15:23:35 +00:00
|
|
|
container = $( '#mw-echo-special-container' );
|
|
|
|
notifications = result.query.notifications;
|
|
|
|
unread = [];
|
|
|
|
|
|
|
|
$.each( notifications.index, function ( index, id ) {
|
|
|
|
data = notifications.list[id];
|
|
|
|
|
|
|
|
if ( that.header !== data.timestamp.date ) {
|
|
|
|
that.header = data.timestamp.date;
|
|
|
|
$( '<li></li>' ).addClass( 'mw-echo-date-section' ).append( that.header ).appendTo( container );
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
2013-06-18 15:23:35 +00:00
|
|
|
|
|
|
|
$li = $( '<li></li>' )
|
|
|
|
.data( 'details', data )
|
|
|
|
.data( 'id', id )
|
|
|
|
.addClass( 'mw-echo-notification' )
|
|
|
|
.attr( {
|
|
|
|
'data-notification-category': data.category,
|
|
|
|
'data-notification-event': data.id,
|
|
|
|
'data-notification-type': data.type
|
|
|
|
} )
|
|
|
|
.append( data['*'] )
|
|
|
|
.appendTo( container );
|
|
|
|
|
|
|
|
if ( !data.read ) {
|
|
|
|
$li.addClass( 'mw-echo-unread' );
|
|
|
|
unread.push( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
mw.echo.setupNotificationLogging( $li, 'archive' );
|
|
|
|
|
|
|
|
if ( $li.find( '.mw-echo-dismiss' ).length ) {
|
|
|
|
mw.echo.setUpDismissability( $li );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
that.notcontinue = notifications['continue'];
|
|
|
|
if ( unread.length > 0 ) {
|
|
|
|
that.markAsRead( unread );
|
|
|
|
} else {
|
|
|
|
that.onSuccess();
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
2013-06-18 15:23:35 +00:00
|
|
|
} ).fail( function () {
|
|
|
|
that.onError();
|
|
|
|
} );
|
2012-12-15 01:44:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-01-14 23:52:46 +00:00
|
|
|
* Mark notifications as read.
|
2012-12-15 01:44:07 +00:00
|
|
|
*/
|
2013-06-18 15:23:35 +00:00
|
|
|
markAsRead: function ( unread ) {
|
2014-09-05 21:30:45 +00:00
|
|
|
var newCount, rawCount, $badge,
|
|
|
|
api = new mw.Api(), that = this;
|
2012-12-15 01:44:07 +00:00
|
|
|
|
2013-09-25 00:18:02 +00:00
|
|
|
api.post( mw.echo.desktop.appendUseLang( {
|
2013-09-18 21:10:37 +00:00
|
|
|
'action' : 'echomarkread',
|
|
|
|
'list' : unread.join( '|' ),
|
|
|
|
'token': mw.user.tokens.get( 'editToken' )
|
2013-09-25 00:18:02 +00:00
|
|
|
} ) ).done( function ( result ) {
|
2013-06-18 15:23:35 +00:00
|
|
|
// update the badge if the link is enabled
|
2013-09-18 21:10:37 +00:00
|
|
|
if ( result.query.echomarkread.count !== undefined &&
|
2014-09-05 21:30:45 +00:00
|
|
|
$( '#pt-notifications').length
|
2013-06-18 15:23:35 +00:00
|
|
|
) {
|
2014-09-05 21:30:45 +00:00
|
|
|
newCount = result.query.echomarkread.count;
|
|
|
|
rawCount = result.query.echomarkread.rawcount;
|
|
|
|
$badge = mw.echo.getBadge();
|
|
|
|
$badge.text( newCount );
|
|
|
|
|
|
|
|
if ( rawCount !== '0' && rawCount !== 0 ) {
|
|
|
|
$badge.addClass( 'mw-echo-unread-notifications' );
|
|
|
|
} else {
|
|
|
|
$badge.removeClass( 'mw-echo-unread-notifications' );
|
|
|
|
}
|
2012-12-15 01:44:07 +00:00
|
|
|
}
|
2013-06-18 15:23:35 +00:00
|
|
|
that.onSuccess();
|
|
|
|
} ).fail( function () {
|
|
|
|
that.onError();
|
2012-12-15 01:44:07 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
onSuccess: function () {
|
2013-05-03 23:58:56 +00:00
|
|
|
if ( !this.notcontinue ) {
|
2012-12-15 01:44:07 +00:00
|
|
|
$( '#mw-echo-more' ).hide();
|
|
|
|
}
|
|
|
|
this.processing = false;
|
|
|
|
},
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
onError: function () {
|
2012-12-15 01:44:07 +00:00
|
|
|
// Todo: Show detail error message based on error code
|
|
|
|
$( '#mw-echo-more' ).text( mw.msg( 'echo-load-more-error' ) );
|
|
|
|
this.processing = false;
|
2012-12-07 01:08:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-11 20:01:23 +00:00
|
|
|
$( document ).ready( mw.echo.special.initialize );
|
2012-12-07 01:08:33 +00:00
|
|
|
|
|
|
|
} )( jQuery, mediaWiki );
|