Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.ComplexTitleInputWidget.js
1 /*!
2 * MediaWiki Widgets - ComplexTitleInputWidget 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 () {
8
9 /**
10 * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
11 *
12 * @class
13 * @extends OO.ui.Widget
14 *
15 * @constructor
16 * @param {Object} [config] Configuration options
17 * @cfg {Object} namespace Configuration for the NamespaceInputWidget dropdown with list of
18 * namespaces
19 * @cfg {Object} title Configuration for the TitleInputWidget text field
20 */
21 mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
22 // Parent constructor
23 mw.widgets.ComplexTitleInputWidget.parent.call( this, config );
24
25 // Properties
26 this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
27 this.title = new mw.widgets.TitleInputWidget( $.extend(
28 {},
29 config.title,
30 {
31 relative: true,
32 namespace: config.namespace.value || null
33 }
34 ) );
35
36 // Events
37 this.namespace.connect( this, { change: 'updateTitleNamespace' } );
38
39 // Initialization
40 this.$element
41 .addClass( 'mw-widget-complexTitleInputWidget' )
42 .append(
43 this.namespace.$element,
44 this.title.$element
45 );
46 this.updateTitleNamespace();
47 };
48
49 /* Setup */
50
51 OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
52
53 /* Static Methods */
54
55 /**
56 * @inheritdoc
57 */
58 mw.widgets.ComplexTitleInputWidget.static.reusePreInfuseDOM = function ( node, config ) {
59 config = mw.widgets.ComplexTitleInputWidget.parent.static.reusePreInfuseDOM( node, config );
60 config.namespace = mw.widgets.NamespaceInputWidget.static.reusePreInfuseDOM(
61 $( node ).find( '.mw-widget-namespaceInputWidget' ),
62 config.namespace
63 );
64 config.title = mw.widgets.TitleInputWidget.static.reusePreInfuseDOM(
65 $( node ).find( '.mw-widget-titleInputWidget' ),
66 config.title
67 );
68 return config;
69 };
70
71 /**
72 * @inheritdoc
73 */
74 mw.widgets.ComplexTitleInputWidget.static.gatherPreInfuseState = function ( node, config ) {
75 var state = mw.widgets.ComplexTitleInputWidget.parent.static.gatherPreInfuseState( node, config );
76 state.namespace = mw.widgets.NamespaceInputWidget.static.gatherPreInfuseState(
77 $( node ).find( '.mw-widget-namespaceInputWidget' ),
78 config.namespace
79 );
80 state.title = mw.widgets.TitleInputWidget.static.gatherPreInfuseState(
81 $( node ).find( '.mw-widget-titleInputWidget' ),
82 config.title
83 );
84 return state;
85 };
86
87 /* Methods */
88
89 /**
90 * Update the namespace to use for search suggestions of the title when the value of namespace
91 * dropdown changes.
92 */
93 mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
94 this.title.setNamespace( Number( this.namespace.getValue() ) );
95 };
96
97 /**
98 * @inheritdoc
99 */
100 mw.widgets.ComplexTitleInputWidget.prototype.restorePreInfuseState = function ( state ) {
101 mw.widgets.ComplexTitleInputWidget.parent.prototype.restorePreInfuseState.call( this, state );
102 this.namespace.restorePreInfuseState( state.namespace );
103 this.title.restorePreInfuseState( state.title );
104 };
105
106 /**
107 * @inheritdoc
108 */
109 mw.widgets.ComplexTitleInputWidget.prototype.setDisabled = function ( disabled ) {
110 mw.widgets.ComplexTitleInputWidget.parent.prototype.setDisabled.call( this, disabled );
111 if ( this.namespace ) {
112 this.namespace.setDisabled( disabled );
113 }
114
115 if ( this.title ) {
116 this.title.setDisabled( disabled );
117 }
118 return this;
119 };
120
121 }() );