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
23 mw
.Upload
.Dialog = function ( config
) {
25 mw
.Upload
.Dialog
.parent
.call( this, config
);
30 OO
.inheritClass( mw
.Upload
.Dialog
, OO
.ui
.ProcessDialog
);
32 /* Static Properties */
39 mw
.Upload
.Dialog
.static.title
= mw
.msg( 'upload-dialog-title' );
45 mw
.Upload
.Dialog
.static.actions
= [
49 label
: mw
.msg( 'upload-dialog-button-cancel' ),
50 modes
: [ 'upload', 'insert', 'info' ]
53 flags
: [ 'primary', 'progressive' ],
54 label
: mw
.msg( 'upload-dialog-button-done' ),
59 flags
: [ 'primary', 'constructive' ],
60 label
: mw
.msg( 'upload-dialog-button-save' ),
65 flags
: [ 'primary', 'progressive' ],
66 label
: mw
.msg( 'upload-dialog-button-upload' ),
79 mw
.Upload
.Dialog
.prototype.initialize = function () {
81 mw
.Upload
.Dialog
.parent
.prototype.initialize
.call( this );
83 this.uploadBooklet
= this.createUploadBooklet();
84 this.uploadBooklet
.connect( this, {
85 set: 'onUploadBookletSet',
86 uploadValid
: 'onUploadValid',
87 infoValid
: 'onInfoValid'
90 this.$body
.append( this.uploadBooklet
.$element
);
94 * Create an upload booklet
97 * @return {mw.Upload.BookletLayout} An upload booklet
99 mw
.Upload
.Dialog
.prototype.createUploadBooklet = function () {
100 return new mw
.Upload
.BookletLayout();
106 mw
.Upload
.Dialog
.prototype.getBodyHeight = function () {
111 * Handle panelNameSet events from the upload booklet
114 * @param {OO.ui.PageLayout} page Current page
116 mw
.Upload
.Dialog
.prototype.onUploadBookletSet = function ( page
) {
117 this.actions
.setMode( page
.getName() );
118 this.actions
.setAbilities( { upload
: false, save
: false } );
122 * Handle uploadValid events
124 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
125 * for the dialog accordingly.
128 * @param {boolean} isValid The panel is complete and valid
130 mw
.Upload
.Dialog
.prototype.onUploadValid = function ( isValid
) {
131 this.actions
.setAbilities( { upload
: isValid
} );
135 * Handle infoValid events
137 * {@link OO.ui.ActionSet#setAbilities Sets abilities}
138 * for the dialog accordingly.
141 * @param {boolean} isValid The panel is complete and valid
143 mw
.Upload
.Dialog
.prototype.onInfoValid = function ( isValid
) {
144 this.actions
.setAbilities( { save
: isValid
} );
150 mw
.Upload
.Dialog
.prototype.getSetupProcess = function ( data
) {
151 return mw
.Upload
.Dialog
.parent
.prototype.getSetupProcess
.call( this, data
)
153 this.uploadBooklet
.initialize();
160 mw
.Upload
.Dialog
.prototype.getActionProcess = function ( action
) {
163 if ( action
=== 'upload' ) {
164 return new OO
.ui
.Process( this.uploadBooklet
.uploadFile() );
166 if ( action
=== 'save' ) {
167 return new OO
.ui
.Process( this.uploadBooklet
.saveFile() );
169 if ( action
=== 'insert' ) {
170 return new OO
.ui
.Process( function () {
171 dialog
.close( dialog
.upload
);
174 if ( action
=== 'cancel' ) {
175 return new OO
.ui
.Process( this.close() );
178 return mw
.Upload
.Dialog
.parent
.prototype.getActionProcess
.call( this, action
);
184 mw
.Upload
.Dialog
.prototype.getTeardownProcess = function ( data
) {
185 return mw
.Upload
.Dialog
.parent
.prototype.getTeardownProcess
.call( this, data
)
187 this.uploadBooklet
.clear();
191 }( jQuery
, mediaWiki
) );