03e397180c74ec8e3624c7a57de8f1d6bd9f3bb2
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 * @class mw.Upload.Dialog
21 * @extends OO.ui.ProcessDialog
22 * @cfg {Function} [bookletClass=mw.Upload.BookletLayout] Booklet class to be
24 * @cfg {Object} [booklet] Booklet constructor configuration
26 mw
.Upload
.Dialog = function ( config
) {
27 // Config initialization
29 bookletClass
: mw
.Upload
.BookletLayout
33 mw
.Upload
.Dialog
.parent
.call( this, config
);
36 this.bookletClass
= config
.bookletClass
;
37 this.bookletConfig
= config
.booklet
;
42 OO
.inheritClass( mw
.Upload
.Dialog
, OO
.ui
.ProcessDialog
);
44 /* Static Properties */
51 mw
.Upload
.Dialog
.static.title
= mw
.msg( 'upload-dialog-title' );
57 mw
.Upload
.Dialog
.static.actions
= [
61 label
: mw
.msg( 'upload-dialog-button-cancel' ),
62 modes
: [ 'upload', 'insert', 'info' ]
65 flags
: [ 'primary', 'progressive' ],
66 label
: mw
.msg( 'upload-dialog-button-done' ),
71 flags
: [ 'primary', 'constructive' ],
72 label
: mw
.msg( 'upload-dialog-button-save' ),
77 flags
: [ 'primary', 'progressive' ],
78 label
: mw
.msg( 'upload-dialog-button-upload' ),
91 mw
.Upload
.Dialog
.prototype.initialize = function () {
93 mw
.Upload
.Dialog
.parent
.prototype.initialize
.call( this );
95 this.uploadBooklet
= this.createUploadBooklet();
96 this.uploadBooklet
.connect( this, {
97 set: 'onUploadBookletSet',
98 uploadValid
: 'onUploadValid',
99 infoValid
: 'onInfoValid'
102 this.$body
.append( this.uploadBooklet
.$element
);
106 * Create an upload booklet
109 * @return {mw.Upload.BookletLayout} An upload booklet
111 mw
.Upload
.Dialog
.prototype.createUploadBooklet = function () {
112 return new this.bookletClass( $.extend( {
113 $overlay
: this.$overlay
114 }, this.bookletConfig
) );
120 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
125 * Handle panelNameSet events from the upload booklet
128 * @param {OO.ui.PageLayout} page Current page
130 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
131 this.actions
.setMode( page
.getName() );
132 this.actions
.setAbilities( { upload
: false, save
: false } );
136 * Handle uploadValid events
138 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
139 * for the dialog accordingly.
142 * @param {boolean} isValid The panel is complete and valid
144 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
145 this.actions
.setAbilities( { upload
: isValid
} );
149 * Handle infoValid 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.onInfoValid = function ( isValid
) {
158 this.actions
.setAbilities( { save
: isValid
} );
164 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
165 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
167 this.uploadBooklet
.initialize();
174 mw
.Upload
.Dialog
.prototype.getActionProcess = function ( action
) {
177 if ( action
=== 'upload' ) {
178 return new OO
.ui
.Process( this.uploadBooklet
.uploadFile() );
180 if ( action
=== 'save' ) {
181 return new OO
.ui
.Process( this.uploadBooklet
.saveFile() );
183 if ( action
=== 'insert' ) {
184 return new OO
.ui
.Process( function () {
185 dialog
.close( dialog
.upload
);
188 if ( action
=== 'cancel' ) {
189 return new OO
.ui
.Process( this.close() );
192 return mw
.Upload
.Dialog
.parent
.prototype.getActionProcess
.call( this, action
);
198 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
199 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
201 this.uploadBooklet
.clear();
205 }( jQuery
, mediaWiki
) );