Commit a4688911 authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: prevent submitting comment twice [WIP]

parent ce1eb93d
...@@ -218,8 +218,11 @@ ...@@ -218,8 +218,11 @@
submitButton = gadget.element.querySelector("input[type=submit]"); submitButton = gadget.element.querySelector("input[type=submit]");
submitButton.disabled = true; submitButton.disabled = true;
submitButton.classList.add("ui-disabled");
function enableSubmitButton() { function enableSubmitButton() {
submitButton.disabled = false; submitButton.disabled = false;
submitButton.classList.remove("ui-disabled");
} }
queue = gadget.notifySubmitted({message: "Posting comment"}) queue = gadget.notifySubmitted({message: "Posting comment"})
.push(function () { .push(function () {
...@@ -231,6 +234,10 @@ ...@@ -231,6 +234,10 @@
data.append("predecessor", ''); data.append("predecessor", '');
data.append("data", content.comment); data.append("data", content.comment);
data.append("file", file_blob); data.append("file", file_blob);
// reset the file upload, otherwise next comment would upload same file again
choose_file_html_element.value = "";
  • HTML5 spec for file input says

    The value IDL attribute is in mode filename.

    which means:

    .. On setting, if the new value is the empty string, empty the list of selected files; ...

    so it should be OK, but I'm a bit worried that some browser may cause a security error if we change the value of a file input

Please register or sign in to reply
// XXX: Hack, call jIO.util.ajax directly to pass the file blob // XXX: Hack, call jIO.util.ajax directly to pass the file blob
// Because the jio_putAttachment will call readBlobAsText, which // Because the jio_putAttachment will call readBlobAsText, which
// will broke the binary file. Call the jIO.util.ajax directly // will broke the binary file. Call the jIO.util.ajax directly
...@@ -248,12 +255,17 @@ ...@@ -248,12 +255,17 @@
return gadget.notifySubmitted({message: "Comment added", status: "success"}); return gadget.notifySubmitted({message: "Comment added", status: "success"});
}) })
.push(function () { .push(function () {
editor.changeState({value: ''}) // XXX workaround ... because previous state before user start typing was ""
.push(function () { // we first set to "something" to be able to reset to nothing later.
return gadget.redirect({command: 'reload'}); return editor.changeState({value: ' '});
}); })
}); .push(function () {
queue.push(enableSubmitButton, enableSubmitButton); return editor.changeState({value: ''});
  • I wish this was not necessary. If I understood correctly, the value state of the editor is set to "" on initialization and then never changed, in editor gadget, we don't do anything like

    editor.on("change", function() {
      gadget.changeState({
         value: editor.value
       })})

    so the state of the gadget is always empty string, so this changeState({value: ''}) was always resolving immediately, so user was able to submit again the same content.

    @romain if you understand this and you have comment, it would be appreciated.

  • @jerome the value state parameter is modified by ckeditor getContent method. As the editor gadget always calls ckeditor render, I don't see why your change is needed for now.

  • Thanks ! ... so it's should not be needed.

    My guess is that it's because ckeditor gadget modifies its state, but it's wrapped in an editor gadget whose state is not modified on getContent. I'll investigate this more and I'll let you know.

Please register or sign in to reply
})
.push(function () {
return gadget.redirect({command: 'reload'});
})
.push(enableSubmitButton, enableSubmitButton);
return queue; return queue;
}); });
}) })
......
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1539939405.65</float> <float>1539946621.33</float>
<string>GMT+9</string> <string>GMT+9</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment