Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / resources / src / mediawiki.widgets / mw.widgets.ComplexTitleInputWidget.js
blob8f48ec3d506cb50070d2faf6e86fbfef747ea25c
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 ( $, mw ) {
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 );
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                 ) );
36                 // Events
37                 this.namespace.connect( this, { change: 'updateTitleNamespace' } );
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         };
49         /* Setup */
51         OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
53         /* Static Methods */
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         };
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         };
87         /* Methods */
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         };
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         };
106 }( jQuery, mediaWiki ) );