2013-06-18 15:23:35 +00:00
|
|
|
( function ( $, mw ) {
|
2012-12-07 01:08:33 +00:00
|
|
|
'use strict';
|
2015-06-26 00:13:28 +00:00
|
|
|
var useLang = mw.config.get( 'wgUserLanguage' );
|
2012-12-07 01:08:33 +00:00
|
|
|
|
|
|
|
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 () {
|
2015-05-04 19:24:37 +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-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 () {
|
2015-08-13 00:54:16 +00:00
|
|
|
mw.echo.logger.logInteraction(
|
|
|
|
'notification-impression',
|
|
|
|
mw.echo.Logger.static.context.archive,
|
|
|
|
Number( $( this ).attr( 'data-notification-event' ) ),
|
|
|
|
$( this ).attr( 'data-notification-type' )
|
|
|
|
);
|
2013-01-14 23:52:46 +00:00
|
|
|
} );
|
|
|
|
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '#mw-echo-moreinfo-link' ).click( function () {
|
2015-08-13 00:54:16 +00:00
|
|
|
mw.echo.logger.logInteraction( 'ui-help-click', mw.echo.Logger.static.context.archive );
|
2013-06-05 20:44:06 +00:00
|
|
|
} );
|
2013-06-18 15:23:35 +00:00
|
|
|
$( '#mw-echo-pref-link' ).click( function () {
|
2015-08-13 00:54:16 +00:00
|
|
|
mw.echo.logger.logInteraction( 'ui-prefs-click', mw.echo.Logger.static.context.archive );
|
2013-06-05 20:44:06 +00:00
|
|
|
} );
|
|
|
|
|
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 () {
|
2015-05-04 19:24:37 +00:00
|
|
|
var notifications, data, container, $li,
|
|
|
|
api = new mw.Api( { ajax: { cache: false } } ),
|
2015-08-24 23:43:38 +00:00
|
|
|
seenTime = mw.config.get( 'wgEchoSeenTime' ),
|
2015-05-04 19:24:37 +00:00
|
|
|
that = this,
|
|
|
|
unread = [],
|
|
|
|
apiData = {
|
|
|
|
action: 'query',
|
|
|
|
meta: 'notifications',
|
|
|
|
notformat: 'html',
|
|
|
|
notprop: 'index|list',
|
|
|
|
notcontinue: this.notcontinue,
|
|
|
|
notlimit: mw.config.get( 'wgEchoDisplayNum' ),
|
2015-06-26 00:13:28 +00:00
|
|
|
uselang: useLang
|
2015-05-04 19:24:37 +00:00
|
|
|
};
|
2013-08-27 00:55:45 +00:00
|
|
|
|
2014-08-12 15:09:09 +00:00
|
|
|
api.get( 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 );
|
|
|
|
}
|
|
|
|
|
2015-04-29 12:08:30 +00:00
|
|
|
if ( seenTime !== null && data.timestamp.mw > seenTime ) {
|
|
|
|
$li.addClass( 'mw-echo-unseen' );
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
mw.echo.logger.logInteraction(
|
|
|
|
'notification-impression',
|
|
|
|
mw.echo.Logger.static.context.archive,
|
|
|
|
Number( $li.attr( 'data-notification-event' ) ),
|
|
|
|
$li.attr( 'data-notification-type' )
|
|
|
|
);
|
2013-06-18 15:23:35 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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 ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
var api = new mw.Api(),
|
2015-05-04 19:24:37 +00:00
|
|
|
that = this;
|
2015-06-08 00:24:09 +00:00
|
|
|
api.postWithToken( 'edit', {
|
2015-05-04 19:24:37 +00:00
|
|
|
action: 'echomarkread',
|
|
|
|
list: unread.join( '|' ),
|
2015-06-26 00:13:28 +00:00
|
|
|
uselang: useLang
|
2015-08-13 00:54:16 +00:00
|
|
|
} ).done( function () {
|
|
|
|
// HACK: We should really redo the way the entire special
|
|
|
|
// page handles the notifications now that they are separated
|
|
|
|
// into 'alert' and 'messages'. However, until that happens,
|
|
|
|
// the badges should be updated individually.
|
|
|
|
// Don't try this at home.
|
|
|
|
mw.echo.ui.messageWidget.fetchUnreadCountFromApi();
|
|
|
|
mw.echo.ui.alertWidget.fetchUnreadCountFromApi();
|
|
|
|
|
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 );
|