this.filePreview = new OO.ui.Widget( {
classes: [ 'mw-upload-bookletLayout-filePreview' ]
} );
+ this.progressBarWidget = new OO.ui.ProgressBarWidget( {
+ progress: 0
+ } );
+ this.filePreview.$element.append( this.progressBarWidget.$element );
+
this.filenameWidget = new OO.ui.TextInputWidget( {
required: true,
validate: /.+/
this.descriptionWidget.on( 'change', this.onInfoFormChange.bind( this ) );
this.dateWidget.on( 'change', this.onInfoFormChange.bind( this ) );
+ this.on( 'fileUploadProgress', function ( progress ) {
+ this.progressBarWidget.setProgress( progress * 100 );
+ }.bind( this ) );
+
return this.infoForm;
};
-( function ( $, mw ) {
+/*global moment*/
+( function ( $, mw, moment ) {
/**
* mw.Upload.BookletLayout encapsulates the process of uploading a file
/* Events */
+ /**
+ * Progress events for the uploaded file
+ *
+ * @event fileUploadProgress
+ * @param {number} progress In percentage
+ * @param {Object} duration Duration object from `moment.duration()`
+ */
+
/**
* The file has finished uploading
*
* file object.
*
* @protected
+ * @fires fileUploadProgress
* @fires fileUploaded
* @return {jQuery.Promise}
*/
mw.Upload.BookletLayout.prototype.uploadFile = function () {
var deferred = $.Deferred(),
+ startTime = new Date(),
layout = this,
file = this.getFile();
// really be an error...
var errorMessage = layout.getErrorMessageForStateDetails();
deferred.reject( errorMessage );
+ }, function ( progress ) {
+ var elapsedTime = new Date() - startTime,
+ estimatedTotalTime = ( 1 / progress ) * elapsedTime,
+ estimatedRemainingTime = moment.duration( estimatedTotalTime - elapsedTime );
+ layout.emit( 'fileUploadProgress', progress, estimatedRemainingTime );
} );
// If there is an error in uploading, come back to the upload page
this.filePreview = new OO.ui.Widget( {
classes: [ 'mw-upload-bookletLayout-filePreview' ]
} );
+ this.progressBarWidget = new OO.ui.ProgressBarWidget( {
+ progress: 0
+ } );
+ this.filePreview.$element.append( this.progressBarWidget.$element );
+
this.filenameWidget = new OO.ui.TextInputWidget( {
indicator: 'required',
required: true,
items: [ this.filePreview, fieldset ]
} );
+ this.on( 'fileUploadProgress', function ( progress ) {
+ this.progressBarWidget.setProgress( progress * 100 );
+ }.bind( this ) );
+
this.filenameWidget.on( 'change', this.onInfoFormChange.bind( this ) );
this.descriptionWidget.on( 'change', this.onInfoFormChange.bind( this ) );
*/
mw.Upload.BookletLayout.prototype.clear = function () {
this.selectFileWidget.setValue( null );
+ this.progressBarWidget.setProgress( 0 );
this.filenameWidget.setValue( null ).setValidityFlag( true );
this.descriptionWidget.setValue( null ).setValidityFlag( true );
this.filenameUsageWidget.setValue( null );
};
-}( jQuery, mediaWiki ) );
+}( jQuery, mediaWiki, moment ) );