Merge "Add wfWaitForSlaves() call in DatabaseUpdater::runUpdates()"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.Upload.Dialog.js
1 ( function ( $, mw ) {
2
3 /**
4 * mw.Upload.Dialog controls a {@link mw.Upload.BookletLayout BookletLayout}.
5 *
6 * ## Usage
7 *
8 * To use, setup a {@link OO.ui.WindowManager window manager} like for normal
9 * dialogs:
10 *
11 * var uploadDialog = new mw.Upload.Dialog();
12 * var windowManager = new OO.ui.WindowManager();
13 * $( 'body' ).append( windowManager.$element );
14 * windowManager.addWindows( [ uploadDialog ] );
15 * windowManager.openWindow( uploadDialog );
16 *
17 * The dialog's closing promise can be used to get details of the upload.
18 *
19 * @class mw.Upload.Dialog
20 * @uses mw.Upload
21 * @extends OO.ui.ProcessDialog
22 */
23 mw.Upload.Dialog = function ( config ) {
24 // Parent constructor
25 mw.Upload.Dialog.parent.call( this, config );
26 };
27
28 /* Setup */
29
30 OO.inheritClass( mw.Upload.Dialog, OO.ui.ProcessDialog );
31
32 /* Static Properties */
33
34 /**
35 * @inheritdoc
36 * @property title
37 */
38 /*jshint -W024*/
39 mw.Upload.Dialog.static.title = mw.msg( 'upload-dialog-title' );
40
41 /**
42 * @inheritdoc
43 * @property actions
44 */
45 mw.Upload.Dialog.static.actions = [
46 {
47 flags: 'safe',
48 action: 'cancel',
49 label: mw.msg( 'upload-dialog-button-cancel' ),
50 modes: [ 'upload', 'insert', 'info' ]
51 },
52 {
53 flags: [ 'primary', 'progressive' ],
54 label: mw.msg( 'upload-dialog-button-done' ),
55 action: 'insert',
56 modes: 'insert'
57 },
58 {
59 flags: [ 'primary', 'constructive' ],
60 label: mw.msg( 'upload-dialog-button-save' ),
61 action: 'save',
62 modes: 'info'
63 },
64 {
65 flags: [ 'primary', 'progressive' ],
66 label: mw.msg( 'upload-dialog-button-upload' ),
67 action: 'upload',
68 modes: 'upload'
69 }
70 ];
71
72 /*jshint +W024*/
73
74 /* Methods */
75
76 /**
77 * @inheritdoc
78 */
79 mw.Upload.Dialog.prototype.initialize = function () {
80 // Parent method
81 mw.Upload.Dialog.parent.prototype.initialize.call( this );
82
83 this.uploadBooklet = this.createUploadBooklet();
84 this.uploadBooklet.connect( this, {
85 set: 'onUploadBookletSet',
86 uploadValid: 'onUploadValid',
87 infoValid: 'onInfoValid'
88 } );
89
90 this.$body.append( this.uploadBooklet.$element );
91 };
92
93 /**
94 * Create an upload booklet
95 *
96 * @protected
97 * @return {mw.Upload.BookletLayout} An upload booklet
98 */
99 mw.Upload.Dialog.prototype.createUploadBooklet = function () {
100 return new mw.Upload.BookletLayout();
101 };
102
103 /**
104 * @inheritdoc
105 */
106 mw.Upload.Dialog.prototype.getBodyHeight = function () {
107 return 300;
108 };
109
110 /**
111 * Handle panelNameSet events from the upload booklet
112 *
113 * @protected
114 * @param {OO.ui.PageLayout} page Current page
115 */
116 mw.Upload.Dialog.prototype.onUploadBookletSet = function ( page ) {
117 this.actions.setMode( page.getName() );
118 this.actions.setAbilities( { upload: false, save: false } );
119 };
120
121 /**
122 * Handle uploadValid events
123 *
124 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
125 * for the dialog accordingly.
126 *
127 * @protected
128 * @param {boolean} isValid The panel is complete and valid
129 */
130 mw.Upload.Dialog.prototype.onUploadValid = function ( isValid ) {
131 this.actions.setAbilities( { upload: isValid } );
132 };
133
134 /**
135 * Handle infoValid events
136 *
137 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
138 * for the dialog accordingly.
139 *
140 * @protected
141 * @param {boolean} isValid The panel is complete and valid
142 */
143 mw.Upload.Dialog.prototype.onInfoValid = function ( isValid ) {
144 this.actions.setAbilities( { save: isValid } );
145 };
146
147 /**
148 * @inheritdoc
149 */
150 mw.Upload.Dialog.prototype.getSetupProcess = function ( data ) {
151 return mw.Upload.Dialog.parent.prototype.getSetupProcess.call( this, data )
152 .next( function () {
153 this.uploadBooklet.initialize();
154 }, this );
155 };
156
157 /**
158 * @inheritdoc
159 */
160 mw.Upload.Dialog.prototype.getActionProcess = function ( action ) {
161 var dialog = this;
162
163 if ( action === 'upload' ) {
164 return new OO.ui.Process( this.uploadBooklet.uploadFile() );
165 }
166 if ( action === 'save' ) {
167 return new OO.ui.Process( this.uploadBooklet.saveFile() );
168 }
169 if ( action === 'insert' ) {
170 return new OO.ui.Process( function () {
171 dialog.close( dialog.upload );
172 } );
173 }
174 if ( action === 'cancel' ) {
175 return new OO.ui.Process( this.close() );
176 }
177
178 return mw.Upload.Dialog.parent.prototype.getActionProcess.call( this, action );
179 };
180
181 /**
182 * @inheritdoc
183 */
184 mw.Upload.Dialog.prototype.getTeardownProcess = function ( data ) {
185 return mw.Upload.Dialog.parent.prototype.getTeardownProcess.call( this, data )
186 .next( function () {
187 this.uploadBooklet.clear();
188 }, this );
189 };
190
191 }( jQuery, mediaWiki ) );