]> source.dussan.org Git - gitea.git/commitdiff
prevent double click new issue/pull/comment button (#16157)
authora1012112796 <1012112796@qq.com>
Sat, 7 May 2022 12:24:02 +0000 (20:24 +0800)
committerGitHub <noreply@github.com>
Sat, 7 May 2022 12:24:02 +0000 (14:24 +0200)
* prevent double click new issue/pull/comment button

when network is not good, these button maybe
double clicked, then more than one same issues
pulls or comments will be created. this pull
request will fix this bug.

Signed-off-by: a1012112796 <1012112796@qq.com>
templates/repo/issue/new_form.tmpl
templates/repo/issue/view_content.tmpl
web_src/js/features/common-global.js

index 9a4548643fb991d0f11421fa91bb19d2ba894cc1..9e6a69f71a2559c8b47fda5b7ee1fc80fbf49e0d 100644 (file)
@@ -20,7 +20,7 @@
                                        </div>
                                        {{template "repo/issue/comment_tab" .}}
                                        <div class="text right">
-                                               <button class="ui green button" tabindex="6">
+                                               <button class="ui green button loading-button" tabindex="6">
                                                        {{if .PageIsComparePull}}
                                                                {{.i18n.Tr "repo.pulls.create"}}
                                                        {{else}}
index b5f838e9d0aa44c987d591507dc3d778a998da0a..91af5160b6dc8d00748683344ad3f0948e75c441 100644 (file)
                                                                                        </div>
                                                                                {{end}}
                                                                        {{end}}
-                                                                       <button class="ui green button" tabindex="5">
+                                                                       <button class="ui green button loading-button" tabindex="5">
                                                                                {{.i18n.Tr "repo.issues.create_comment"}}
                                                                        </button>
                                                                </div>
                                                                                                </div>
                                                                                        {{end}}
                                                                                {{end}}
-                                                                               <button class="ui green button" tabindex="5">
+                                                                               <button class="ui green button loading-button" tabindex="5">
                                                                                        {{.i18n.Tr "repo.issues.create_comment"}}
                                                                                </button>
                                                                        </div>
index dda803ae8de313798c4f07ecf716aa784ba3740c..eb21a4bb9313ae3ff2d303dd4cb3bdb6f304bfe0 100644 (file)
@@ -142,6 +142,18 @@ export function initGlobalCommon() {
       window.location = href;
     }
   });
+
+  // loading-button this logic used to prevent push one form more than one time
+  $(document).on('click', '.button.loading-button', function (e) {
+    const $btn = $(this);
+
+    if ($btn.hasClass('loading')) {
+      e.preventDefault();
+      return false;
+    }
+
+    $btn.addClass('loading disabled');
+  });
 }
 
 export function initGlobalDropzone() {