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
,
49 title
: mw
.msg( 'rcfilters-highlightmenu-help' )
52 this.highlightButton
.toggle( this.model
.isHighlightEnabled() );
54 layout
= new OO
.ui
.FieldLayout( this.checkboxWidget
, {
60 this.checkboxWidget
.connect( this, { userChange
: 'onCheckboxChange' } );
61 this.model
.connect( this, { update
: 'onModelUpdate' } );
62 this.model
.getGroupModel().connect( this, { update
: 'onGroupModelUpdate' } );
65 .addClass( 'mw-rcfilters-ui-filterItemWidget' )
68 .addClass( 'mw-rcfilters-ui-table' )
71 .addClass( 'mw-rcfilters-ui-row' )
74 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-filterItemWidget-filterCheckbox' )
75 .append( layout
.$element
),
77 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-filterItemWidget-highlightButton' )
78 .append( this.highlightButton
.$element
)
86 OO
.inheritClass( mw
.rcfilters
.ui
.FilterItemWidget
, OO
.ui
.Widget
);
91 * Respond to checkbox change.
92 * NOTE: This event is emitted both for deliberate user action and for
93 * a change that the code requests ('setSelected')
95 * @param {boolean} isSelected The checkbox is selected
97 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onCheckboxChange = function ( isSelected
) {
98 this.controller
.toggleFilterSelect( this.model
.getName(), isSelected
);
102 * Respond to item model update event
104 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onModelUpdate = function () {
105 this.checkboxWidget
.setSelected( this.model
.isSelected() );
107 this.setCurrentMuteState();
111 * Respond to item group model update event
113 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.onGroupModelUpdate = function () {
114 this.setCurrentMuteState();
118 * Set selected state on this widget
120 * @param {boolean} [isSelected] Widget is selected
122 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.toggleSelected = function ( isSelected
) {
123 isSelected
= isSelected
!== undefined ? isSelected
: !this.selected
;
125 if ( this.selected
!== isSelected
) {
126 this.selected
= isSelected
;
128 this.$element
.toggleClass( 'mw-rcfilters-ui-filterItemWidget-selected', this.selected
);
133 * Set the current mute state for this item
135 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.setCurrentMuteState = function () {
136 this.$element
.toggleClass(
137 'mw-rcfilters-ui-filterItemWidget-muted',
138 this.model
.isConflicted() ||
140 // Item is also muted when any of the items in its group is active
141 this.model
.getGroupModel().isActive() &&
142 // But it isn't selected
143 !this.model
.isSelected() &&
144 // And also not included
145 !this.model
.isIncluded()
149 this.highlightButton
.toggle( this.model
.isHighlightEnabled() );
153 * Get the name of this filter
155 * @return {string} Filter name
157 mw
.rcfilters
.ui
.FilterItemWidget
.prototype.getName = function () {
158 return this.model
.getName();
160 }( mediaWiki
, jQuery
) );