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 OO.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, { change: 'onCheckboxChange' } );
50 this.model.connect( this, { update: 'onModelUpdate' } );
53 .addClass( 'mw-rcfilters-ui-filterItemWidget' )
61 OO.inheritClass( mw.rcfilters.ui.FilterItemWidget, OO.ui.Widget );
66 * Respond to checkbox change.
67 * NOTE: This event is emitted both for deliberate user action and for
68 * a change that the code requests ('setSelected')
70 * @param {boolean} isSelected The checkbox is selected
72 mw.rcfilters.ui.FilterItemWidget.prototype.onCheckboxChange = function ( isSelected ) {
73 this.controller.updateFilter( this.model.getName(), isSelected );
77 * Respond to item model update event
79 mw.rcfilters.ui.FilterItemWidget.prototype.onModelUpdate = function () {
80 this.checkboxWidget.setSelected( this.model.isSelected() );
84 * Get the name of this filter
86 * @return {string} Filter name
88 mw.rcfilters.ui.FilterItemWidget.prototype.getName = function () {
89 return this.model.getName();
92 }( mediaWiki, jQuery ) );