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.name
= 'mwUploadDialog';
69 mw
.Upload
.Dialog
.static.title
= mw
.msg( 'upload-dialog-title' );
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' ),
113 mw
.Upload
.Dialog
.prototype.initialize = function () {
115 mw
.Upload
.Dialog
.parent
.prototype.initialize
.call( this );
117 this.uploadBooklet
= this.createUploadBooklet();
118 this.uploadBooklet
.connect( this, {
119 set: 'onUploadBookletSet',
120 uploadValid
: 'onUploadValid',
121 infoValid
: 'onInfoValid'
124 this.$body
.append( this.uploadBooklet
.$element
);
128 * Create an upload booklet
131 * @return {mw.Upload.BookletLayout} An upload booklet
133 mw
.Upload
.Dialog
.prototype.createUploadBooklet = function () {
134 // eslint-disable-next-line new-cap
135 return new this.bookletClass( $.extend( {
136 $overlay
: this.$overlay
137 }, this.bookletConfig
) );
143 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
148 * Handle panelNameSet events from the upload booklet
151 * @param {OO.ui.PageLayout} page Current page
153 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
154 this.actions
.setMode( page
.getName() );
155 this.actions
.setAbilities( { upload
: false, save
: false } );
159 * Handle uploadValid events
161 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
162 * for the dialog accordingly.
165 * @param {boolean} isValid The panel is complete and valid
167 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
168 this.actions
.setAbilities( { upload
: isValid
} );
172 * Handle infoValid events
174 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
175 * for the dialog accordingly.
178 * @param {boolean} isValid The panel is complete and valid
180 mw
.Upload
.Dialog
.prototype.onInfoValid = function ( isValid
) {
181 this.actions
.setAbilities( { save
: isValid
} );
187 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
188 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
190 return this.uploadBooklet
.initialize();
197 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( function () {
208 dialog
.close( dialog
.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
.parent
.prototype.getActionProcess
.call( this, action
);
224 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
225 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
227 this.uploadBooklet
.clear();
230 }( jQuery
, mediaWiki
) );