Merge "ApiQueryInfo: fix query limits for testactions"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.CheckboxInputWidget.js
1 ( function ( mw ) {
2 /**
3 * A widget representing a single toggle filter
4 *
5 * @extends OO.ui.CheckboxInputWidget
6 *
7 * @constructor
8 * @param {Object} config Configuration object
9 */
10 mw.rcfilters.ui.CheckboxInputWidget = function MwRcfiltersUiCheckboxInputWidget( config ) {
11 config = config || {};
12
13 // Parent
14 mw.rcfilters.ui.CheckboxInputWidget.parent.call( this, config );
15
16 // Event
17 this.$input
18 // HACK: This widget just pretends to be a checkbox for visual purposes.
19 // In reality, all actions - setting to true or false, etc - are
20 // decided by the model, and executed by the controller. This means
21 // that we want to let the controller and model make the decision
22 // of whether to check/uncheck this checkboxInputWidget, and for that,
23 // we have to bypass the browser action that checks/unchecks it during
24 // click.
25 .on( 'click', false )
26 .on( 'change', this.onUserChange.bind( this ) );
27 };
28
29 /* Initialization */
30
31 OO.inheritClass( mw.rcfilters.ui.CheckboxInputWidget, OO.ui.CheckboxInputWidget );
32
33 /* Events */
34
35 /**
36 * @event userChange
37 * @param {boolean} Current state of the checkbox
38 *
39 * The user has checked or unchecked this checkbox
40 */
41
42 /* Methods */
43
44 /**
45 * @inheritdoc
46 */
47 mw.rcfilters.ui.CheckboxInputWidget.prototype.onEdit = function () {
48 // Similarly to preventing defaults in 'click' event, we want
49 // to prevent this widget from deciding anything about its own
50 // state; it emits a change event and the model and controller
51 // make a decision about what its select state is.
52 // onEdit has a widget.$input.prop( 'checked' ) inside a setTimeout()
53 // so we really want to prevent that from messing with what
54 // the model decides the state of the widget is.
55 };
56
57 /**
58 * Respond to checkbox change by a user and emit 'userChange'.
59 */
60 mw.rcfilters.ui.CheckboxInputWidget.prototype.onUserChange = function () {
61 this.emit( 'userChange', this.$input.prop( 'checked' ) );
62 };
63 }( mediaWiki ) );