mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
1dd3af10bb
Now that we have the cog menu, it should be placed correctly in mobile and the "preferences" link should be hidden. Since MobileFrontend doesn't have the personal toolbar, and we can't cheat by using jQuery and grabbing the url of preferences, we have to get SpecialNotifications.php to output the urls to a wg variable and reading it from there. Bug: T115528 Change-Id: I6a69823d6f75c376c04e9a21d79916321e417178
148 lines
3.8 KiB
JavaScript
148 lines
3.8 KiB
JavaScript
( function ( $, mw ) {
|
|
/**
|
|
* Widget for the settings menu in the Special:Notifications page
|
|
*
|
|
* @param {mw.echo.dm.ModelManager} manager Model manager
|
|
* @param {Object} config Configuration object
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget = function MwEchoUiSpecialHelpMenuWidget( manager, config ) {
|
|
var $menu = $( '<div>' )
|
|
.addClass( 'mw-echo-ui-specialHelpMenuWidget-menu' );
|
|
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
mw.echo.ui.SpecialHelpMenuWidget.parent.call( this, $.extend( {
|
|
icon: 'advanced',
|
|
indicator: 'down',
|
|
popup: {
|
|
$content: $menu,
|
|
width: 300
|
|
}
|
|
}, config ) );
|
|
|
|
// Mixin constructors
|
|
OO.ui.mixin.GroupWidget.call( this, $.extend( {}, config, { $group: $menu } ) );
|
|
OO.ui.mixin.PendingElement.call( this, config );
|
|
|
|
this.manager = manager;
|
|
|
|
this.markAllReadButton = new OO.ui.ButtonWidget( {
|
|
framed: false,
|
|
icon: 'doubleCheck',
|
|
label: this.getMarkAllReadButtonLabel()
|
|
} );
|
|
this.setPendingElement( this.$element );
|
|
this.markAllReadButton.toggle( false );
|
|
|
|
this.addItems( [ this.markAllReadButton ] );
|
|
if ( config.prefLink ) {
|
|
this.addItems( [
|
|
// Preferences link
|
|
new OO.ui.ButtonWidget( {
|
|
framed: false,
|
|
icon: 'advanced',
|
|
label: mw.msg( 'mypreferences' ),
|
|
href: config.prefLink
|
|
} )
|
|
] );
|
|
}
|
|
|
|
if ( config.helpLink ) {
|
|
this.addItems( [
|
|
// Help link
|
|
new OO.ui.ButtonWidget( {
|
|
framed: false,
|
|
icon: 'help',
|
|
label: mw.msg( 'echo-learn-more' ),
|
|
href: config.helpLink
|
|
} )
|
|
] );
|
|
}
|
|
|
|
// Events
|
|
this.markAllReadButton.connect( this, { click: 'onMarkAllreadButtonClick' } );
|
|
this.manager.connect( this, {
|
|
localCountChange: 'onLocalCountChange'
|
|
} );
|
|
this.manager.getFiltersModel().getSourcePagesModel().connect( this, { update: 'onSourcePageUpdate' } );
|
|
|
|
this.$element
|
|
.addClass( 'mw-echo-ui-specialHelpMenuWidget' );
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
OO.inheritClass( mw.echo.ui.SpecialHelpMenuWidget, OO.ui.PopupButtonWidget );
|
|
OO.mixinClass( mw.echo.ui.SpecialHelpMenuWidget, OO.ui.mixin.GroupElement );
|
|
OO.mixinClass( mw.echo.ui.SpecialHelpMenuWidget, OO.ui.mixin.PendingElement );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @event markAllRead
|
|
*
|
|
* Mark all notifications as read in the selected wiki
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Respond to source page change
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.onSourcePageUpdate = function () {
|
|
this.markAllReadButton.setLabel( this.getMarkAllReadButtonLabel() );
|
|
|
|
};
|
|
|
|
/**
|
|
* Respond to local counter update event
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.onLocalCountChange = function ( count ) {
|
|
this.markAllReadButton.toggle( count > 0 );
|
|
};
|
|
|
|
/**
|
|
* Respond to mark all read button click
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.onMarkAllreadButtonClick = function () {
|
|
this.popup.toggle( false );
|
|
this.emit( 'markAllRead' );
|
|
};
|
|
|
|
/**
|
|
* Build the button label
|
|
*
|
|
* @return {string} Mark all read button label
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.getMarkAllReadButtonLabel = function () {
|
|
var pageModel = this.manager.getFiltersModel().getSourcePagesModel(),
|
|
source = pageModel.getCurrentSource(),
|
|
sourceTitle = pageModel.getSourceTitle( source );
|
|
|
|
return sourceTitle ?
|
|
mw.msg( 'echo-mark-wiki-as-read', sourceTitle ) :
|
|
mw.msg( 'echo-mark-all-as-read' );
|
|
};
|
|
|
|
/**
|
|
* Extend the pushPending method to disable the mark all read button
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.pushPending = function () {
|
|
this.markAllReadButton.setDisabled( true );
|
|
|
|
// Mixin method
|
|
OO.ui.mixin.PendingElement.prototype.pushPending.call( this );
|
|
};
|
|
|
|
/**
|
|
* Extend the popPending method to enable the mark all read button
|
|
*/
|
|
mw.echo.ui.SpecialHelpMenuWidget.prototype.popPending = function () {
|
|
this.markAllReadButton.setDisabled( false );
|
|
|
|
// Mixin method
|
|
OO.ui.mixin.PendingElement.prototype.popPending.call( this );
|
|
};
|
|
} )( jQuery, mediaWiki );
|