2 * MediaWiki Widgets - ComplexNamespaceInputWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * @classdesc Displays a dropdown box with the choice of available namespaces,
11 * plus two checkboxes to include associated namespace or to invert selection.
14 * @extends OO.ui.Widget
17 * @description Create an instance of `mw.widgets.ComplexNamespaceInputWidget`.
18 * @param {Object} [config] Configuration options
19 * @param {Object} config.namespace Configuration for the NamespaceInputWidget dropdown with list
21 * @param {string} config.namespace.includeAllValue If specified, add a "all namespaces"
22 * option to the dropdown, and use this as the input value for it
23 * @param {Object} config.invert Configuration for the "invert selection" CheckboxInputWidget. If
24 * null, the checkbox will not be generated.
25 * @param {Object} config.associated Configuration for the "include associated namespace"
26 * CheckboxInputWidget. If null, the checkbox will not be generated.
27 * @param {Object} config.invertLabel Configuration for the FieldLayout with label wrapping the
28 * "invert selection" checkbox
29 * @param {string} config.invertLabel.label Label text for the label
30 * @param {Object} config.associatedLabel Configuration for the FieldLayout with label wrapping
31 * the "include associated namespace" checkbox
32 * @param {string} config.associatedLabel.label Label text for the label
34 mw.widgets.ComplexNamespaceInputWidget = function MwWidgetsComplexNamespaceInputWidget( config ) {
35 // Configuration initialization
36 config = Object.assign(
38 // Config options for nested widgets
49 mw.widgets.ComplexNamespaceInputWidget.super.call( this, config );
54 this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
55 if ( config.associated !== null ) {
56 this.associated = new OO.ui.CheckboxInputWidget( Object.assign(
60 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
61 this.associatedLabel = new OO.ui.FieldLayout(
65 config.associatedLabel
69 if ( config.invert !== null ) {
70 this.invert = new OO.ui.CheckboxInputWidget( Object.assign(
74 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
75 this.invertLabel = new OO.ui.FieldLayout(
85 this.namespace.connect( this, { change: 'updateCheckboxesState' } );
89 .addClass( 'mw-widget-complexNamespaceInputWidget' )
91 this.namespace.$element,
92 this.invert ? this.invertLabel.$element : '',
93 this.associated ? this.associatedLabel.$element : ''
95 this.updateCheckboxesState();
100 OO.inheritClass( mw.widgets.ComplexNamespaceInputWidget, OO.ui.Widget );
105 * Update the disabled state of checkboxes when the value of namespace dropdown changes.
109 mw.widgets.ComplexNamespaceInputWidget.prototype.updateCheckboxesState = function () {
110 const disabled = this.namespace.getValue() === this.namespace.allValue;
112 this.invert.setDisabled( disabled );
114 if ( this.associated ) {
115 this.associated.setDisabled( disabled );
122 mw.widgets.ComplexNamespaceInputWidget.prototype.setDisabled = function ( disabled ) {
123 mw.widgets.ComplexNamespaceInputWidget.super.prototype.setDisabled.call( this, disabled );
124 if ( this.namespace ) {
125 this.namespace.setDisabled( disabled );
128 this.invert.setDisabled( disabled );
131 if ( this.associated ) {
132 this.associated.setDisabled( disabled );