2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-05-31 22:32:16 +00:00
|
|
|
/**
|
|
|
|
* An option widget for the page filter in PageFilterWidget
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.OptionWidget
|
2024-04-30 14:21:54 +00:00
|
|
|
* @mixes OO.ui.mixin.IconElement
|
|
|
|
* @mixes OO.ui.mixin.TitledElement
|
2016-05-31 22:32:16 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {number} [config.count] Number of unread notifications
|
|
|
|
* @param {boolean} [config.isCapped] The count for this widget is capped
|
2016-05-31 22:32:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.PageNotificationsOptionWidget = function MwEchoUiPageNotificationsOptionWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
2018-05-22 14:56:46 +00:00
|
|
|
// Parent constructor
|
|
|
|
mw.echo.ui.PageNotificationsOptionWidget.super.call( this, config );
|
2016-05-31 22:32:16 +00:00
|
|
|
// Mixin constructors
|
|
|
|
OO.ui.mixin.IconElement.call( this, config );
|
2016-07-13 13:51:51 +00:00
|
|
|
OO.ui.mixin.TitledElement.call( this, config );
|
2016-05-31 22:32:16 +00:00
|
|
|
|
|
|
|
this.$label
|
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-title-label' );
|
|
|
|
|
2016-09-12 23:30:39 +00:00
|
|
|
this.count = config.count !== undefined ? config.count : 0;
|
|
|
|
|
2024-03-05 22:39:09 +00:00
|
|
|
var countLabel = mw.language.convertNumber( this.count );
|
2016-09-12 23:30:39 +00:00
|
|
|
countLabel = config.isCapped ?
|
|
|
|
mw.msg( 'echo-badge-count', countLabel ) : countLabel;
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
this.unreadCountLabel = new OO.ui.LabelWidget( {
|
2016-09-12 23:30:39 +00:00
|
|
|
classes: [ 'mw-echo-ui-pageNotificationsOptionWidget-label-count' ],
|
|
|
|
label: countLabel
|
2016-05-31 22:32:16 +00:00
|
|
|
} );
|
|
|
|
|
2024-03-05 22:39:09 +00:00
|
|
|
var $row = $( '<div>' )
|
2018-01-12 00:03:08 +00:00
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-row' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
|
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-title' )
|
|
|
|
.append( this.$label ),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
|
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-count' )
|
|
|
|
.append( this.unreadCountLabel.$element )
|
|
|
|
);
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
2018-01-12 00:03:08 +00:00
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-table' )
|
|
|
|
.append( $row )
|
2016-05-31 22:32:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( this.getIcon() ) {
|
2018-01-12 00:03:08 +00:00
|
|
|
$row.prepend(
|
2016-05-31 22:32:16 +00:00
|
|
|
$( '<div>' )
|
2018-01-12 00:03:08 +00:00
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
|
2016-05-31 22:32:16 +00:00
|
|
|
.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-icon' )
|
|
|
|
.append( this.$icon )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.OptionWidget );
|
|
|
|
OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.IconElement );
|
2016-07-13 13:51:51 +00:00
|
|
|
OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.TitledElement );
|
2016-05-31 22:32:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the page count
|
|
|
|
*
|
|
|
|
* @return {number} Page count
|
|
|
|
*/
|
|
|
|
mw.echo.ui.PageNotificationsOptionWidget.prototype.getCount = function () {
|
|
|
|
return this.count;
|
|
|
|
};
|
|
|
|
|
2016-10-04 23:08:14 +00:00
|
|
|
mw.echo.ui.PageNotificationsOptionWidget.prototype.setPressed = function ( state ) {
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.PageNotificationsOptionWidget.super.prototype.setPressed.call( this, state );
|
2016-10-04 23:08:14 +00:00
|
|
|
if ( this.pressed ) {
|
|
|
|
this.setFlags( 'progressive' );
|
|
|
|
} else if ( !this.selected ) {
|
|
|
|
this.clearFlags();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.echo.ui.PageNotificationsOptionWidget.prototype.setSelected = function ( state ) {
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.PageNotificationsOptionWidget.super.prototype.setSelected.call( this, state );
|
2016-10-04 23:08:14 +00:00
|
|
|
if ( this.selected ) {
|
|
|
|
this.setFlags( 'progressive' );
|
|
|
|
} else {
|
|
|
|
this.clearFlags();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|