| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.ProgressDialog = function VeUiProgressDialog( config ) { |
| 17 |
|
| 18 |
ve.ui.ProgressDialog.super.call( this, config ); |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.inheritClass( ve.ui.ProgressDialog, OO.ui.MessageDialog ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
ve.ui.ProgressDialog.static.name = 'progress'; |
| 28 |
|
| 29 |
ve.ui.ProgressDialog.static.size = 'medium'; |
| 30 |
|
| 31 |
ve.ui.ProgressDialog.static.actions = [ |
| 32 |
{ |
| 33 |
action: 'cancel', |
| 34 |
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ), |
| 35 |
flags: 'destructive', |
| 36 |
modes: 'cancellable' |
| 37 |
} |
| 38 |
]; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
ve.ui.ProgressDialog.static.escapable = false; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ve.ui.ProgressDialog.prototype.initialize = function () { |
| 50 |
|
| 51 |
ve.ui.ProgressDialog.super.prototype.initialize.call( this ); |
| 52 |
|
| 53 |
|
| 54 |
this.inProgress = 0; |
| 55 |
this.cancelDeferreds = []; |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ve.ui.ProgressDialog.prototype.getSetupProcess = function ( data ) { |
| 62 |
data = data || {}; |
| 63 |
|
| 64 |
|
| 65 |
return ve.ui.ProgressDialog.super.prototype.getSetupProcess.call( this, data ) |
| 66 |
.next( () => { |
| 67 |
const progresses = data.progresses; |
| 68 |
|
| 69 |
let cancellable = false; |
| 70 |
this.inProgress = progresses.length; |
| 71 |
this.text.$element.empty(); |
| 72 |
this.cancelDeferreds = []; |
| 73 |
|
| 74 |
for ( let i = 0, l = progresses.length; i < l; i++ ) { |
| 75 |
const cancelDeferred = ve.createDeferred(); |
| 76 |
const $row = $( '<div>' ).addClass( 've-ui-progressDialog-row' ); |
| 77 |
const progressBar = new OO.ui.ProgressBarWidget(); |
| 78 |
const fieldLayout = new OO.ui.FieldLayout( |
| 79 |
progressBar, |
| 80 |
{ |
| 81 |
label: progresses[ i ].label, |
| 82 |
align: 'top' |
| 83 |
} |
| 84 |
); |
| 85 |
|
| 86 |
$row.append( fieldLayout.$element ); |
| 87 |
|
| 88 |
if ( progresses[ i ].cancellable ) { |
| 89 |
const cancelButton = new OO.ui.ButtonWidget( { |
| 90 |
framed: false, |
| 91 |
icon: 'cancel', |
| 92 |
title: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ) |
| 93 |
} ).on( 'click', cancelDeferred.reject.bind( cancelDeferred ) ); |
| 94 |
$row.append( cancelButton.$element ); |
| 95 |
cancellable = true; |
| 96 |
} |
| 97 |
|
| 98 |
this.text.$element.append( $row ); |
| 99 |
progresses[ i ].progressBarDeferred.resolve( progressBar, cancelDeferred.promise() ); |
| 100 |
progresses[ i ].progressCompletePromise.then( |
| 101 |
this.progressComplete.bind( this, $row, false ), |
| 102 |
this.progressComplete.bind( this, $row, true ) |
| 103 |
); |
| 104 |
this.cancelDeferreds.push( cancelDeferred ); |
| 105 |
} |
| 106 |
this.actions.setMode( cancellable ? 'cancellable' : 'default' ); |
| 107 |
} ); |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
ve.ui.ProgressDialog.prototype.getActionProcess = function ( action ) { |
| 114 |
return new OO.ui.Process( () => { |
| 115 |
if ( action === 'cancel' ) { |
| 116 |
for ( let i = 0, l = this.cancelDeferreds.length; i < l; i++ ) { |
| 117 |
this.cancelDeferreds[ i ].reject(); |
| 118 |
} |
| 119 |
} |
| 120 |
this.close( { action: action } ); |
| 121 |
} ); |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ve.ui.ProgressDialog.prototype.progressComplete = function ( $row, failed ) { |
| 131 |
this.inProgress--; |
| 132 |
if ( !this.inProgress ) { |
| 133 |
this.close(); |
| 134 |
} |
| 135 |
if ( failed ) { |
| 136 |
$row.remove(); |
| 137 |
this.updateSize(); |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
ve.ui.windowFactory.register( ve.ui.ProgressDialog ); |