From 304aeac0ff1c44cfc4a8bfc7df1ebb154a579262 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 19 2016 08:21:33 +0000 Subject: [PATCH 1/2] Ensure we disable all the submit button when clicking on one This should ensure comments are only submitting ones, not more. Fixes https://pagure.io/pagure/issue/1407 --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 784bae6..9e0ce8b 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -580,13 +580,24 @@ source.addEventListener('message', function(e) { }, false); {% if authenticated and form %} +function set_ui_for_comment(setting){ + console.log(setting) + if (setting == false) { + $(document.body).find('input[type="submit"]').removeAttr("disabled"); + document.body.style.cursor = 'default'; + } else { + $(document.body).find('input[type="submit"]').attr("disabled", "disabled"); + document.body.style.cursor = 'wait'; + } +} function try_async_comment(form) { console.log(form) - $(form).find('input[type="submit"]').attr("disabled", "disabled"); + set_ui_for_comment(true); var _data = $(form).serialize(); var btn = $(document.activeElement); if (btn[0].name == 'drop_comment'){ _data += '&drop_comment=' + btn[0].value; + set_ui_for_comment(false); return true; } if (!sse) { @@ -611,6 +622,7 @@ function try_async_comment(form) { $( ".issue-metadata-display" ).show(); $( ".issue-custom-form" ).hide(); $( ".issue-custom-display" ).show(); + set_ui_for_comment(false); } else { // Make the browser submit the form sync $(form).off('submit'); @@ -622,7 +634,6 @@ function try_async_comment(form) { $(form).off('submit'); form.submit(); }) - $(form).find('input[type="submit"]').removeAttr("disabled"); return false; }; {% endif %} From d5bca2819e3238543e7abdc11f8aa0d45aec368d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 19 2016 08:21:33 +0000 Subject: [PATCH 2/2] Adjust the pull-request template/page to prevent sending two comments --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index daf7865..9d6c89f 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -1113,13 +1113,24 @@ $('#assignee').selectize({ } ); +function set_ui_for_comment(setting){ + console.log(setting) + if (setting == false) { + $(document.body).find('input[type="submit"]').removeAttr("disabled"); + document.body.style.cursor = 'default'; + } else { + $(document.body).find('input[type="submit"]').attr("disabled", "disabled"); + document.body.style.cursor = 'wait'; + } +} + function try_async_comment(form, inline) { - $(form).off('submit'); - $(form).find('input[type="submit"]').attr("disabled", "disabled"); + set_ui_for_comment(true); var _data = $(form).serialize(); var btn = $(document.activeElement); if (btn[0].name == 'drop_comment'){ _data += '&drop_comment=' + btn[0].value; + set_ui_for_comment(false); return true; } if (!sse) { @@ -1148,6 +1159,7 @@ function try_async_comment(form, inline) { $(item.parent().children()[1]).show() } item.remove(); + set_ui_for_comment(false); } else { // Make the browser submit the form sync form.submit(); @@ -1157,8 +1169,6 @@ function try_async_comment(form, inline) { // Make the browser submit the form sync form.submit(); }) - $(form).on('submit'); - $(form).find('input[type="submit"]').removeAttr("disabled"); return false; }; {% endif %}