Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.PageNotificationsOptionWidget.js

raw symbols SCIP
1 ( function () {
2 /**
3 * An option widget for the page filter in PageFilterWidget
4 *
5 * @class
6 * @extends OO.ui.OptionWidget
7 * @mixes OO.ui.mixin.IconElement
8 * @mixes OO.ui.mixin.TitledElement
9 *
10 * @constructor
11 * @param {Object} [config] Configuration object
12 * @param {number} [config.count] Number of unread notifications
13 * @param {boolean} [config.isCapped] The count for this widget is capped
14 */
15 mw.echo.ui.PageNotificationsOptionWidget = function MwEchoUiPageNotificationsOptionWidget( config ) {
16 config = config || {};
17
18 // Parent constructor
19 mw.echo.ui.PageNotificationsOptionWidget.super.call( this, config );
20 // Mixin constructors
21 OO.ui.mixin.IconElement.call( this, config );
22 OO.ui.mixin.TitledElement.call( this, config );
23
24 this.$label
25 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-title-label' );
26
27 this.count = config.count !== undefined ? config.count : 0;
28
29 let countLabel = mw.language.convertNumber( this.count );
30 countLabel = config.isCapped ?
31 mw.msg( 'echo-badge-count', countLabel ) : countLabel;
32
33 this.unreadCountLabel = new OO.ui.LabelWidget( {
34 classes: [ 'mw-echo-ui-pageNotificationsOptionWidget-label-count' ],
35 label: countLabel
36 } );
37
38 const $row = $( '<div>' )
39 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-row' )
40 .append(
41 $( '<div>' )
42 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
43 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-title' )
44 .append( this.$label ),
45 $( '<div>' )
46 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
47 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-count' )
48 .append( this.unreadCountLabel.$element )
49 );
50
51 // Initialization
52 this.$element
53 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget' )
54 .append( $row );
55
56 if ( this.getIcon() ) {
57 $row.prepend(
58 $( '<div>' )
59 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
60 .addClass( 'mw-echo-ui-pageNotificationsOptionWidget-icon' )
61 .append( this.$icon )
62 );
63 }
64 };
65
66 /* Initialization */
67
68 OO.inheritClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.OptionWidget );
69 OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.IconElement );
70 OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.TitledElement );
71
72 /**
73 * Get the page count
74 *
75 * @return {number} Page count
76 */
77 mw.echo.ui.PageNotificationsOptionWidget.prototype.getCount = function () {
78 return this.count;
79 };
80
81 mw.echo.ui.PageNotificationsOptionWidget.prototype.setPressed = function ( state ) {
82 mw.echo.ui.PageNotificationsOptionWidget.super.prototype.setPressed.call( this, state );
83 if ( this.pressed ) {
84 this.setFlags( 'progressive' );
85 } else if ( !this.selected ) {
86 this.clearFlags();
87 }
88 return this;
89 };
90
91 mw.echo.ui.PageNotificationsOptionWidget.prototype.setSelected = function ( state ) {
92 mw.echo.ui.PageNotificationsOptionWidget.super.prototype.setSelected.call( this, state );
93 if ( this.selected ) {
94 this.setFlags( 'progressive' );
95 } else {
96 this.clearFlags();
97 }
98 return this;
99 };
100
101 }() );