Debian Codegraph @

resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.js

raw symbols SCIP
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 * @classdesc 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 * @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
19 * namespaces
20 * @param {Object} config.title Configuration for the TitleInputWidget text field
21 */
22 mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
23 // Parent constructor
24 mw.widgets.ComplexTitleInputWidget.super.call( this, config );
25
26 // Properties
27 this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
28 this.title = new mw.widgets.TitleInputWidget( Object.assign(
29 {},
30 config.title,
31 {
32 relative: true,
33 namespace: config.namespace.value || null
34 }
35 ) );
36
37 // Events
38 this.namespace.connect( this, { change: 'updateTitleNamespace' } );
39
40 // Initialization
41 this.$element
42 .addClass( 'mw-widget-complexTitleInputWidget' )
43 .append(
44 this.namespace.$element,
45 this.title.$element
46 );
47 this.updateTitleNamespace();
48 };
49
50 /* Setup */
51
52 OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
53
54 /* Static Methods */
55
56 /**
57 * @inheritdoc
58 */
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' ),
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 };
71
72 /**
73 * @inheritdoc
74 */
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' ),
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 };
87
88 /* Methods */
89
90 /**
91 * Update the namespace to use for search suggestions of the title when the value of namespace
92 * dropdown changes.
93 */
94 mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
95 this.title.setNamespace( Number( this.namespace.getValue() ) );
96 };
97
98 /**
99 * @inheritdoc
100 */
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 );
105 };
106
107 /**
108 * @inheritdoc
109 */
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 );
114 }
115
116 if ( this.title ) {
117 this.title.setDisabled( disabled );
118 }
119 return this;
120 };
121
122 }() );