Implement OOUI version of tag filter in ChangeTags
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.NamespaceInputWidget.js
1 /*!
2 * MediaWiki Widgets - NamespaceInputWidget class.
3 *
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function ( $, mw ) {
8
9 /**
10 * Creates a mw.widgets.NamespaceInputWidget object.
11 *
12 * This is not a complete implementation and is not intended for public usage. It only exists
13 * because of HTMLForm shenanigans.
14 *
15 * @class
16 * @private
17 * @extends OO.ui.Widget
18 *
19 * @constructor
20 * @param {Object} [config] Configuration options
21 * @cfg {OO.ui.DropdownInputWidget} namespace Widget to include
22 * @cfg {OO.ui.CheckboxInputWidget|null} invert Widget to include
23 * @cfg {OO.ui.CheckboxInputWidget|null} associated Widget to include
24 * @cfg {string|null} allValue Value for "all namespaces" option, if any
25 */
26 mw.widgets.NamespaceInputWidget = function MwWidgetsNamespaceInputWidget( config ) {
27 // Parent constructor
28 OO.ui.Widget.call( this, config );
29
30 // Properties
31 this.namespace = config.namespace;
32 this.invert = config.invert;
33 this.associated = config.associated;
34 this.allValue = config.allValue;
35
36 // Events
37 config.namespace.connect( this, { change: 'updateCheckboxesState' } );
38
39 // Initialization
40 this.$element
41 .addClass( 'mw-widget-namespaceInputWidget' )
42 .append(
43 config.namespace.$element,
44 config.invert ? config.invert.$element : '',
45 config.associated ? config.associated.$element : ''
46 );
47 this.updateCheckboxesState();
48 };
49
50 /* Inheritance */
51
52 OO.inheritClass( mw.widgets.NamespaceInputWidget, OO.ui.Widget );
53
54 /* Methods */
55
56 /**
57 * Update the disabled state of checkboxes when the value of namespace dropdown changes.
58 */
59 mw.widgets.NamespaceInputWidget.prototype.updateCheckboxesState = function () {
60 if ( this.invert ) {
61 this.invert.getField().setDisabled( this.namespace.getValue() === this.allValue );
62 }
63 if ( this.associated ) {
64 this.associated.getField().setDisabled( this.namespace.getValue() === this.allValue );
65 }
66 };
67
68 }( jQuery, mediaWiki ) );