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
;
25 this.checkboxWidget
= new mw
.rcfilters
.ui
.CheckboxInputWidget( {
26 value
: this.model
.getName(),
27 selected
: this.model
.isSelected()
32 .addClass( 'mw-rcfilters-ui-filterItemWidget-label-title' )
33 .text( this.model
.getLabel() )
35 if ( this.model
.getDescription() ) {
38 .addClass( 'mw-rcfilters-ui-filterItemWidget-label-desc' )
39 .text( this.model
.getDescription() )
43 layout
= new OO
.ui
.FieldLayout( this.checkboxWidget
, {
49 this.checkboxWidget
.connect( this, { userChange
: 'onCheckboxChange' } );
50 this.model
.connect( this, { update
: 'onModelUpdate' } );
51 this.model
.getGroupModel().connect( this, { update
: 'onGroupModelUpdate' } );
54 .addClass( 'mw-rcfilters-ui-filterItemWidget' )
62 OO
.inheritClass( mw
.rcfilters
.ui
.FilterItemWidget
, OO
.ui
.Widget
);
67 * Respond to checkbox change.
68 * NOTE: This event is emitted both for deliberate user action and for
69 * a change that the code requests ('setSelected')
71 * @param {boolean} isSelected The checkbox is selected
73 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onCheckboxChange = function ( isSelected
) {
74 this.controller
.updateFilter( this.model
.getName(), isSelected
);
78 * Respond to item model update event
80 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onModelUpdate = function () {
81 this.checkboxWidget
.setSelected( this.model
.isSelected() );
83 this.setCurrentMuteState();
87 * Respond to item group model update event
89 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onGroupModelUpdate = function () {
90 this.setCurrentMuteState();
94 * Set the current mute state for this item
96 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.setCurrentMuteState = function () {
97 this.$element
.toggleClass(
98 'mw-rcfilters-ui-filterItemWidget-muted',
99 this.model
.isConflicted() ||
100 this.model
.isIncluded() ||
101 this.model
.isFullyCovered() ||
103 // Item is also muted when any of the items in its group is active
104 this.model
.getGroupModel().isActive() &&
105 // But it isn't selected
106 !this.model
.isSelected()
111 * Get the name of this filter
113 * @return {string} Filter name
115 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.getName = function () {
116 return this.model
.getName();
119 }( mediaWiki
, jQuery
) );