Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/321663
Change subject: Add "copy all fields" feature again after having failed to submit ...................................................................... Add "copy all fields" feature again after having failed to submit And make sure it is only added under the correct circumstances (not less than 2 editable uploads) and in the correct position (below the first editoable upload) Bug: T150523 Change-Id: I0ac3405e6aa27419588034c40f6d247ec12eb0ea --- M resources/controller/uw.controller.Details.js M resources/mw.UploadWizardDetails.js 2 files changed, 44 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard refs/changes/63/321663/1 diff --git a/resources/controller/uw.controller.Details.js b/resources/controller/uw.controller.Details.js index 8058203..321e173 100644 --- a/resources/controller/uw.controller.Details.js +++ b/resources/controller/uw.controller.Details.js @@ -53,13 +53,9 @@ * @param {mw.UploadWizardUpload[]} uploads List of uploads being carried forward. */ uw.controller.Details.prototype.moveTo = function ( uploads ) { - var details = this, - failures, successes; + var details = this; uw.controller.Step.prototype.moveTo.call( this, uploads ); - - failures = this.getUploadStatesCount( [ 'aborted', 'error' ] ) + this.countEmpties(); - successes = uploads.length - failures; $.each( uploads, function ( i, upload ) { var serialized; @@ -85,14 +81,13 @@ } ); // Show the widget allowing to copy selected metadata if there's more than one successful upload - if ( successes > 1 && this.config.copyMetadataFeature ) { + if ( this.config.copyMetadataFeature ) { this.addCopyMetadataFeature( uploads ); } - if ( successes > 0 ) { - $.each( uploads, function ( i, upload ) { - upload.on( 'remove-upload', details.removeUpload.bind( details ) ); - } ); - } + + $.each( uploads, function ( i, upload ) { + upload.on( 'remove-upload', details.removeUpload.bind( details ) ); + } ); }; uw.controller.Details.prototype.moveNext = function () { @@ -123,13 +118,42 @@ }; uw.controller.Details.prototype.addCopyMetadataFeature = function ( uploads ) { + var first, + // uploads can only be edited when they're in a certain state: + // a flat out upload failure or a completed upload can not be edited + invalidStates = [ 'aborted', 'error', 'complete' ], + invalids = this.getUploadStatesCount( invalidStates ) + this.countEmpties(), + valids = uploads.length - invalids; + + // no point in having this feature if there's no target to copy to + if ( valids < 2 ) { + return; + } + + // The first upload is not necessarily the one we want to copy from + // E.g. the first upload could've gone through successfully, but the + // rest failed because of abusefilter (or another recoverable error), in + // which case we'll want the "copy" feature to appear below the 2nd + // upload (or the first not-yet-completed not flat-out-failed upload) + $.each( uploads, function ( i, upload ) { + if ( upload && invalidStates.indexOf( upload.state ) === -1 ) { + first = upload; + return false; + } + } ); + + // could not find a source upload to copy from + if ( !first ) { + return; + } + this.copyMetadataWidget = new uw.CopyMetadataWidget( { - copyFrom: uploads[ 0 ], + copyFrom: first, // Include the "source" upload in the targets too copyTo: uploads } ); - $( uploads[ 0 ].details.div ).after( this.copyMetadataWidget.$element ); + $( first.details.div ).after( this.copyMetadataWidget.$element ); }; uw.controller.Details.prototype.removeCopyMetadataFeature = function () { @@ -366,7 +390,7 @@ } // Clear error state - if ( upload.state === 'error' ) { + if ( upload.state === 'error' || upload.state === 'recoverable-error' ) { upload.state = details.stepName; } @@ -377,7 +401,6 @@ // Disable edit interface this.ui.disableEdits(); this.ui.previousButton.$element.hide(); - // No way to restore this later... We don't handle partially-successful uploads very well this.removeCopyMetadataFeature(); return this.transitionAll().then( function () { @@ -396,6 +419,9 @@ uw.controller.Details.prototype.showErrors = function () { this.ui.previousButton.$element.show(); + this.removeCopyMetadataFeature(); + this.addCopyMetadataFeature( this.uploads ); + this.ui.showWarnings(); // Scroll to the warning first so that any errors will have precedence this.ui.showErrors(); }; @@ -404,16 +430,13 @@ * Handler for when an upload is removed. */ uw.controller.Details.prototype.removeUpload = function () { - var failures = this.getUploadStatesCount( [ 'aborted', 'error' ] ) + this.countEmpties(), - successes = this.uploads.length - failures; - this.removeCopyMetadataFeature(); // Make sure we still have more multiple uploads adding the // copy feature again - if ( successes > 1 && this.config.copyMetadataFeature ) { + if ( this.config.copyMetadataFeature ) { this.addCopyMetadataFeature( this.uploads ); - } else if ( successes < 1 ) { + } else if ( this.uploads.length === 0 ) { // If we have no more uploads, go to the "Upload" step. (This will go to "Thanks" step, // which will skip itself in moveTo() because there are no uploads left.) this.moveNext(); diff --git a/resources/mw.UploadWizardDetails.js b/resources/mw.UploadWizardDetails.js index 75673ee..d9e6335 100644 --- a/resources/mw.UploadWizardDetails.js +++ b/resources/mw.UploadWizardDetails.js @@ -922,7 +922,7 @@ */ recoverFromError: function ( errorMessage, errorCode ) { uw.eventFlowLogger.logError( 'details', { code: errorCode, message: errorMessage } ); - this.upload.state = 'error'; + this.upload.state = 'recoverable-error'; this.dataDiv.morphCrossfade( '.detailsForm' ); this.titleDetailsField.setErrors( [ errorMessage ] ); }, -- To view, visit https://gerrit.wikimedia.org/r/321663 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0ac3405e6aa27419588034c40f6d247ec12eb0ea Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UploadWizard Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits