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 */
61 mw
.Upload
.Dialog
.static.title
= mw
.msg( 'upload-dialog-title' );
67 mw
.Upload
.Dialog
.static.actions
= [
71 label
: mw
.msg( 'upload-dialog-button-cancel' ),
72 modes
: [ 'upload', 'insert', 'info' ]
75 flags
: [ 'primary', 'progressive' ],
76 label
: mw
.msg( 'upload-dialog-button-done' ),
81 flags
: [ 'primary', 'constructive' ],
82 label
: mw
.msg( 'upload-dialog-button-save' ),
87 flags
: [ 'primary', 'progressive' ],
88 label
: mw
.msg( 'upload-dialog-button-upload' ),
101 mw
.Upload
.Dialog
.prototype.initialize = function () {
103 mw
.Upload
.Dialog
.parent
.prototype.initialize
.call( this );
105 this.uploadBooklet
= this.createUploadBooklet();
106 this.uploadBooklet
.connect( this, {
107 set: 'onUploadBookletSet',
108 uploadValid
: 'onUploadValid',
109 infoValid
: 'onInfoValid'
112 this.$body
.append( this.uploadBooklet
.$element
);
116 * Create an upload booklet
119 * @return {mw.Upload.BookletLayout} An upload booklet
121 mw
.Upload
.Dialog
.prototype.createUploadBooklet = function () {
122 return new this.bookletClass( $.extend( {
123 $overlay
: this.$overlay
124 }, this.bookletConfig
) );
130 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
135 * Handle panelNameSet events from the upload booklet
138 * @param {OO.ui.PageLayout} page Current page
140 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
141 this.actions
.setMode( page
.getName() );
142 this.actions
.setAbilities( { upload
: false, save
: false } );
146 * Handle uploadValid events
148 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
149 * for the dialog accordingly.
152 * @param {boolean} isValid The panel is complete and valid
154 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
155 this.actions
.setAbilities( { upload
: isValid
} );
159 * Handle infoValid 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.onInfoValid = function ( isValid
) {
168 this.actions
.setAbilities( { save
: isValid
} );
174 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
175 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
177 return this.uploadBooklet
.initialize();
184 mw
.Upload
.Dialog
.prototype.getActionProcess = function ( action
) {
187 if ( action
=== 'upload' ) {
188 return new OO
.ui
.Process( this.uploadBooklet
.uploadFile() );
190 if ( action
=== 'save' ) {
191 return new OO
.ui
.Process( this.uploadBooklet
.saveFile() );
193 if ( action
=== 'insert' ) {
194 return new OO
.ui
.Process( function () {
195 dialog
.close( dialog
.upload
);
198 if ( action
=== 'cancel' ) {
199 return new OO
.ui
.Process( this.close() );
202 return mw
.Upload
.Dialog
.parent
.prototype.getActionProcess
.call( this, action
);
208 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
209 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
211 this.uploadBooklet
.clear();
214 }( jQuery
, mediaWiki
) );