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
32 * @cfg {Function} [bookletClass=mw.Upload.BookletLayout] Booklet class to be
34 * @cfg {Object} [booklet] Booklet constructor configuration
36 mw
.Upload
.Dialog = function ( config
) {
37 // Config initialization
39 bookletClass
: mw
.Upload
.BookletLayout
43 mw
.Upload
.Dialog
.parent
.call( this, config
);
46 this.bookletClass
= config
.bookletClass
;
47 this.bookletConfig
= config
.booklet
;
52 OO
.inheritClass( mw
.Upload
.Dialog
, OO
.ui
.ProcessDialog
);
54 /* Static Properties */
60 mw
.Upload
.Dialog
.static.title
= mw
.msg( 'upload-dialog-title' );
66 mw
.Upload
.Dialog
.static.actions
= [
70 label
: mw
.msg( 'upload-dialog-button-cancel' ),
71 modes
: [ 'upload', 'insert' ]
75 action
: 'cancelupload',
76 label
: mw
.msg( 'upload-dialog-button-back' ),
80 flags
: [ 'primary', 'progressive' ],
81 label
: mw
.msg( 'upload-dialog-button-done' ),
86 flags
: [ 'primary', 'progressive' ],
87 label
: mw
.msg( 'upload-dialog-button-save' ),
92 flags
: [ 'primary', 'progressive' ],
93 label
: mw
.msg( 'upload-dialog-button-upload' ),
104 mw
.Upload
.Dialog
.prototype.initialize = function () {
106 mw
.Upload
.Dialog
.parent
.prototype.initialize
.call( this );
108 this.uploadBooklet
= this.createUploadBooklet();
109 this.uploadBooklet
.connect( this, {
110 set: 'onUploadBookletSet',
111 uploadValid
: 'onUploadValid',
112 infoValid
: 'onInfoValid'
115 this.$body
.append( this.uploadBooklet
.$element
);
119 * Create an upload booklet
122 * @return {mw.Upload.BookletLayout} An upload booklet
124 mw
.Upload
.Dialog
.prototype.createUploadBooklet = function () {
125 // eslint-disable-next-line new-cap
126 return new this.bookletClass( $.extend( {
127 $overlay
: this.$overlay
128 }, this.bookletConfig
) );
134 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
139 * Handle panelNameSet events from the upload booklet
142 * @param {OO.ui.PageLayout} page Current page
144 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
145 this.actions
.setMode( page
.getName() );
146 this.actions
.setAbilities( { upload
: false, save
: false } );
150 * Handle uploadValid events
152 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
153 * for the dialog accordingly.
156 * @param {boolean} isValid The panel is complete and valid
158 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
159 this.actions
.setAbilities( { upload
: isValid
} );
163 * Handle infoValid events
165 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
166 * for the dialog accordingly.
169 * @param {boolean} isValid The panel is complete and valid
171 mw
.Upload
.Dialog
.prototype.onInfoValid = function ( isValid
) {
172 this.actions
.setAbilities( { save
: isValid
} );
178 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
179 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
181 return this.uploadBooklet
.initialize();
188 mw
.Upload
.Dialog
.prototype.getActionProcess = function ( action
) {
191 if ( action
=== 'upload' ) {
192 return new OO
.ui
.Process( this.uploadBooklet
.uploadFile() );
194 if ( action
=== 'save' ) {
195 return new OO
.ui
.Process( this.uploadBooklet
.saveFile() );
197 if ( action
=== 'insert' ) {
198 return new OO
.ui
.Process( function () {
199 dialog
.close( dialog
.upload
);
202 if ( action
=== 'cancel' ) {
203 return new OO
.ui
.Process( this.close() );
205 if ( action
=== 'cancelupload' ) {
206 return new OO
.ui
.Process( this.uploadBooklet
.initialize() );
209 return mw
.Upload
.Dialog
.parent
.prototype.getActionProcess
.call( this, action
);
215 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
216 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
218 this.uploadBooklet
.clear();
221 }( jQuery
, mediaWiki
) );