jenkins-bot has submitted this change and it was merged.

Change subject: Move detailsValid to details step controller
......................................................................


Move detailsValid to details step controller

Further independence from the main UW object.

Bug: T78057
Change-Id: I5acd0fa1f97e5e2664eb32269fdbeaea2817e040
---
M resources/controller/uw.controller.Details.js
M resources/mw.UploadWizard.js
2 files changed, 95 insertions(+), 79 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/controller/uw.controller.Details.js 
b/resources/controller/uw.controller.Details.js
index c985c25..5d76b57 100644
--- a/resources/controller/uw.controller.Details.js
+++ b/resources/controller/uw.controller.Details.js
@@ -29,7 +29,7 @@
                        this,
                        new uw.ui.Details()
                                .connect( this, {
-                                       'start-details': [ 'emit', 
'start-details' ],
+                                       'start-details': 'startDetails',
                                        'finalize-details-after-removal': [ 
'emit', 'start-details' ]
                                } )
                );
@@ -76,12 +76,99 @@
                        }
                } );
 
-               uw.controller.Step.prototype.moveTo.call( this );
+               uw.controller.Step.prototype.moveTo.call( this, uploads );
        };
 
        DP.empty = function () {
                this.ui.empty();
        };
 
+       /**
+        * Start details submit.
+        * @TODO move the rest of the logic here from mw.UploadWizard
+        */
+       DP.startDetails = function () {
+               var details = this;
+
+               this.valid().done( function () {
+                       details.ui.hideEndButtons();
+                       details.emit( 'start-details' );
+               } ).fail( function () {
+                       details.emit( 'details-error' );
+               } );
+       };
+
+       /**
+        * Check details for validity.
+        * @return {jQuery.Promise}
+        */
+       DP.valid = function () {
+               var confirmationDialog, title,
+                       d = $.Deferred(),
+                       valid = 0,
+                       necessary = 0,
+                       total = 0,
+                       buttons = {},
+                       titles = {};
+
+               $.each( this.uploads, function ( i, upload ) {
+                       if ( upload === undefined ) {
+                               return;
+                       }
+                       total += 1;
+
+                       upload.details.clearDuplicateTitleError().valid( 
function () {
+                               title = upload.title.getName();
+
+                               // Seen this title before?
+                               if ( titles[title] ) {
+
+                                       // Don't submit. Instead, set an error 
in details step.
+                                       upload.details.setDuplicateTitleError();
+                                       return;
+                               } else {
+                                       titles[title] = true;
+                               }
+                               valid += 1;
+                       } );
+                       upload.details.necessaryFilled( function () {
+                               necessary += 1;
+                       } );
+               } );
+
+               // Set up buttons for dialog box. We have to do it the hard way 
since the json keys are localized
+               buttons[ mw.message( 'mwe-upwiz-dialog-yes' ).escaped() ] = 
function () {
+                       $( this ).dialog( 'close' );
+                       d.resolve();
+               };
+               buttons[ mw.message( 'mwe-upwiz-dialog-no' ).escaped() ] = 
function () {
+                       $( this ).dialog( 'close' );
+               };
+               confirmationDialog = $( '<div></div>' )
+                       .text( mw.message( 'mwe-upwiz-necessary-confirm' 
).text() )
+                       .dialog( {
+                               width: 500,
+                               zIndex: 200000,
+                               autoOpen: false,
+                               modal: true,
+                               buttons: buttons,
+                               title: mw.message( 'mwe-upwiz-dialog-title' 
).escaped(),
+                               open: function () {
+                                       $( this ).siblings( 
'.ui-dialog-buttonpane' ).find( 'button:eq(1)' ).focus();
+                               }
+                       } );
+
+               if ( valid === total ) {
+                       if ( necessary === total ) {
+                               return d.resolve();
+                       } else {
+                               confirmationDialog.dialog( 'open' );
+                               return d.promise();
+                       }
+               } else {
+                       return d.reject();
+               }
+       };
+
        uw.controller.Details = Details;
 }( mediaWiki.uploadWizard, jQuery, OO ) );
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index b7a5799..b6e0cda 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -65,15 +65,14 @@
 
                        details: new uw.controller.Details()
                                .on( 'start-details', function () {
-                                       wizard.detailsValid( function () {
-                                               
wizard.steps.details.ui.hideEndButtons();
-                                               wizard.detailsSubmit( function 
() {
-                                                       
wizard.detailsErrorCount();
-                                                       wizard.showNext( 
'details', 'complete', finalizeDetails );
-                                               } );
-                                       }, function () {
+                                       wizard.detailsSubmit( function () {
                                                wizard.detailsErrorCount();
+                                               wizard.showNext( 'details', 
'complete', finalizeDetails );
                                        } );
+                               } )
+
+                               .on( 'details-error', function () {
+                                       wizard.detailsErrorCount();
                                } )
 
                                .on( 'finalize-details-after-removal', function 
() {
@@ -850,76 +849,6 @@
                                this.moveToStep( 'file' );
 
                                this.progressBar = undefined;
-                       }
-               },
-
-               /**
-                * are all the details valid?
-                * @return boolean
-                */
-               detailsValid: function (cb, cberr) {
-                       var confirmationDialog, title,
-                               valid = 0,
-                               necessary = 0,
-                               total = 0,
-                               buttons = {},
-                               titles = {};
-
-                       $.each( this.uploads, function (i, upload) {
-                               if ( upload === undefined ) {
-                                       return;
-                               }
-                               total += 1;
-
-                               
upload.details.clearDuplicateTitleError().valid( function () {
-                                       title = upload.title.getName();
-
-                                       // Seen this title before?
-                                       if ( titles[title] ) {
-
-                                               // Don't submit. Instead, set 
an error in details step.
-                                               
upload.details.setDuplicateTitleError();
-                                               return;
-                                       } else {
-                                               titles[title] = true;
-                                       }
-                                       valid += 1;
-                               } );
-                               upload.details.necessaryFilled( function () {
-                                       necessary += 1;
-                               } );
-                       } );
-
-                       // Set up buttons for dialog box. We have to do it the 
hard way since the json keys are localized
-                       buttons[ mw.message( 'mwe-upwiz-dialog-yes' ).escaped() 
] = function () {
-                               $( this ).dialog( 'close' );
-                               cb();
-                       };
-                       buttons[ mw.message( 'mwe-upwiz-dialog-no' ).escaped() 
] = function () {
-                               $( this ).dialog( 'close' );
-                       };
-                       confirmationDialog = $( '<div></div>' )
-                               .text( mw.message( 
'mwe-upwiz-necessary-confirm' ).text() )
-                               .dialog( {
-                                       width: 500,
-                                       zIndex: 200000,
-                                       autoOpen: false,
-                                       modal: true,
-                                       buttons: buttons,
-                                       title: mw.message( 
'mwe-upwiz-dialog-title' ).escaped(),
-                                       open: function () {
-                                               $( this ).siblings( 
'.ui-dialog-buttonpane' ).find( 'button:eq(1)' ).focus();
-                                       }
-                               } );
-
-                       if ( valid === total ) {
-                               if ( necessary === total ) {
-                                       cb();
-                               } else {
-                                       confirmationDialog.dialog( 'open' );
-                               }
-                       } else {
-                               cberr();
                        }
                },
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5acd0fa1f97e5e2664eb32269fdbeaea2817e040
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to