4 * mw.Upload.Dialog controls a {@link mw.Upload.BookletLayout BookletLayout}.
8 * To use, setup 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 * $( 'body' ).append( windowManager.$element );
14 * windowManager.addWindows( [ uploadDialog ] );
15 * windowManager.openWindow( uploadDialog );
17 * The dialog's closing promise can be used to get details of the upload.
19 * If you want to use a different OO.ui.BookletLayout, for example the
20 * mw.ForeignStructuredUpload.BookletLayout, like in the case of of the upload
21 * interface in VisualEditor, you can pass it in the {@link #cfg-bookletClass}:
23 * var uploadDialog = new mw.Upload.Dialog( {
24 * bookletClass: mw.ForeignStructuredUpload.BookletLayout
28 * @class mw.Upload.Dialog
30 * @uses mw.Upload.BookletLayout
31 * @extends OO.ui.ProcessDialog
34 * @param {Object} [config] Configuration options
35 * @cfg {Function} [bookletClass=mw.Upload.BookletLayout] Booklet class to be
37 * @cfg {Object} [booklet] Booklet constructor configuration
39 mw.Upload.Dialog = function ( config ) {
40 // Config initialization
42 bookletClass: mw.Upload.BookletLayout
46 mw.Upload.Dialog.parent.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 */
63 mw.Upload.Dialog.static.title = mw.msg( 'upload-dialog-title' );
69 mw.Upload.Dialog.static.actions = [
73 label: mw.msg( 'upload-dialog-button-cancel' ),
74 modes: [ 'upload', 'insert' ]
78 action: 'cancelupload',
79 label: mw.msg( 'upload-dialog-button-back' ),
83 flags: [ 'primary', 'progressive' ],
84 label: mw.msg( 'upload-dialog-button-done' ),
89 flags: [ 'primary', 'progressive' ],
90 label: mw.msg( 'upload-dialog-button-save' ),
95 flags: [ 'primary', 'progressive' ],
96 label: mw.msg( 'upload-dialog-button-upload' ),
107 mw.Upload.Dialog.prototype.initialize = function () {
109 mw.Upload.Dialog.parent.prototype.initialize.call( this );
111 this.uploadBooklet = this.createUploadBooklet();
112 this.uploadBooklet.connect( this, {
113 set: 'onUploadBookletSet',
114 uploadValid: 'onUploadValid',
115 infoValid: 'onInfoValid'
118 this.$body.append( this.uploadBooklet.$element );
122 * Create an upload booklet
125 * @return {mw.Upload.BookletLayout} An upload booklet
127 mw.Upload.Dialog.prototype.createUploadBooklet = function () {
128 // eslint-disable-next-line new-cap
129 return new this.bookletClass( $.extend( {
130 $overlay: this.$overlay
131 }, this.bookletConfig ) );
137 mw.Upload.Dialog.prototype.getBodyHeight = function () {
142 * Handle panelNameSet events from the upload booklet
145 * @param {OO.ui.PageLayout} page Current page
147 mw.Upload.Dialog.prototype.onUploadBookletSet = function ( page ) {
148 this.actions.setMode( page.getName() );
149 this.actions.setAbilities( { upload: false, save: false } );
153 * Handle uploadValid events
155 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
156 * for the dialog accordingly.
159 * @param {boolean} isValid The panel is complete and valid
161 mw.Upload.Dialog.prototype.onUploadValid = function ( isValid ) {
162 this.actions.setAbilities( { upload: isValid } );
166 * Handle infoValid events
168 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
169 * for the dialog accordingly.
172 * @param {boolean} isValid The panel is complete and valid
174 mw.Upload.Dialog.prototype.onInfoValid = function ( isValid ) {
175 this.actions.setAbilities( { save: isValid } );
181 mw.Upload.Dialog.prototype.getSetupProcess = function ( data ) {
182 return mw.Upload.Dialog.parent.prototype.getSetupProcess.call( this, data )
184 return this.uploadBooklet.initialize();
191 mw.Upload.Dialog.prototype.getActionProcess = function ( action ) {
194 if ( action === 'upload' ) {
195 return new OO.ui.Process( this.uploadBooklet.uploadFile() );
197 if ( action === 'save' ) {
198 return new OO.ui.Process( this.uploadBooklet.saveFile() );
200 if ( action === 'insert' ) {
201 return new OO.ui.Process( function () {
202 dialog.close( dialog.upload );
205 if ( action === 'cancel' ) {
206 return new OO.ui.Process( this.close() );
208 if ( action === 'cancelupload' ) {
209 return new OO.ui.Process( this.uploadBooklet.initialize() );
212 return mw.Upload.Dialog.parent.prototype.getActionProcess.call( this, action );
218 mw.Upload.Dialog.prototype.getTeardownProcess = function ( data ) {
219 return mw.Upload.Dialog.parent.prototype.getTeardownProcess.call( this, data )
221 this.uploadBooklet.clear();
224 }( jQuery, mediaWiki ) );