63db2b042a753f472eeddb59f9713c10dd7eb9e6
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 this.highlightButton
= new mw
.rcfilters
.ui
.FilterItemHighlightButton(
47 $overlay
: config
.$overlay
|| this.$element
50 this.highlightButton
.toggle( this.model
.isHighlightEnabled() );
52 layout
= new OO
.ui
.FieldLayout( this.checkboxWidget
, {
58 this.checkboxWidget
.connect( this, { userChange
: 'onCheckboxChange' } );
59 this.model
.connect( this, { update
: 'onModelUpdate' } );
60 this.model
.getGroupModel().connect( this, { update
: 'onGroupModelUpdate' } );
63 .addClass( 'mw-rcfilters-ui-filterItemWidget' )
66 .addClass( 'mw-rcfilters-ui-table' )
69 .addClass( 'mw-rcfilters-ui-row' )
72 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-filterItemWidget-filterCheckbox' )
73 .append( layout
.$element
),
75 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-filterItemWidget-highlightButton' )
76 .append( this.highlightButton
.$element
)
84 OO
.inheritClass( mw
.rcfilters
.ui
.FilterItemWidget
, OO
.ui
.Widget
);
89 * Respond to checkbox change.
90 * NOTE: This event is emitted both for deliberate user action and for
91 * a change that the code requests ('setSelected')
93 * @param {boolean} isSelected The checkbox is selected
95 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onCheckboxChange = function ( isSelected
) {
96 this.controller
.updateFilter( this.model
.getName(), isSelected
);
100 * Respond to item model update event
102 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onModelUpdate = function () {
103 this.checkboxWidget
.setSelected( this.model
.isSelected() );
105 this.setCurrentMuteState();
109 * Respond to item group model update event
111 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onGroupModelUpdate = function () {
112 this.setCurrentMuteState();
116 * Set the current mute state for this item
118 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.setCurrentMuteState = function () {
119 this.$element
.toggleClass(
120 'mw-rcfilters-ui-filterItemWidget-muted',
121 this.model
.isConflicted() ||
122 this.model
.isIncluded() ||
123 this.model
.isFullyCovered() ||
125 // Item is also muted when any of the items in its group is active
126 this.model
.getGroupModel().isActive() &&
127 // But it isn't selected
128 !this.model
.isSelected()
132 this.highlightButton
.toggle( this.model
.isHighlightEnabled() );
136 * Get the name of this filter
138 * @return {string} Filter name
140 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.getName = function () {
141 return this.model
.getName();
143 }( mediaWiki
, jQuery
) );