summaryrefslogtreecommitdiff
blob: 211161063861661a3072b26da3b678f5c394ad75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
( function () {
	/**
	 * An option widget for the page filter in PageFilterWidget
	 *
	 * @class
	 * @extends OO.ui.OptionWidget
	 * @mixins OO.ui.mixin.IconElement
	 * @mixins OO.ui.mixin.TitledElement
	 *
	 * @constructor
	 * @param {Object} [config] Configuration object
	 * @cfg {number} [count] Number of unread notifications
	 * @cfg {boolean} [isCapped] The count for this widget is capped
	 */
	mw.echo.ui.PageNotificationsOptionWidget = function MwEchoUiPageNotificationsOptionWidget( config ) {
		var countLabel, $row;

		config = config || {};

		// Parent constructor
		mw.echo.ui.PageNotificationsOptionWidget.super.call( this, config );
		// Mixin constructors
		OO.ui.mixin.IconElement.call( this, config );
		OO.ui.mixin.TitledElement.call( this, config );

		this.$label
			.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-title-label' );

		this.count = config.count !== undefined ? config.count : 0;

		countLabel = mw.language.convertNumber( this.count );
		countLabel = config.isCapped ?
			mw.msg( 'echo-badge-count', countLabel ) : countLabel;

		this.unreadCountLabel = new OO.ui.LabelWidget( {
			classes: [ 'mw-echo-ui-pageNotificationsOptionWidget-label-count' ],
			label: countLabel
		} );

		$row = $( '<div>' )
			.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 )
			);

		// Initialization
		this.$element
			.addClass( 'mw-echo-ui-pageNotificationsOptionWidget' )
			.append(
				$( '<div>' )
					.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-table' )
					.append( $row )
			);

		if ( this.getIcon() ) {
			$row.prepend(
				$( '<div>' )
					.addClass( 'mw-echo-ui-pageNotificationsOptionWidget-cell' )
					.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 );
	OO.mixinClass( mw.echo.ui.PageNotificationsOptionWidget, OO.ui.mixin.TitledElement );

	/**
	 * Get the page count
	 *
	 * @return {number} Page count
	 */
	mw.echo.ui.PageNotificationsOptionWidget.prototype.getCount = function () {
		return this.count;
	};

	mw.echo.ui.PageNotificationsOptionWidget.prototype.setPressed = function ( state ) {
		mw.echo.ui.PageNotificationsOptionWidget.super.prototype.setPressed.call( this, state );
		if ( this.pressed ) {
			this.setFlags( 'progressive' );
		} else if ( !this.selected ) {
			this.clearFlags();
		}
		return this;
	};

	mw.echo.ui.PageNotificationsOptionWidget.prototype.setSelected = function ( state ) {
		mw.echo.ui.PageNotificationsOptionWidget.super.prototype.setSelected.call( this, state );
		if ( this.selected ) {
			this.setFlags( 'progressive' );
		} else {
			this.clearFlags();
		}
		return this;
	};

}() );