airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [06/10] airavata-php-gateway git commit: AIRAVATA-1397 Fix client side checking for opt input files
Date Thu, 19 Jan 2017 19:50:39 GMT
AIRAVATA-1397 Fix client side checking for opt input files


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/9e75b854
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/9e75b854
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/9e75b854

Branch: refs/heads/develop
Commit: 9e75b854f6b0f0165f97c5e2095cf8fb5434faa8
Parents: 71f32f4
Author: Marcus Christie <machristie@apache.org>
Authored: Wed Jan 18 16:27:23 2017 -0500
Committer: Marcus Christie <machristie@apache.org>
Committed: Wed Jan 18 16:27:23 2017 -0500

----------------------------------------------------------------------
 app/views/experiment/create-complete.blade.php | 11 +++++----
 app/views/experiment/edit.blade.php            | 11 +++++----
 public/js/util.js                              | 25 ++++++++++++++++++++-
 3 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/9e75b854/app/views/experiment/create-complete.blade.php
----------------------------------------------------------------------
diff --git a/app/views/experiment/create-complete.blade.php b/app/views/experiment/create-complete.blade.php
index 8860df2..7f085ca 100755
--- a/app/views/experiment/create-complete.blade.php
+++ b/app/views/experiment/create-complete.blade.php
@@ -52,6 +52,7 @@
 </script>
 {{ HTML::script('js/sharing/sharing_utils.js') }}
 {{ HTML::script('js/sharing/share.js') }}
+{{ HTML::script('js/util.js') }}
 <script>
     var warn = true;
 
@@ -62,12 +63,14 @@
 
     $('.file-input').bind('change', function () {
 
-        var inputFileSize = Math.round(this.files[0].size / (1024 * 1024));
-        if (inputFileSize > $("#allowedFileSize").val()) {
-            alert("The input file size is greater than the allowed file size (" + $("#allowedFileSize").val()
+ " MB) in a form. Please upload another file.");
+        var allowedFileSize = $("#allowedFileSize").val();
+        var tooLargeFilenames = util.validateMaxUploadFileSize(this.files, allowedFileSize);
+
+        if (tooLargeFilenames.length > 0) {
+            var singleOrMultiple = tooLargeFilenames.length === 1 ? " the file [" : " each
of the files [";
+            alert("The size of " + singleOrMultiple + tooLargeFilenames.join(", ") + "] is
greater than the allowed file size (" + allowedFileSize + " MB) in a form. Please upload another
file.");
             $(this).val("");
         }
-
     });
 
     $("#enableEmail").change(function () {

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/9e75b854/app/views/experiment/edit.blade.php
----------------------------------------------------------------------
diff --git a/app/views/experiment/edit.blade.php b/app/views/experiment/edit.blade.php
index 00fd008..cbefee3 100755
--- a/app/views/experiment/edit.blade.php
+++ b/app/views/experiment/edit.blade.php
@@ -67,15 +67,18 @@
 </script>
 {{ HTML::script('js/sharing/sharing_utils.js') }}
 {{ HTML::script('js/sharing/share.js') }}
+{{ HTML::script('js/util.js') }}
 <script>
     $('.file-input').bind('change', function () {
 
-        var inputFileSize = Math.round(this.files[0].size / (1024 * 1024));
-        if (inputFileSize > $("#allowedFileSize").val()) {
-            alert("The input file size is greater than the allowed file size (" + $("#allowedFileSize").val()
+ " MB) in a form. Please upload another file.");
+        var allowedFileSize = $("#allowedFileSize").val();
+        var tooLargeFilenames = util.validateMaxUploadFileSize(this.files, allowedFileSize);
+
+        if (tooLargeFilenames.length > 0) {
+            var singleOrMultiple = tooLargeFilenames.length === 1 ? " the file [" : " each
of the files [";
+            alert("The size of " + singleOrMultiple + tooLargeFilenames.join(", ") + "] is
greater than the allowed file size (" + allowedFileSize + " MB) in a form. Please upload another
file.");
             $(this).val("");
         }
-
     });
 
     $("#enableEmail").change(function () {

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/9e75b854/public/js/util.js
----------------------------------------------------------------------
diff --git a/public/js/util.js b/public/js/util.js
index c5cbb24..0b7d1e6 100644
--- a/public/js/util.js
+++ b/public/js/util.js
@@ -1,12 +1,35 @@
 
 var util = (function(){
     "use strict";
-    
+
     return {
         sanitizeHTMLId: function(id) {
             // Replace anything that isn't an HTML safe id character with underscore
             // Here safe means allowable by HTML5 and also safe to use in a jQuery selector
             return id.replace(/[^a-zA-Z0-9_-]/g, "_");
+        },
+
+        /**
+         * Return a list of filenames that exceed the given maxUploadFileSize.
+         *
+         * @param fileList is of type FileList
+         * @param maxUploadFileSize is a number of megabytes
+         * @return Array of string filenames. Array is empty if none of the
+         * files exceed the given maxUploadFileSize.
+         */
+        validateMaxUploadFileSize: function(fileList, maxUploadFileSize) {
+
+            var tooLargeFilenames = [];
+            for (var i=0; i < fileList.length; i++) {
+
+                var file = fileList[i];
+                var inputFileSize = file.size / (1024 * 1024);
+                if (inputFileSize > maxUploadFileSize) {
+                    tooLargeFilenames.push(file.name);
+                }
+            }
+
+            return tooLargeFilenames;
         }
     };
 })();
\ No newline at end of file


Mime
View raw message