Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322124

Change subject: Rip reset routine out of controllers
......................................................................

Rip reset routine out of controllers

These controllers should be as much self-contained as possible,
without overarching/shared code to orchestrate things.

However, these controllers shouldn'be be making assumptions about
each other, or about their order. "details" controller shouldn't
assume that he can skip to "file" by passing an empty array to
"thanks", which will in that case also just move along to the next
one, which it knows is "file". There's way to many assumptions
about other things in there. This is likely to break at some point.

If we ever want to make UW, or parts of it, embeddable elsewhere,
these steps may also be different at some point. I can definitely
image a different "thanks" step, for example :)

We already trimmed a lot of fat in mw.UploadWizard and there's still
more left to be moved. However, I think this is one of the very few
acceptable things that actually belong in here.

Change-Id: If69a591f33f5f7d9b7b9deb53607470fbd1c1218
---
M resources/controller/uw.controller.Details.js
M resources/controller/uw.controller.Thanks.js
M resources/mw.UploadWizard.js
3 files changed, 17 insertions(+), 13 deletions(-)


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

diff --git a/resources/controller/uw.controller.Details.js 
b/resources/controller/uw.controller.Details.js
index 2fc12f7..3804004 100644
--- a/resources/controller/uw.controller.Details.js
+++ b/resources/controller/uw.controller.Details.js
@@ -424,10 +424,6 @@
                // copy feature again
                if ( this.config.copyMetadataFeature ) {
                        this.addCopyMetadataFeature( this.uploads );
-               } 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 load() because there are 
no uploads left.)
-                       this.moveNext();
                }
        };
 
diff --git a/resources/controller/uw.controller.Thanks.js 
b/resources/controller/uw.controller.Thanks.js
index 7ed402f..09f583b 100644
--- a/resources/controller/uw.controller.Thanks.js
+++ b/resources/controller/uw.controller.Thanks.js
@@ -40,12 +40,6 @@
        uw.controller.Thanks.prototype.load = function ( uploads ) {
                var thanks = this;
 
-               if ( uploads.length === 0 ) {
-                       // We got here after the user removed all uploads; just 
restart from "Upload" step
-                       this.moveNext();
-                       return;
-               }
-
                uw.controller.Step.prototype.load.call( this, uploads );
 
                $.each( uploads, function ( i, upload ) {
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index 20ea5ea..2e3c31c 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -59,8 +59,19 @@
                 * Resets wizard state and moves to the file step.
                 */
                bailAndloadFile: function () {
+                       // if we're already in the file step, there's nothing 
to be done
+                       // (or we'd end up in an endless recursion)
+                       if ( this.currentStep === 'file' ) {
+                               return;
+                       }
+
                        // destroy the flickr interface if it exists
                        this.flickrInterfaceDestroy();
+
+                       if ( this.currentStep ) {
+                               this.steps[ this.currentStep ].unload();
+                       }
+                       this.steps.file.load( [] );
                },
 
                /**
@@ -72,7 +83,7 @@
                        this.initialiseSteps();
 
                        // "select" the first step - highlight, make it 
visible, hide all others
-                       this.steps.firstStep.load( [] );
+                       this.firstStep.load( [] );
                },
 
                /**
@@ -96,13 +107,16 @@
                        this.steps.thanks = new uw.controller.Thanks( this.api, 
this.config );
 
                        if ( skipTutorial ) {
-                               this.steps.firstStep = this.steps.file;
+                               this.firstStep = this.steps.file;
                        } else {
-                               this.steps.firstStep = this.steps.tutorial;
+                               this.firstStep = this.steps.tutorial;
                        }
 
                        $.each( this.steps, function ( name, step ) {
                                step
+                                       .on( 'load', function () {
+                                               wizard.currentStep = name;
+                                       } )
                                        .on( 'no-uploads', function () {
                                                wizard.bailAndloadFile();
                                        } );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If69a591f33f5f7d9b7b9deb53607470fbd1c1218
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