2 * MediaWiki Widgets - ComplexTitleInputWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * @classdesc Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
13 * @extends OO.ui.Widget
16 * @description Create an instance of `mw.widgets.ComplexTitleInputWidget`.
17 * @param {Object} [config] Configuration options
18 * @param {Object} config.namespace Configuration for the NamespaceInputWidget dropdown with list of
20 * @param {Object} config.title Configuration for the TitleInputWidget text field
22 mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
24 mw.widgets.ComplexTitleInputWidget.super.call( this, config );
27 this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
28 this.title = new mw.widgets.TitleInputWidget( Object.assign(
33 namespace: config.namespace.value || null
38 this.namespace.connect( this, { change: 'updateTitleNamespace' } );
42 .addClass( 'mw-widget-complexTitleInputWidget' )
44 this.namespace.$element,
47 this.updateTitleNamespace();
52 OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
59 mw.widgets.ComplexTitleInputWidget.static.reusePreInfuseDOM = function ( node, config ) {
60 config = mw.widgets.ComplexTitleInputWidget.super.static.reusePreInfuseDOM( node, config );
61 config.namespace = mw.widgets.NamespaceInputWidget.static.reusePreInfuseDOM(
62 $( node ).find( '.mw-widget-namespaceInputWidget' ),
65 config.title = mw.widgets.TitleInputWidget.static.reusePreInfuseDOM(
66 $( node ).find( '.mw-widget-titleInputWidget' ),
75 mw.widgets.ComplexTitleInputWidget.static.gatherPreInfuseState = function ( node, config ) {
76 const state = mw.widgets.ComplexTitleInputWidget.super.static.gatherPreInfuseState( node, config );
77 state.namespace = mw.widgets.NamespaceInputWidget.static.gatherPreInfuseState(
78 $( node ).find( '.mw-widget-namespaceInputWidget' ),
81 state.title = mw.widgets.TitleInputWidget.static.gatherPreInfuseState(
82 $( node ).find( '.mw-widget-titleInputWidget' ),
91 * Update the namespace to use for search suggestions of the title when the value of namespace
94 mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
95 this.title.setNamespace( Number( this.namespace.getValue() ) );
101 mw.widgets.ComplexTitleInputWidget.prototype.restorePreInfuseState = function ( state ) {
102 mw.widgets.ComplexTitleInputWidget.super.prototype.restorePreInfuseState.call( this, state );
103 this.namespace.restorePreInfuseState( state.namespace );
104 this.title.restorePreInfuseState( state.title );
110 mw.widgets.ComplexTitleInputWidget.prototype.setDisabled = function ( disabled ) {
111 mw.widgets.ComplexTitleInputWidget.super.prototype.setDisabled.call( this, disabled );
112 if ( this.namespace ) {
113 this.namespace.setDisabled( disabled );
117 this.title.setDisabled( disabled );