Browse Source

HUE-1047 [core] Invalid form submission blocks next submission

All the use cases are now covered. From now on when a form submit event is intercepted by jQuery and canceled we need to call the globally available resetPrimaryButtonsStatus() function.
Enrico Berti 12 years ago
parent
commit
21acdd0

+ 27 - 27
apps/filebrowser/src/filebrowser/templates/edit.mako

@@ -84,36 +84,36 @@ ${ commonheader(_('%(filename)s - File Viewer') % dict(filename=truncate(filenam
     </form>
 </div>
 
-<script type="text/javascript" charset="utf-8">
-	$(document).ready(function(){
-		$("#saveAsBtn").click(function(){
-			$("#saveAsModal").modal({
-				backdrop: "static",
-				keyboard: true,
-				show: true
-			})
-		});
+  <script type="text/javascript" charset="utf-8">
+    $(document).ready(function () {
+      $("#saveAsBtn").click(function () {
+        $("#saveAsModal").modal({
+          backdrop: "static",
+          keyboard: true,
+          show: true
+        })
+      });
 
+      $("#cancelSaveAsBtn").click(function () {
+        $("#saveAsModal").modal("hide");
+      });
 
-		$("#cancelSaveAsBtn").click(function(){
-			$("#saveAsModal").modal("hide");
-		});
+      $("#saveAsForm").submit(function () {
+        if ($.trim($("#saveAsForm").find("input[name='path']").val()) == "") {
+          $("#saveAsForm").find("input[name='path']").addClass("fieldError");
+          $("#saveAsNameRequiredAlert").show();
+          resetPrimaryButtonsStatus(); //globally available
+          return false;
+        }
+        return true;
+      });
 
-		$("#saveAsForm").submit(function() {
-			if ($.trim($("#saveAsForm").find("input[name='path']").val()) == ""){
-				$("#saveAsForm").find("input[name='path']").addClass("fieldError");
-				$("#saveAsNameRequiredAlert").show();
-				return false;
-			}
-			return true;
-		});
-
-		$("#saveAsForm").find("input[name='path']").focus(function(){
-			$(this).removeClass("fieldError");
-			$("#saveAsNameRequiredAlert").hide();
-		});
-	});
-</script>
+      $("#saveAsForm").find("input[name='path']").focus(function () {
+        $(this).removeClass("fieldError");
+        $("#saveAsNameRequiredAlert").hide();
+      });
+    });
+  </script>
 
 ${ commonfooter(messages) | n,unicode }
 

+ 13 - 1
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -506,11 +506,13 @@ from django.utils.translation import ugettext as _
         if ($("#chownForm select[name='user']").val() == null) {
           $("#chownRequired").find(".label").text("${_('User is required.')}");
           $("#chownRequired").show();
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         else if ($("#chownForm select[name='group']").val() == null) {
           $("#chownRequired").find(".label").text("${_('Group is required.')}");
           $("#chownRequired").show();
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         else {
@@ -518,6 +520,7 @@ from django.utils.translation import ugettext as _
             $("#chownRequired").find(".label").text("${_('Specify another group.')}");
             $("#chownForm input[name='group_other']").addClass("fieldError");
             $("#chownRequired").show();
+            resetPrimaryButtonsStatus(); //globally available
             return false;
           }
           if ($("#chownForm select[name='user']").val() == "__other__" && $("input[name='user_other']").val() == "") {
@@ -525,6 +528,7 @@ from django.utils.translation import ugettext as _
             $("#chownForm input[name='user_other']").addClass("fieldError");
             $("#chownRequired").show();
             return false;
+            resetPrimaryButtonsStatus(); //globally available
           }
           return true;
         }
@@ -534,12 +538,14 @@ from django.utils.translation import ugettext as _
         if ($("#newNameInput").val() == "") {
           $("#renameNameRequiredAlert").show();
           $("#newNameInput").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         if (fileExists($("#newNameInput").val())) {
           $("#renameNameExistsAlert").find(".newName").text($("#newNameInput").val());
           $("#renameNameExistsAlert").show();
           $("#newNameInput").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         return true;
@@ -555,6 +561,7 @@ from django.utils.translation import ugettext as _
         if ($.trim($("#moveForm").find("input.pathChooser").val()) == "") {
           $("#moveNameRequiredAlert").show();
           $("#moveForm").find("input[name='*dest_path']").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         return true;
@@ -569,6 +576,7 @@ from django.utils.translation import ugettext as _
         if ($.trim($("#copyForm").find("input.pathChooser").val()) == "") {
           $("#copyNameRequiredAlert").show();
           $("#copyForm").find("input[name='*dest_path']").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         return true;
@@ -576,7 +584,7 @@ from django.utils.translation import ugettext as _
 
       $("#copyForm").find("input[name='dest_path']").on("focus", function () {
         $("#copyNameRequiredAlert").hide();
-        $("#copyForm").find("input[name='dest_path']").recopyClass("fieldError");
+        $("#copyForm").find("input[name='dest_path']").removeClass("fieldError");
       });
 
       $(".create-directory-link").click(function () {
@@ -597,12 +605,14 @@ from django.utils.translation import ugettext as _
         if ($.trim($("#newDirectoryNameInput").val()) == "") {
           $("#directoryNameRequiredAlert").show();
           $("#newDirectoryNameInput").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         if (fileExists($("#newDirectoryNameInput").val())) {
           $("#directoryNameExistsAlert").find(".newName").text($("#newDirectoryNameInput").val());
           $("#directoryNameExistsAlert").show();
           $("#newDirectoryNameInput").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         return true;
@@ -619,12 +629,14 @@ from django.utils.translation import ugettext as _
         if ($.trim($("#newFileNameInput").val()) == "") {
           $("#fileNameRequiredAlert").show();
           $("#newFileNameInput").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         if (fileExists($("#newFileNameInput").val())) {
           $("#fileNameExistsAlert").find(".newName").text($("#newFileNameInput").val());
           $("#fileNameExistsAlert").show();
           $("#newFileNameInput").addClass("fieldError");
+          resetPrimaryButtonsStatus(); //globally available
           return false;
         }
         return true;

+ 43 - 14
desktop/core/src/desktop/templates/common_footer.html

@@ -32,6 +32,10 @@ limitations under the License.
     <script type="text/javascript">
       $(document).ready(function () {
         $(".dataTables_wrapper").jHueTableScroller();
+
+        var resetTimeout = -1;
+        var pendingRequestsInterval = -1;
+
         // sets feedback on every primary and danger action across Hue
         // can be disabled adding the class "disable-feedback" to the button
         $(document).on("click", ".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)", function () {
@@ -40,32 +44,57 @@ limitations under the License.
             $(this).attr("data-loading-text", text + " ...");
             $(this).button("loading");
             startPendingRequestsPolling();
+            resetTimeout = window.setTimeout(function () {
+              resetPrimaryButtonsStatus();
+            }, 100);
           }
         });
 
-        var pendingRequestsInterval = -1;
+        $(document).on("hidden", ".modal", function () {
+          resetPrimaryButtonsStatus();
+        });
+
+        $(window).unload(function () {
+          window.clearInterval(pendingRequestsInterval);
+          window.clearTimeout(resetTimeout);
+        });
+
+        $("form").submit(function () {
+          window.setInterval(function () {
+            window.clearTimeout(resetTimeout);
+          }, 10);
+        });
+
+        var hasAjaxBeenSent = false;
+        $(document).ajaxSend(function () {
+          hasAjaxBeenSent = true;
+        });
 
         function startPendingRequestsPolling() {
           pendingRequestsInterval = window.setInterval(function () {
-            var activeRequests = 0;
-            if (jQuery.ajax.active) {
-              activeRequests = jQuery.ajax.active;
+            if (hasAjaxBeenSent) {
+              var activeRequests = 0;
+              if (jQuery.ajax.active) {
+                activeRequests = jQuery.ajax.active;
+              }
+              else {
+                activeRequests = jQuery.active;
+              }
+              if (activeRequests == 0) {
+                resetPrimaryButtonsStatus();
+                window.clearInterval(pendingRequestsInterval);
+              }
             }
             else {
-              activeRequests = jQuery.active;
-            }
-            if (activeRequests == 0) {
-              $(".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)").button("reset");
               window.clearInterval(pendingRequestsInterval);
             }
-          }, 500);
+          }, 200);
         }
-
-        $(document).on("hidden", ".modal", function () {
-          $(".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)").button("reset");
-        });
-
       });
+
+      function resetPrimaryButtonsStatus() {
+        $(".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)").button("reset");
+      }
     </script>
 
 	</body>