2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-06-29 23:36:03 +00:00
|
|
|
/**
|
|
|
|
* Widget for the settings menu in the Special:Notifications page
|
|
|
|
*
|
|
|
|
* @param {mw.echo.dm.ModelManager} manager Model manager
|
|
|
|
* @param {Object} config Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {string} [config.prefLink] Link to preferences page
|
2016-06-29 23:36:03 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.SpecialHelpMenuWidget = function MwEchoUiSpecialHelpMenuWidget( manager, config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.SpecialHelpMenuWidget.super.call( this, $.extend( {
|
2019-02-07 14:41:55 +00:00
|
|
|
icon: 'settings',
|
2020-05-18 19:34:40 +00:00
|
|
|
label: mw.msg( 'echo-specialpage-special-help-menu-widget-aria-label' ),
|
2019-02-07 14:41:55 +00:00
|
|
|
indicator: 'down',
|
2020-05-18 19:34:40 +00:00
|
|
|
invisibleLabel: true,
|
2018-05-22 11:40:49 +00:00
|
|
|
menu: {
|
|
|
|
classes: [ 'mw-echo-ui-specialHelpMenuWidget-menu' ],
|
|
|
|
horizontalPosition: 'end',
|
|
|
|
width: 'auto'
|
2016-06-29 23:36:03 +00:00
|
|
|
}
|
|
|
|
}, config ) );
|
|
|
|
|
|
|
|
this.manager = manager;
|
|
|
|
|
2018-05-22 11:40:49 +00:00
|
|
|
this.markAllReadOption = new OO.ui.MenuOptionWidget( {
|
2018-03-22 21:21:06 +00:00
|
|
|
icon: 'checkAll',
|
2023-04-21 11:53:26 +00:00
|
|
|
label: this.getMarkAllReadOptionLabel(
|
|
|
|
this.manager.getPaginationModel().getCurrentPageItemCount()
|
|
|
|
),
|
2018-05-22 11:40:49 +00:00
|
|
|
data: 'markAllRead'
|
2016-06-29 23:36:03 +00:00
|
|
|
} );
|
2018-05-22 11:40:49 +00:00
|
|
|
this.markAllReadOption.toggle( false );
|
2016-06-29 23:36:03 +00:00
|
|
|
|
2018-05-22 11:40:49 +00:00
|
|
|
this.menu.addItems( [ this.markAllReadOption ] );
|
2016-07-23 00:23:54 +00:00
|
|
|
if ( config.prefLink ) {
|
2018-05-22 11:40:49 +00:00
|
|
|
this.menu.addItems( [
|
2016-07-23 00:23:54 +00:00
|
|
|
// Preferences link
|
2018-05-22 11:40:49 +00:00
|
|
|
new OO.ui.MenuOptionWidget( {
|
|
|
|
// Use link for accessibility
|
|
|
|
$element: $( '<a>' ).attr( 'href', config.prefLink ),
|
2018-09-08 02:54:20 +00:00
|
|
|
icon: 'settings',
|
2016-07-23 00:23:54 +00:00
|
|
|
label: mw.msg( 'mypreferences' ),
|
2018-05-22 11:40:49 +00:00
|
|
|
data: { href: config.prefLink }
|
2016-07-23 00:23:54 +00:00
|
|
|
} )
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
// Events
|
|
|
|
this.manager.connect( this, {
|
|
|
|
localCountChange: 'onLocalCountChange'
|
|
|
|
} );
|
|
|
|
this.manager.getFiltersModel().getSourcePagesModel().connect( this, { update: 'onSourcePageUpdate' } );
|
2018-05-22 11:40:49 +00:00
|
|
|
this.menu.connect( this, { choose: 'onMenuChoose' } );
|
2016-06-29 23:36:03 +00:00
|
|
|
|
2018-05-22 11:40:49 +00:00
|
|
|
this.$element.addClass( 'mw-echo-ui-specialHelpMenuWidget' );
|
2016-06-29 23:36:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
2020-04-15 10:59:49 +00:00
|
|
|
OO.inheritClass( mw.echo.ui.SpecialHelpMenuWidget, OO.ui.ButtonMenuSelectWidget );
|
2016-06-29 23:36:03 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark all notifications as read in the selected wiki
|
2024-04-30 14:21:54 +00:00
|
|
|
*
|
|
|
|
* @event mw.echo.ui.SpecialHelpMenuWidget#markAllRead
|
2016-06-29 23:36:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to source page change
|
|
|
|
*/
|
|
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.onSourcePageUpdate = function () {
|
2023-04-21 11:53:26 +00:00
|
|
|
var sourcePagesModel = this.manager.getFiltersModel().getSourcePagesModel(),
|
|
|
|
source = sourcePagesModel.getCurrentSource(),
|
|
|
|
sourcePages = sourcePagesModel.getSourcePages( source ),
|
|
|
|
currentPage = sourcePagesModel.getCurrentPage(),
|
|
|
|
currentCount = currentPage ?
|
|
|
|
sourcePages[ currentPage ].count :
|
|
|
|
sourcePagesModel.getSourceTotalCount( source );
|
|
|
|
|
|
|
|
this.markAllReadOption.setLabel( this.getMarkAllReadOptionLabel( currentCount ) );
|
2016-06-29 23:36:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to local counter update event
|
2016-11-18 21:16:43 +00:00
|
|
|
*
|
|
|
|
* @param {number} count New count
|
2016-06-29 23:36:03 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.onLocalCountChange = function ( count ) {
|
2023-04-21 11:53:26 +00:00
|
|
|
this.markAllReadOption.setLabel( this.getMarkAllReadOptionLabel( count ) );
|
2018-05-22 11:40:49 +00:00
|
|
|
this.markAllReadOption.toggle( count > 0 );
|
2016-06-29 23:36:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-04-15 10:59:49 +00:00
|
|
|
* Handle menu choose events
|
2018-05-22 11:40:49 +00:00
|
|
|
*
|
|
|
|
* @param {OO.ui.MenuOptionWidget} item Chosen item
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.ui.SpecialHelpMenuWidget#markAllRead
|
2016-06-29 23:36:03 +00:00
|
|
|
*/
|
2018-05-22 11:40:49 +00:00
|
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.onMenuChoose = function ( item ) {
|
|
|
|
var data = item.getData();
|
|
|
|
if ( data.href ) {
|
|
|
|
location.href = data.href;
|
|
|
|
} else if ( data === 'markAllRead' ) {
|
|
|
|
this.emit( 'markAllRead' );
|
|
|
|
}
|
2016-06-29 23:36:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the button label
|
|
|
|
*
|
2023-04-21 11:53:26 +00:00
|
|
|
* @param {number} count Number of unread notifications
|
2016-06-29 23:36:03 +00:00
|
|
|
* @return {string} Mark all read button label
|
|
|
|
*/
|
2023-04-21 11:53:26 +00:00
|
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.getMarkAllReadOptionLabel = function ( count ) {
|
2016-06-29 23:36:03 +00:00
|
|
|
var pageModel = this.manager.getFiltersModel().getSourcePagesModel(),
|
|
|
|
source = pageModel.getCurrentSource(),
|
|
|
|
sourceTitle = pageModel.getSourceTitle( source );
|
|
|
|
|
|
|
|
return sourceTitle ?
|
2023-04-21 11:53:26 +00:00
|
|
|
mw.msg( 'echo-mark-wiki-as-read', sourceTitle, count ) :
|
|
|
|
mw.msg( 'echo-mark-all-as-read', count );
|
2016-06-29 23:36:03 +00:00
|
|
|
};
|
|
|
|
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|