3 * A widget representing a single toggle filter
5 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.Controller} controller RCFilters controller
9 * @param {mw.rcfilters.dm.FilterItem} model Filter item model
10 * @param {Object} config Configuration object
12 mw
.rcfilters
.ui
.FilterItemWidget
= function MwRcfiltersUiFilterItemWidget( controller
, model
, config
) {
15 .addClass( 'mw-rcfilters-ui-filterItemWidget-label' );
17 config
= config
|| {};
20 mw
.rcfilters
.ui
.FilterItemWidget
.parent
.call( this, config
);
22 this.controller
= controller
;
24 this.selected
= false;
26 this.checkboxWidget
= new mw
.rcfilters
.ui
.CheckboxInputWidget( {
27 value
: this.model
.getName(),
28 selected
: this.model
.isSelected()
33 .addClass( 'mw-rcfilters-ui-filterItemWidget-label-title' )
34 .text( this.model
.getLabel() )
36 if ( this.model
.getDescription() ) {
39 .addClass( 'mw-rcfilters-ui-filterItemWidget-label-desc' )
40 .text( this.model
.getDescription() )
44 this.highlightButton
= new mw
.rcfilters
.ui
.FilterItemHighlightButton(
48 $overlay
: config
.$overlay
|| this.$element
51 this.highlightButton
.toggle( this.model
.isHighlightEnabled() );
53 layout
= new OO
.ui
.FieldLayout( this.checkboxWidget
, {
59 this.checkboxWidget
.connect( this, { userChange
: 'onCheckboxChange' } );
60 this.model
.connect( this, { update
: 'onModelUpdate' } );
61 this.model
.getGroupModel().connect( this, { update
: 'onGroupModelUpdate' } );
64 .addClass( 'mw-rcfilters-ui-filterItemWidget' )
67 .addClass( 'mw-rcfilters-ui-table' )
70 .addClass( 'mw-rcfilters-ui-row' )
73 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-filterItemWidget-filterCheckbox' )
74 .append( layout
.$element
),
76 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-filterItemWidget-highlightButton' )
77 .append( this.highlightButton
.$element
)
85 OO
.inheritClass( mw
.rcfilters
.ui
.FilterItemWidget
, OO
.ui
.Widget
);
90 * Respond to checkbox change.
91 * NOTE: This event is emitted both for deliberate user action and for
92 * a change that the code requests ('setSelected')
94 * @param {boolean} isSelected The checkbox is selected
96 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onCheckboxChange = function ( isSelected
) {
97 this.controller
.updateFilter( this.model
.getName(), isSelected
);
101 * Respond to item model update event
103 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onModelUpdate = function () {
104 this.checkboxWidget
.setSelected( this.model
.isSelected() );
106 this.setCurrentMuteState();
110 * Respond to item group model update event
112 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onGroupModelUpdate = function () {
113 this.setCurrentMuteState();
117 * Set selected state on this widget
119 * @param {boolean} [isSelected] Widget is selected
121 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.toggleSelected = function ( isSelected
) {
122 isSelected
= isSelected
!== undefined ? isSelected
: !this.selected
;
124 if ( this.selected
!== isSelected
) {
125 this.selected
= isSelected
;
127 this.$element
.toggleClass( 'mw-rcfilters-ui-filterItemWidget-selected', this.selected
);
132 * Set the current mute state for this item
134 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.setCurrentMuteState = function () {
135 this.$element
.toggleClass(
136 'mw-rcfilters-ui-filterItemWidget-muted',
137 this.model
.isConflicted() ||
138 this.model
.isIncluded() ||
139 this.model
.isFullyCovered() ||
141 // Item is also muted when any of the items in its group is active
142 this.model
.getGroupModel().isActive() &&
143 // But it isn't selected
144 !this.model
.isSelected()
148 this.highlightButton
.toggle( this.model
.isHighlightEnabled() );
152 * Get the name of this filter
154 * @return {string} Filter name
156 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.getName = function () {
157 return this.model
.getName();
159 }( mediaWiki
, jQuery
) );