8bda6019c79a1a0b9b8872202a7a4c7f5d331e3f
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 return new this.bookletClass( $.extend( {
126 $overlay
: this.$overlay
127 }, this.bookletConfig
) );
133 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
138 * Handle panelNameSet events from the upload booklet
141 * @param {OO.ui.PageLayout} page Current page
143 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
144 this.actions
.setMode( page
.getName() );
145 this.actions
.setAbilities( { upload
: false, save
: false } );
149 * Handle uploadValid events
151 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
152 * for the dialog accordingly.
155 * @param {boolean} isValid The panel is complete and valid
157 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
158 this.actions
.setAbilities( { upload
: isValid
} );
162 * Handle infoValid events
164 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
165 * for the dialog accordingly.
168 * @param {boolean} isValid The panel is complete and valid
170 mw
.Upload
.Dialog
.prototype.onInfoValid = function ( isValid
) {
171 this.actions
.setAbilities( { save
: isValid
} );
177 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
178 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
180 return this.uploadBooklet
.initialize();
187 mw
.Upload
.Dialog
.prototype.getActionProcess = function ( action
) {
190 if ( action
=== 'upload' ) {
191 return new OO
.ui
.Process( this.uploadBooklet
.uploadFile() );
193 if ( action
=== 'save' ) {
194 return new OO
.ui
.Process( this.uploadBooklet
.saveFile() );
196 if ( action
=== 'insert' ) {
197 return new OO
.ui
.Process( function () {
198 dialog
.close( dialog
.upload
);
201 if ( action
=== 'cancel' ) {
202 return new OO
.ui
.Process( this.close() );
204 if ( action
=== 'cancelupload' ) {
205 return new OO
.ui
.Process( this.uploadBooklet
.initialize() );
208 return mw
.Upload
.Dialog
.parent
.prototype.getActionProcess
.call( this, action
);
214 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
215 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
217 this.uploadBooklet
.clear();
220 }( jQuery
, mediaWiki
) );