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' ]
76 action
: 'cancelupload',
77 label
: mw
.msg( 'upload-dialog-button-back' ),
81 flags
: [ 'primary', 'progressive' ],
82 label
: mw
.msg( 'upload-dialog-button-done' ),
87 flags
: [ 'primary', 'constructive' ],
88 label
: mw
.msg( 'upload-dialog-button-save' ),
93 flags
: [ 'primary', 'progressive' ],
94 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 return new this.bookletClass( $.extend( {
129 $overlay
: this.$overlay
130 }, this.bookletConfig
) );
136 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
141 * Handle panelNameSet events from the upload booklet
144 * @param {OO.ui.PageLayout} page Current page
146 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
147 this.actions
.setMode( page
.getName() );
148 this.actions
.setAbilities( { upload
: false, save
: false } );
152 * Handle uploadValid events
154 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
155 * for the dialog accordingly.
158 * @param {boolean} isValid The panel is complete and valid
160 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
161 this.actions
.setAbilities( { upload
: isValid
} );
165 * Handle infoValid events
167 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
168 * for the dialog accordingly.
171 * @param {boolean} isValid The panel is complete and valid
173 mw
.Upload
.Dialog
.prototype.onInfoValid = function ( isValid
) {
174 this.actions
.setAbilities( { save
: isValid
} );
180 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
181 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
183 return this.uploadBooklet
.initialize();
190 mw
.Upload
.Dialog
.prototype.getActionProcess = function ( action
) {
193 if ( action
=== 'upload' ) {
194 return new OO
.ui
.Process( this.uploadBooklet
.uploadFile() );
196 if ( action
=== 'save' ) {
197 return new OO
.ui
.Process( this.uploadBooklet
.saveFile() );
199 if ( action
=== 'insert' ) {
200 return new OO
.ui
.Process( function () {
201 dialog
.close( dialog
.upload
);
204 if ( action
=== 'cancel' ) {
205 return new OO
.ui
.Process( this.close() );
207 if ( action
=== 'cancelupload' ) {
208 return new OO
.ui
.Process( this.uploadBooklet
.initialize() );
211 return mw
.Upload
.Dialog
.parent
.prototype.getActionProcess
.call( this, action
);
217 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
218 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
220 this.uploadBooklet
.clear();
223 }( jQuery
, mediaWiki
) );