4 * @classdesc Controls a {@link mw.Upload.BookletLayout BookletLayout}.
8 * To use, set up a {@link OO.ui.WindowManager window manager} like for normal
11 * var uploadDialog = new mw.Upload.Dialog();
12 * var windowManager = new OO.ui.WindowManager();
13 * $( document.body ).append( windowManager.$element );
14 * windowManager.addWindows( [ uploadDialog ] );
15 * windowManager.openWindow( uploadDialog );
18 * The dialog's closing promise can be used to get details of the upload.
20 * If you want to use a different {@link OO.ui.BookletLayout}, for example the
21 * {@link mw.ForeignStructuredUpload.BookletLayout}, like in the case of the upload
22 * interface in VisualEditor, you can pass it in through the `bookletClass` config option:
24 * var uploadDialog = new mw.Upload.Dialog( {
25 * bookletClass: mw.ForeignStructuredUpload.BookletLayout
29 * @class mw.Upload.Dialog
30 * @extends OO.ui.ProcessDialog
33 * @description Create an instance of `mw.Upload.Dialog`.
34 * @param {Object} [config] Configuration options
35 * @param {Function} [config.bookletClass=mw.Upload.BookletLayout] Booklet class to be
37 * @param {Object} [config.booklet] Booklet constructor configuration
39 mw.Upload.Dialog = function ( config ) {
40 // Config initialization
41 config = Object.assign( {
42 bookletClass: mw.Upload.BookletLayout
46 mw.Upload.Dialog.super.call( this, config );
49 this.bookletClass = config.bookletClass;
50 this.bookletConfig = config.booklet;
55 OO.inheritClass( mw.Upload.Dialog, OO.ui.ProcessDialog );
57 /* Static Properties */
61 * @property {string} name
63 mw.Upload.Dialog.static.name = 'mwUploadDialog';
67 * @property {Function|string} title
69 mw.Upload.Dialog.static.title = mw.msg( 'upload-dialog-title' );
73 * @property {Object[]} actions
75 mw.Upload.Dialog.static.actions = [
79 label: mw.msg( 'upload-dialog-button-cancel' ),
80 modes: [ 'upload', 'insert' ]
84 action: 'cancelupload',
85 label: mw.msg( 'upload-dialog-button-back' ),
89 flags: [ 'primary', 'progressive' ],
90 label: mw.msg( 'upload-dialog-button-done' ),
95 flags: [ 'primary', 'progressive' ],
96 label: mw.msg( 'upload-dialog-button-save' ),
101 flags: [ 'primary', 'progressive' ],
102 label: mw.msg( 'upload-dialog-button-upload' ),
114 mw.Upload.Dialog.prototype.initialize = function () {
116 mw.Upload.Dialog.super.prototype.initialize.call( this );
118 this.uploadBooklet = this.createUploadBooklet();
119 this.uploadBooklet.connect( this, {
120 set: 'onUploadBookletSet',
121 uploadValid: 'onUploadValid',
122 infoValid: 'onInfoValid'
125 this.$body.append( this.uploadBooklet.$element );
129 * Create an upload booklet.
132 * @return {mw.Upload.BookletLayout} An upload booklet
134 mw.Upload.Dialog.prototype.createUploadBooklet = function () {
135 // eslint-disable-next-line new-cap
136 return new this.bookletClass( Object.assign( {
137 $overlay: this.$overlay
138 }, this.bookletConfig ) );
145 mw.Upload.Dialog.prototype.getBodyHeight = function () {
150 * Handle panelNameSet events from the upload booklet.
153 * @param {OO.ui.PageLayout} page Current page
155 mw.Upload.Dialog.prototype.onUploadBookletSet = function ( page ) {
156 this.actions.setMode( page.getName() );
157 this.actions.setAbilities( { upload: false, save: false } );
161 * Handle uploadValid events.
163 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
164 * for the dialog accordingly.
167 * @param {boolean} isValid The panel is complete and valid
169 mw.Upload.Dialog.prototype.onUploadValid = function ( isValid ) {
170 this.actions.setAbilities( { upload: isValid } );
174 * Handle infoValid events.
176 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
177 * for the dialog accordingly.
180 * @param {boolean} isValid The panel is complete and valid
182 mw.Upload.Dialog.prototype.onInfoValid = function ( isValid ) {
183 this.actions.setAbilities( { save: isValid } );
190 mw.Upload.Dialog.prototype.getSetupProcess = function ( data ) {
191 return mw.Upload.Dialog.super.prototype.getSetupProcess.call( this, data )
192 .next( () => this.uploadBooklet.initialize() );
199 mw.Upload.Dialog.prototype.getActionProcess = function ( action ) {
200 if ( action === 'upload' ) {
201 return new OO.ui.Process( this.uploadBooklet.uploadFile() );
203 if ( action === 'save' ) {
204 return new OO.ui.Process( this.uploadBooklet.saveFile() );
206 if ( action === 'insert' ) {
207 return new OO.ui.Process( () => {
208 this.close( this.upload );
211 if ( action === 'cancel' ) {
212 return new OO.ui.Process( this.close().closed );
214 if ( action === 'cancelupload' ) {
215 return new OO.ui.Process( this.uploadBooklet.initialize() );
218 return mw.Upload.Dialog.super.prototype.getActionProcess.call( this, action );
225 mw.Upload.Dialog.prototype.getTeardownProcess = function ( data ) {
226 return mw.Upload.Dialog.super.prototype.getTeardownProcess.call( this, data )
228 this.uploadBooklet.clear();