MarkTraceur has uploaded a new change for review.

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

Change subject: Move showTooManyFilesWarning to the wizard object
......................................................................

Move showTooManyFilesWarning to the wizard object

This was stupid and it made refactoring the upload stuff very difficult

Change-Id: I5357cc9e5bc40528d6f30fd92a5f798194e37b48
---
M resources/mw.UploadWizard.js
M resources/mw.UploadWizardUpload.js
M resources/mw.UploadWizardUploadInterface.js
3 files changed, 57 insertions(+), 42 deletions(-)


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

diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index 6d46417..31f4807 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -401,7 +401,16 @@
                        }
 
                        upload = new mw.UploadWizardUpload( this, 
'#mwe-upwiz-filelist', providedFile )
-                               .on( 'file-changed', function ( files ) {
+                               .on( 'file-changed', function ( upload, files ) 
{
+                                       var totalFiles = files.length + 
wizard.uploads.length,
+                                               tooManyFiles = totalFiles > 
mw.UploadWizard.config.maxUploads;
+
+                                       if ( tooManyFiles ) {
+                                               wizard.showTooManyFilesWarning( 
totalFiles );
+                                               upload.resetFileInput();
+                                               return;
+                                       }
+
                                        uw.eventFlowLogger.logUploadEvent( 
'uploads-added', { quantity: files.length } );
                                } )
 
@@ -430,6 +439,36 @@
                },
 
                /**
+                * Shows an error dialog informing the user that some uploads 
have been omitted
+                * since they went over the max files limit.
+                * @param filesUploaded integer - the number of files that have 
been attempted to upload
+                */
+               showTooManyFilesWarning: function ( filesUploaded ) {
+                       var buttons = [
+                               {
+                                       text: mw.message( 
'mwe-upwiz-too-many-files-ok' ).escaped(),
+                                       click: function () {
+                                               
$(this).dialog('destroy').remove();
+                                       }
+                               }
+                       ];
+                       $( '<div>' )
+                               .msg(
+                                       'mwe-upwiz-too-many-files-text',
+                                       mw.UploadWizard.config.maxUploads,
+                                       filesUploaded
+                               )
+                               .dialog( {
+                                       width: 500,
+                                       zIndex: 200000,
+                                       autoOpen: true,
+                                       title: mw.message( 
'mwe-upwiz-too-many-files' ).escaped(),
+                                       modal: true,
+                                       buttons: buttons
+                               } );
+               },
+
+               /**
                 * When an upload is filled with a real file, accept it in the 
wizard's list of uploads
                 * and set up some other interfaces
                 * @param UploadWizardUpload
diff --git a/resources/mw.UploadWizardUpload.js 
b/resources/mw.UploadWizardUpload.js
index 77e1a1f..20468b3 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -68,7 +68,7 @@
                // details
                this.ui = new mw.UploadWizardUploadInterface( this, filesDiv, 
providedFile )
                        .on( 'file-changed', function ( files ) {
-                               upload.emit( 'file-changed', files );
+                               upload.emit( 'file-changed', upload, files );
                        } )
 
                        .on( 'upload-filled', function () {
@@ -104,6 +104,13 @@
 
        UWUP.acceptDeed = function () {
                this.deed.applyDeed( this );
+       };
+
+       /**
+        * Reset file input.
+        */
+       UWUP.resetFileInput = function () {
+               this.ui.resetFileInput();
        };
 
        /**
@@ -396,8 +403,7 @@
 
                        // Check if filename is acceptable
                        // TODO sanitize filename
-                       basename = this.getBasename( filename ),
-                       tooManyFiles = files.length + 
this.wizard.uploads.length > mw.UploadWizard.config.maxUploads;
+                       basename = this.getBasename( filename );
 
                function finishCallback() {
                        if ( upload && upload.ui ) {
@@ -405,12 +411,6 @@
                        } else {
                                setTimeout( finishCallback, 200 );
                        }
-               }
-
-               if ( tooManyFiles ) {
-                       this.showTooManyFilesWarning( files.length + 
this.wizard.uploads.length );
-                       resetFileInput();
-                       return;
                }
 
                if ( files.length > 1 ) {
@@ -596,36 +596,6 @@
                                zIndex: 200000,
                                autoOpen: true,
                                title: mw.message( 'mwe-upwiz-file-too-large' 
).escaped(),
-                               modal: true,
-                               buttons: buttons
-                       } );
-       };
-
-       /**
-        * Shows an error dialog informing the user that some uploads have been 
omitted
-        * since they went over the max files limit.
-        * @param filesUploaded integer - the number of files that have been 
attempted to upload
-        */
-       UWUP.showTooManyFilesWarning = function ( filesUploaded ) {
-               var buttons = [
-                       {
-                               text: mw.message( 'mwe-upwiz-too-many-files-ok' 
).escaped(),
-                               click: function () {
-                                       $(this).dialog('destroy').remove();
-                               }
-                       }
-               ];
-               $( '<div></div>' )
-                       .msg(
-                               'mwe-upwiz-too-many-files-text',
-                               mw.UploadWizard.config.maxUploads,
-                               filesUploaded
-                       )
-                       .dialog( {
-                               width: 500,
-                               zIndex: 200000,
-                               autoOpen: true,
-                               title: mw.message( 'mwe-upwiz-too-many-files' 
).escaped(),
                                modal: true,
                                buttons: buttons
                        } );
diff --git a/resources/mw.UploadWizardUploadInterface.js 
b/resources/mw.UploadWizardUploadInterface.js
index 01de51d..f8281ac 100644
--- a/resources/mw.UploadWizardUploadInterface.js
+++ b/resources/mw.UploadWizardUploadInterface.js
@@ -286,13 +286,19 @@
                                ui.getFilename(),
                                files,
                                function () { ui.fileChangedOk(); },
-                               function ( code, info ) { ui.fileChangedError( 
code, info ); },
-                               function () { ui.$fileInputCtrl.get(0).value = 
''; }
+                               function ( code, info ) { ui.fileChangedError( 
code, info ); }
                        );
                } );
        };
 
        /**
+        * Reset file input to have no value.
+        */
+       UIP.resetFileInput = function () {
+               this.$fileInputCtrl.get( 0 ).value = '';
+       };
+
+       /**
         * Get a list of the files from this file input, defaulting to the 
value from the input form
         * @return {Array} of File objects
         */

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

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

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

Reply via email to