Matthias Mullie has uploaded a new change for review.

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

Change subject: Move logic to display uploads to uw.ui.Upload
......................................................................

Move logic to display uploads to uw.ui.Upload

This has no functional impact and is not really needed.
I just happened to stumble on it while working on something
else, and it looked related. Having so much in mw.UploadWizard.js
is confusing when it can be contained in the relevant UI object.

Change-Id: I981a8d3169b7234e8df9668791983c5dbddac748
---
M resources/mw.UploadWizard.js
M resources/ui/steps/uw.ui.Upload.js
M resources/ui/uw.ui.Step.js
3 files changed, 43 insertions(+), 28 deletions(-)


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

diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index fc27401..e9070c8 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -124,6 +124,7 @@
                        if ( !this.config.tutorial.skip ) {
                                this.steps.tutorial = new 
uw.controller.Tutorial( this.api, this.config );
                        }
+
                        this.steps.file = new uw.controller.Upload( this.api, 
this.config )
                                .on( 'flickr-ui-init', function () {
                                        wizard.flickrInterfaceInit();
@@ -131,8 +132,6 @@
                                } )
 
                                .on( 'load', function () {
-                                       wizard.reset();
-
                                        // Check for iOS 5 Safari's lack of 
file uploads (T34328#364508).
                                        // While this looks extremely unlikely 
to be right, it actually is. Blame Apple.
                                        if ( $( '<input type="file">' ).prop( 
'disabled' ) ) {
@@ -324,40 +323,16 @@
                 */
                addUploads: function ( files ) {
                        var
-                               uploadObj, thumbPromise,
+                               uploadObj,
                                uploadObjs = [],
-                               uploadInterfaceDivs = [],
                                wizard = this;
 
                        $.each( files, function ( i, file ) {
                                uploadObj = wizard.addUpload( file );
                                uploadObjs.push( uploadObj );
-                               // We'll attach all interfaces to the DOM at 
once rather than one-by-one, for better
-                               // performance
-                               uploadInterfaceDivs.push( uploadObj.ui.div );
                        } );
 
-                       // Attach all interfaces to the DOM
-                       $( '#mwe-upwiz-filelist' ).append( $( 
uploadInterfaceDivs ) );
-
-                       // Display thumbnails, but not all at once because 
they're somewhat expensive to generate.
-                       // This will wait for each thumbnail to be complete 
before starting the next one.
-                       thumbPromise = $.Deferred().resolve();
-                       $.each( uploadObjs, function ( i, uploadObj ) {
-                               thumbPromise = thumbPromise.then( function () {
-                                       var deferred = $.Deferred();
-                                       setTimeout( function () {
-                                               if ( 
wizard.steps.file.movedFrom ) {
-                                                       // We're no longer 
displaying any of these thumbnails, stop
-                                                       deferred.reject();
-                                               }
-                                               
uploadObj.ui.showThumbnail().done( function () {
-                                                       deferred.resolve();
-                                               } );
-                                       } );
-                                       return deferred.promise();
-                               } );
-                       } );
+                       this.steps.file.ui.displayUploads( uploadObjs );
 
                        uw.eventFlowLogger.logUploadEvent( 'uploads-added', { 
quantity: files.length } );
                },
diff --git a/resources/ui/steps/uw.ui.Upload.js 
b/resources/ui/steps/uw.ui.Upload.js
index be0b2cf..c16ad28 100644
--- a/resources/ui/steps/uw.ui.Upload.js
+++ b/resources/ui/steps/uw.ui.Upload.js
@@ -291,6 +291,40 @@
                $( '#mwe-upwiz-add-file' ).show();
        };
 
+       uw.ui.Upload.prototype.displayUploads = function ( uploads ) {
+               var
+                       thumbPromise,
+                       uploadInterfaceDivs = [];
+
+               $.each( uploads, function ( i, upload ) {
+                       // We'll attach all interfaces to the DOM at once 
rather than one-by-one, for better
+                       // performance
+                       uploadInterfaceDivs.push( upload.ui.div );
+               } );
+
+               // Attach all interfaces to the DOM
+               this.$fileList.append( $( uploadInterfaceDivs ) );
+
+               // Display thumbnails, but not all at once because they're 
somewhat expensive to generate.
+               // This will wait for each thumbnail to be complete before 
starting the next one.
+               thumbPromise = $.Deferred().resolve();
+               $.each( uploads, function ( i, upload ) {
+                       thumbPromise = thumbPromise.then( function () {
+                               var deferred = $.Deferred();
+                               setTimeout( function () {
+                                       if ( this.movedFrom ) {
+                                               // We're no longer displaying 
any of these thumbnails, stop
+                                               deferred.reject();
+                                       }
+                                       upload.ui.showThumbnail().done( 
function () {
+                                               deferred.resolve();
+                                       } );
+                               } );
+                               return deferred.promise();
+                       } );
+               } );
+       };
+
        uw.ui.Upload.prototype.addNextButton = function () {
                var ui = this;
 
diff --git a/resources/ui/uw.ui.Step.js b/resources/ui/uw.ui.Step.js
index e2b00df..3034f51 100644
--- a/resources/ui/uw.ui.Step.js
+++ b/resources/ui/uw.ui.Step.js
@@ -60,6 +60,8 @@
         * @param {mw.UploadWizardUpload[]} uploads
         */
        uw.ui.Step.prototype.moveTo = function ( uploads ) {
+               this.movedFrom = false;
+
                var offset = $( 'h1:first' ).offset();
 
                this.uploads = uploads;
@@ -76,6 +78,8 @@
         * Move to the next step.
         */
        uw.ui.Step.prototype.moveNext = function () {
+               this.movedFrom = true;
+
                this.$div.children().detach();
        };
 
@@ -83,6 +87,8 @@
         * Move to the previous step.
         */
        uw.ui.Step.prototype.movePrevious = function () {
+               this.movedFrom = true;
+
                this.$div.children().detach();
        };
 

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

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

Reply via email to