1660fb2e035644085dc9a5c2c947a7e5e9fb7b04
3 * A widget representing a base toggle item
5 * @extends OO.ui.MenuOptionWidget
8 * @param {mw.rcfilters.Controller} controller RCFilters controller
9 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel
10 * @param {mw.rcfilters.dm.ItemModel} invertModel
11 * @param {mw.rcfilters.dm.ItemModel} itemModel Item model
12 * @param {mw.rcfilters.ui.HighlightPopupWidget} highlightPopup Shared highlight color picker
13 * @param {Object} config Configuration object
15 mw
.rcfilters
.ui
.ItemMenuOptionWidget
= function MwRcfiltersUiItemMenuOptionWidget(
16 controller
, filtersViewModel
, invertModel
, itemModel
, highlightPopup
, config
21 .addClass( 'mw-rcfilters-ui-itemMenuOptionWidget-label' );
23 config
= config
|| {};
25 this.controller
= controller
;
26 this.filtersViewModel
= filtersViewModel
;
27 this.invertModel
= invertModel
;
28 this.itemModel
= itemModel
;
31 mw
.rcfilters
.ui
.ItemMenuOptionWidget
.parent
.call( this, $.extend( {
32 // Override the 'check' icon that OOUI defines
34 data
: this.itemModel
.getName(),
35 label
: this.itemModel
.getLabel()
38 this.checkboxWidget
= new mw
.rcfilters
.ui
.CheckboxInputWidget( {
39 value
: this.itemModel
.getName(),
40 selected
: this.itemModel
.isSelected()
45 .addClass( 'mw-rcfilters-ui-itemMenuOptionWidget-label-title' )
46 .append( $( '<bdi>' ).append( this.$label
) )
48 if ( this.itemModel
.getDescription() ) {
51 .addClass( 'mw-rcfilters-ui-itemMenuOptionWidget-label-desc' )
52 .append( $( '<bdi>' ).text( this.itemModel
.getDescription() ) )
56 this.highlightButton
= new mw
.rcfilters
.ui
.FilterItemHighlightButton(
61 $overlay
: config
.$overlay
|| this.$element
,
62 title
: mw
.msg( 'rcfilters-highlightmenu-help' )
65 this.highlightButton
.toggle( this.filtersViewModel
.isHighlightEnabled() );
67 this.excludeLabel
= new OO
.ui
.LabelWidget( {
68 label
: mw
.msg( 'rcfilters-filter-excluded' )
70 this.excludeLabel
.toggle(
71 this.itemModel
.getGroupModel().getView() === 'namespaces' &&
72 this.itemModel
.isSelected() &&
73 this.invertModel
.isSelected()
76 layout
= new OO
.ui
.FieldLayout( this.checkboxWidget
, {
82 this.filtersViewModel
.connect( this, { highlightChange
: 'updateUiBasedOnState' } );
83 this.invertModel
.connect( this, { update
: 'updateUiBasedOnState' } );
84 this.itemModel
.connect( this, { update
: 'updateUiBasedOnState' } );
85 // HACK: Prevent defaults on 'click' for the label so it
86 // doesn't steal the focus away from the input. This means
87 // we can continue arrow-movement after we click the label
88 // and is consistent with the checkbox *itself* also preventing
89 // defaults on 'click' as well.
90 layout
.$label
.on( 'click', false );
93 .addClass( 'mw-rcfilters-ui-itemMenuOptionWidget' )
94 .addClass( 'mw-rcfilters-ui-itemMenuOptionWidget-view-' + this.itemModel
.getGroupModel().getView() )
97 .addClass( 'mw-rcfilters-ui-table' )
100 .addClass( 'mw-rcfilters-ui-row' )
103 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-itemMenuOptionWidget-itemCheckbox' )
104 .append( layout
.$element
),
106 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-itemMenuOptionWidget-excludeLabel' )
107 .append( this.excludeLabel
.$element
),
109 .addClass( 'mw-rcfilters-ui-cell mw-rcfilters-ui-itemMenuOptionWidget-highlightButton' )
110 .append( this.highlightButton
.$element
)
115 if ( this.itemModel
.getIdentifiers() ) {
116 this.itemModel
.getIdentifiers().forEach( function ( ident
) {
117 classes
.push( 'mw-rcfilters-ui-itemMenuOptionWidget-identifier-' + ident
);
120 this.$element
.addClass( classes
);
123 this.updateUiBasedOnState();
128 OO
.inheritClass( mw
.rcfilters
.ui
.ItemMenuOptionWidget
, OO
.ui
.MenuOptionWidget
);
130 /* Static properties */
132 // We do our own scrolling to top
133 mw
.rcfilters
.ui
.ItemMenuOptionWidget
.static.scrollIntoViewOnSelect
= false;
138 * Respond to item model update event
140 mw
.rcfilters
.ui
.ItemMenuOptionWidget
.prototype.updateUiBasedOnState = function () {
141 this.checkboxWidget
.setSelected( this.itemModel
.isSelected() );
143 this.highlightButton
.toggle( this.filtersViewModel
.isHighlightEnabled() );
144 this.excludeLabel
.toggle(
145 this.itemModel
.getGroupModel().getView() === 'namespaces' &&
146 this.itemModel
.isSelected() &&
147 this.invertModel
.isSelected()
149 this.toggle( this.itemModel
.isVisible() );
153 * Get the name of this filter
155 * @return {string} Filter name
157 mw
.rcfilters
.ui
.ItemMenuOptionWidget
.prototype.getName = function () {
158 return this.itemModel
.getName();
161 mw
.rcfilters
.ui
.ItemMenuOptionWidget
.prototype.getModel = function () {
162 return this.itemModel
;