| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
mw.Upload.Dialog = function ( config ) { |
| 40 |
|
| 41 |
config = Object.assign( { |
| 42 |
bookletClass: mw.Upload.BookletLayout |
| 43 |
}, config ); |
| 44 |
|
| 45 |
|
| 46 |
mw.Upload.Dialog.super.call( this, config ); |
| 47 |
|
| 48 |
|
| 49 |
this.bookletClass = config.bookletClass; |
| 50 |
this.bookletConfig = config.booklet; |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
OO.inheritClass( mw.Upload.Dialog, OO.ui.ProcessDialog ); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
mw.Upload.Dialog.static.name = 'mwUploadDialog'; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
mw.Upload.Dialog.static.title = mw.msg( 'upload-dialog-title' ); |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
mw.Upload.Dialog.static.actions = [ |
| 76 |
{ |
| 77 |
flags: 'safe', |
| 78 |
action: 'cancel', |
| 79 |
label: mw.msg( 'upload-dialog-button-cancel' ), |
| 80 |
modes: [ 'upload', 'insert' ] |
| 81 |
}, |
| 82 |
{ |
| 83 |
flags: 'safe', |
| 84 |
action: 'cancelupload', |
| 85 |
label: mw.msg( 'upload-dialog-button-back' ), |
| 86 |
modes: [ 'info' ] |
| 87 |
}, |
| 88 |
{ |
| 89 |
flags: [ 'primary', 'progressive' ], |
| 90 |
label: mw.msg( 'upload-dialog-button-done' ), |
| 91 |
action: 'insert', |
| 92 |
modes: 'insert' |
| 93 |
}, |
| 94 |
{ |
| 95 |
flags: [ 'primary', 'progressive' ], |
| 96 |
label: mw.msg( 'upload-dialog-button-save' ), |
| 97 |
action: 'save', |
| 98 |
modes: 'info' |
| 99 |
}, |
| 100 |
{ |
| 101 |
flags: [ 'primary', 'progressive' ], |
| 102 |
label: mw.msg( 'upload-dialog-button-upload' ), |
| 103 |
action: 'upload', |
| 104 |
modes: 'upload' |
| 105 |
} |
| 106 |
]; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
mw.Upload.Dialog.prototype.initialize = function () { |
| 115 |
|
| 116 |
mw.Upload.Dialog.super.prototype.initialize.call( this ); |
| 117 |
|
| 118 |
this.uploadBooklet = this.createUploadBooklet(); |
| 119 |
this.uploadBooklet.connect( this, { |
| 120 |
set: 'onUploadBookletSet', |
| 121 |
uploadValid: 'onUploadValid', |
| 122 |
infoValid: 'onInfoValid' |
| 123 |
} ); |
| 124 |
|
| 125 |
this.$body.append( this.uploadBooklet.$element ); |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
mw.Upload.Dialog.prototype.createUploadBooklet = function () { |
| 135 |
|
| 136 |
return new this.bookletClass( Object.assign( { |
| 137 |
$overlay: this.$overlay |
| 138 |
}, this.bookletConfig ) ); |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
mw.Upload.Dialog.prototype.getBodyHeight = function () { |
| 146 |
return 600; |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
mw.Upload.Dialog.prototype.onUploadBookletSet = function ( page ) { |
| 156 |
this.actions.setMode( page.getName() ); |
| 157 |
this.actions.setAbilities( { upload: false, save: false } ); |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
mw.Upload.Dialog.prototype.onUploadValid = function ( isValid ) { |
| 170 |
this.actions.setAbilities( { upload: isValid } ); |
| 171 |
}; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
mw.Upload.Dialog.prototype.onInfoValid = function ( isValid ) { |
| 183 |
this.actions.setAbilities( { save: isValid } ); |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
mw.Upload.Dialog.prototype.getSetupProcess = function ( data ) { |
| 191 |
return mw.Upload.Dialog.super.prototype.getSetupProcess.call( this, data ) |
| 192 |
.next( function () { |
| 193 |
return this.uploadBooklet.initialize(); |
| 194 |
}, this ); |
| 195 |
}; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
mw.Upload.Dialog.prototype.getActionProcess = function ( action ) { |
| 202 |
const dialog = this; |
| 203 |
|
| 204 |
if ( action === 'upload' ) { |
| 205 |
return new OO.ui.Process( this.uploadBooklet.uploadFile() ); |
| 206 |
} |
| 207 |
if ( action === 'save' ) { |
| 208 |
return new OO.ui.Process( this.uploadBooklet.saveFile() ); |
| 209 |
} |
| 210 |
if ( action === 'insert' ) { |
| 211 |
return new OO.ui.Process( () => { |
| 212 |
dialog.close( dialog.upload ); |
| 213 |
} ); |
| 214 |
} |
| 215 |
if ( action === 'cancel' ) { |
| 216 |
return new OO.ui.Process( this.close().closed ); |
| 217 |
} |
| 218 |
if ( action === 'cancelupload' ) { |
| 219 |
return new OO.ui.Process( this.uploadBooklet.initialize() ); |
| 220 |
} |
| 221 |
|
| 222 |
return mw.Upload.Dialog.super.prototype.getActionProcess.call( this, action ); |
| 223 |
}; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
mw.Upload.Dialog.prototype.getTeardownProcess = function ( data ) { |
| 230 |
return mw.Upload.Dialog.super.prototype.getTeardownProcess.call( this, data ) |
| 231 |
.next( function () { |
| 232 |
this.uploadBooklet.clear(); |
| 233 |
}, this ); |
| 234 |
}; |
| 235 |
}() ); |