CADI AAF Integration and merging the code
[portal.git] / ecomp-portal-widget-ms / widget-ms / src / main / resources / templates / Upload.html
index a5e7c63..01e0564 100644 (file)
@@ -1,12 +1,45 @@
 <html>
+<script>
+var validFileExtensions = [".zip"];    
+function validateInput(form) {
+    var arrInputs = form.getElementsByTagName("input");
+    for (var i = 0; i < arrInputs.length; i++) {
+        var oInput = arrInputs[i];
+        if (oInput.type == "file") {
+            var fileName = oInput.value;
+            if (fileName.length > 0) {
+                var valid = false;
+                for (var j = 0; j < validFileExtensions.length; j++) {
+                    var inputExtension = validFileExtensions[j];
+                    if (fileName.substr(fileName.length - inputExtension.length, inputExtension.length).toLowerCase() == inputExtension.toLowerCase()) {
+                        valid = true;
+                        break;
+                    }
+                }
+                if (!valid) {
+                       document.getElementById("error").style.display="";
+                       setTimeout(function(){ document.getElementById("error").style.display="none";}, 3000);
+                    return false;
+                }
+            }
+        }
+    }
+  
+    return true;
+}
+</script>
 <body>
     <div align="center">
-         <form method="post" action="doUpload/widget-resources" enctype="multipart/form-data">
+         <form method="post" action="doUpload/widget-resources" onSubmit="return validateInput(this);" enctype="multipart/form-data">
             <table border="0">
                 <tr>
                     <td>Pick file:</td>
                     <td><input type="file" name="fileUpload" size="50" /></td>
                 </tr>
+                <tr colspan="2">
+                    <td><span  style="display:none;color:red" id="error">File must be zip.</span></td>
+                    
+                </tr>
                 <tr>
                     <td colspan="2" align="center"><input type="submit" value="Upload" /></td>
                 </tr>