Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / resources / src / mediawiki.widgets / mw.widgets.ComplexTitleInputWidget.js
blobddae9b1f7fb0a1334a2bcfa8e9a8a71bdf429e2d
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 */
54         /*jshint -W024*/
56         /**
57          * @inheritdoc
58          */
59         mw.widgets.ComplexTitleInputWidget.static.reusePreInfuseDOM = function ( node, config ) {
60                 config = mw.widgets.ComplexTitleInputWidget.parent.static.reusePreInfuseDOM( node, config );
61                 config.namespace = mw.widgets.NamespaceInputWidget.static.reusePreInfuseDOM(
62                         $( node ).find( '.mw-widget-namespaceInputWidget' ),
63                         config.namespace
64                 );
65                 config.title = mw.widgets.TitleInputWidget.static.reusePreInfuseDOM(
66                         $( node ).find( '.mw-widget-titleInputWidget' ),
67                         config.title
68                 );
69                 return config;
70         };
72         /**
73          * @inheritdoc
74          */
75         mw.widgets.ComplexTitleInputWidget.static.gatherPreInfuseState = function ( node, config ) {
76                 var state = mw.widgets.ComplexTitleInputWidget.parent.static.gatherPreInfuseState( node, config );
77                 state.namespace = mw.widgets.NamespaceInputWidget.static.gatherPreInfuseState(
78                         $( node ).find( '.mw-widget-namespaceInputWidget' ),
79                         config.namespace
80                 );
81                 state.title = mw.widgets.TitleInputWidget.static.gatherPreInfuseState(
82                         $( node ).find( '.mw-widget-titleInputWidget' ),
83                         config.title
84                 );
85                 return state;
86         };
88         /*jshint +W024*/
90         /* Methods */
92         /**
93          * Update the namespace to use for search suggestions of the title when the value of namespace
94          * dropdown changes.
95          */
96         mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
97                 this.title.setNamespace( Number( this.namespace.getValue() ) );
98         };
100         /**
101          * @inheritdoc
102          */
103         mw.widgets.ComplexTitleInputWidget.prototype.restorePreInfuseState = function ( state ) {
104                 mw.widgets.ComplexTitleInputWidget.parent.prototype.restorePreInfuseState.call( this, state );
105                 this.namespace.restorePreInfuseState( state.namespace );
106                 this.title.restorePreInfuseState( state.title );
107         };
109 }( jQuery, mediaWiki ) );