Matthias Mullie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394593 )

Change subject: Work around inconsistent $.when resolving
......................................................................

Work around inconsistent $.when resolving

If there's only 1 element in the array fed to $.when,
it would resolve with the arguments of that single element,
instead of a nested array (like we'd get when we pass multiple
items to $.when)

In the case of upload campaigns, we can have only 1 deed,
in which case the could would error/block because it assumes
a nested array of error/warning results.

Bug: T181737
Change-Id: Ie1515824acc8a46fcb7378cb07b2762f097eb766
---
M resources/controller/uw.controller.Deed.js
1 file changed, 14 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/93/394593/1

diff --git a/resources/controller/uw.controller.Deed.js 
b/resources/controller/uw.controller.Deed.js
index eb31b94..6c875f9 100644
--- a/resources/controller/uw.controller.Deed.js
+++ b/resources/controller/uw.controller.Deed.js
@@ -42,7 +42,7 @@
        uw.controller.Deed.prototype.moveNext = function () {
                var
                        deedController = this,
-                       valid, fields;
+                       valid, fields, validityPromises;
 
                if ( !this.deedChooser ) {
                        uw.controller.Step.prototype.moveNext.call( this );
@@ -52,11 +52,21 @@
                valid = this.deedChooser.valid();
                if ( valid ) {
                        fields = this.deedChooser.deed.getFields();
-
-                       $.when.apply( $, fields.map( function ( fieldLayout ) {
+                       validityPromises = fields.map( function ( fieldLayout ) 
{
                                // Update any error/warning messages
                                return fieldLayout.checkValidity( true );
-                       } ) ).then( function () {
+                       } );
+                       if ( validityPromises.length === 1 ) {
+                               // validityPromises will hold all promises for 
all uploads;
+                               // adding a bogus promise (no warnings & 
errors) to
+                               // ensure $.when always resolves with an array 
of multiple
+                               // results (if there's just 1, it would 
otherwise have just
+                               // that one's arguments, instead of a 
multi-dimensional array
+                               // of upload warnings & failures)
+                               validityPromises.push( $.Deferred().resolve( 
[], [] ).promise() );
+                       }
+
+                       $.when.apply( $, validityPromises ).then( function () {
                                // `arguments` will be an array of all fields, 
with their warnings & errors
                                // e.g. `[[something], []], [[], [something]]` 
for 2 fields, where the first one has
                                // a warning and the last one an error

-- 
To view, visit https://gerrit.wikimedia.org/r/394593
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1515824acc8a46fcb7378cb07b2762f097eb766
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to