Bläddra i källkod

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

Added button reset on modal hide and on not ongoing ajax requests
Enrico Berti 12 år sedan
förälder
incheckning
1432bff2b0
1 ändrade filer med 25 tillägg och 1 borttagningar
  1. 25 1
      desktop/core/src/desktop/templates/common_footer.html

+ 25 - 1
desktop/core/src/desktop/templates/common_footer.html

@@ -36,11 +36,35 @@ limitations under the License.
         // 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 () {
           if (!$(this).hasClass('disabled')) {
-            var text = ($(this).text()) ? $(this).text() : $(this).val();
+            var text = ($(this).text() != "") ? $(this).text() : $(this).val();
             $(this).attr("data-loading-text", text + " ...");
             $(this).button("loading");
+            startPendingRequestsPolling();
           }
         });
+
+        var pendingRequestsInterval = -1;
+
+        function startPendingRequestsPolling() {
+          pendingRequestsInterval = window.setInterval(function () {
+            var activeRequests = 0;
+            if (jQuery.ajax.active) {
+              activeRequests = jQuery.ajax.active;
+            }
+            else {
+              activeRequests = jQuery.active;
+            }
+            if (activeRequests == 0) {
+              $(".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)").button("reset");
+              window.clearInterval(pendingRequestsInterval);
+            }
+          }, 500);
+        }
+
+        $(document).on("hidden", ".modal", function () {
+          $(".btn-primary:not(.disable-feedback), .btn-danger:not(.disable-feedback)").button("reset");
+        });
+
       });
     </script>