[Libreoffice-commits] .: bug/bug

Loic Dachary loic at kemper.freedesktop.org
Thu Sep 29 02:15:48 PDT 2011


 bug/bug/bug.js  |    6 ++++++
 bug/bug/test.js |    5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

New commits:
commit 07706f06bf47fde2dce9b853583afa3b577f00a5
Author: Loic Dachary <loic at dachary.org>
Date:   Thu Sep 29 11:15:38 2011 +0200

    Prevent double submission of the form.
      https://freedesktop.dachary.org/show_bug.cgi?id=41269
      https://freedesktop.dachary.org/show_bug.cgi?id=41270
    are most likely examples of what happens when the form is submitted twice because of a double click.

diff --git a/bug/bug/bug.js b/bug/bug/bug.js
index d391adb..3429bcf 100644
--- a/bug/bug/bug.js
+++ b/bug/bug/bug.js
@@ -179,6 +179,11 @@
             var element = $('.state_submit');
             if(!element.hasClass('initialized')) {
                 $('.go', element).click(function() {
+                    if($(element).hasClass('inprogress')) {
+                        return;
+                    } else {
+                        $(element).addClass('inprogress');
+                    }
                     var version = $('.state_version .chosen').attr('data');
                     var component = $('.state_component .chosen').attr('data').replace('_',' ');
                     var short_desc = $('.state_subcomponent .active_subcomponent .chosen').attr('data') + ': ' + $('.state_description .short').val();
@@ -199,6 +204,7 @@
                         comment: comment,
                         status_whiteboard: 'BSA'
                     }).pipe(function(data) {
+                        $(element).removeClass('inprogress');
                         $("body").css("cursor", "default");
                         return $.bug.lookup_result(data,
                                                    $.bug.state_submit_error_regexps,
diff --git a/bug/bug/test.js b/bug/bug/test.js
index 55db48c..56f0ddb 100644
--- a/bug/bug/test.js
+++ b/bug/bug/test.js
@@ -200,7 +200,7 @@ test("state_description", function() {
 });
 
 test("state_submit", function() {
-    expect(14);
+    expect(16);
 
     var state_success = $.bug.state_success;
     $.bug.state_success = function() { ok(true, 'state_success'); };
@@ -226,6 +226,8 @@ test("state_submit", function() {
     $('.state_description .long').val(comment);
     var bug = '40763';
     $.bug.ajax = function(type, url, data) {
+        ok(element.hasClass('inprogress'), 'is in progress');
+        $('.go', element).click(); // noop
         if(data.component == component_text &&
            data.version == version &&
            data.short_desc == subcomponent + ': ' + short_desc &&
@@ -235,6 +237,7 @@ test("state_submit", function() {
     };
     $('.go', element).click();
     equal($('.bug', element).text(), bug, 'bug number');
+    ok(!element.hasClass('inprogress'), 'is no longer progress');
 
     var error = ' ERROR ';
     equal($('.error').text(), '', 'error is not set');


More information about the Libreoffice-commits mailing list