Commit 486f9bb1 authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: prevent submitting comment twice

parent 73096e57
......@@ -204,11 +204,10 @@
.declareJob('submitPostComment', function () {
var gadget = this,
submitButton = null,
queue = null,
editor = null;
queue = null;
return gadget.getDeclaredGadget("editor")
.push(function (e) {
editor = e;
return e.getContent();
})
.push(function (content) {
......@@ -218,8 +217,11 @@
submitButton = gadget.element.querySelector("input[type=submit]");
submitButton.disabled = true;
submitButton.classList.add("ui-disabled");
function enableSubmitButton() {
submitButton.disabled = false;
submitButton.classList.remove("ui-disabled");
}
queue = gadget.notifySubmitted({message: "Posting comment"})
.push(function () {
......@@ -231,6 +233,10 @@
data.append("predecessor", '');
data.append("data", content.comment);
data.append("file", file_blob);
// reset the file upload, otherwise next comment would upload same file again
choose_file_html_element.value = "";
// XXX: Hack, call jIO.util.ajax directly to pass the file blob
// Because the jio_putAttachment will call readBlobAsText, which
// will broke the binary file. Call the jIO.util.ajax directly
......@@ -245,15 +251,15 @@
});
})
.push(function () {
return gadget.notifySubmitted({message: "Comment added", status: "success"});
})
.push(function () {
editor.changeState({value: ''})
.push(function () {
return new RSVP.Queue().push(function () {
gadget.notifySubmitted({message: "Comment added", status: "success"});
}).push(function () {
return gadget.redirect({command: 'reload'});
});
}, function (e) {
enableSubmitButton();
return gadget.notifySubmitted({message: "Error:" + e, status: "error"});
});
queue.push(enableSubmitButton, enableSubmitButton);
return queue;
});
})
......@@ -266,6 +272,6 @@
);
}, 5000)
.onEvent('submit', function () {
this.submitPostComment();
return this.submitPostComment();
});
}(window, rJS, RSVP, calculatePageTitle, moment, Handlebars));
\ No newline at end of file
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1539939405.65</float>
<float>1539946621.33</float>
<string>GMT+9</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testDoubleSubmitComment</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html>
<head>
<title tal:content="template/title_or_id">The title</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Support Request Zuite</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_SupportRequestUITemplate/macros/init" />
<tr>
<td>open</td>
<td>${base_url}/web_site_module/erp5_officejs_support_request_ui/</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@data-i18n='[value]Submit New Support Request']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[@data-i18n='[value]Submit New Support Request']</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@data-i18n="[value]Proceed"]</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>//input[@name='field_your_title']</td>
<td>test</td>
</tr>
<tr>
<td>select</td>
<td>field_your_project</td>
<td>RobotMaking</td>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>FeatureRequire</td>
<td></td>
</tr>
<tr>
<td>select</td>
<td>field_your_resource</td>
<td>FeatureRequire</td>
</tr>
<tal:block tal:define="text_content string:First Post Content">
<tal:block metal:use-macro="container/Zuite_CommonTemplateForRenderjsUi/macros/type_ckeditor_text_content"/>
</tal:block>
<tr>
<td>waitForElementPresent</td>
<td>//input[@data-i18n='[value]Proceed']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[@data-i18n='[value]Proceed']</td>
<td></td>
</tr>
<tr>
<td>waitForText</td>
<td>//ol[@id="post_list"]//li[1]/p</td>
<td>First Post Content</td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@data-i18n="[value]Post Comment"]</td>
<td></td>
</tr>
<tal:block tal:define="text_content string:Second Post Content">
<tal:block metal:use-macro="container/Zuite_CommonTemplateForRenderjsUi/macros/type_ckeditor_text_content"/>
</tal:block>
<tr>
<td>click</td>
<td>//input[@data-i18n='[value]Post Comment']</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@data-i18n='[value]Post Comment' and @disabled and contains(@class, "ui-disabled")]</td>
<td></td>
</tr>
<tal:block tal:define="notification_configuration python: {'class': 'success',
'text': 'Comment added'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
<tr>
<td>click</td>
<td>//input[@data-i18n='[value]Post Comment']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[@data-i18n='[value]Post Comment']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//input[@data-i18n='[value]Post Comment']</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{selenium.browserbot.getCurrentWindow().location.href}</td>
<td>current_location</td>
</tr>
<tr>
<td>open</td>
<td tal:content="string:${here/portal_url}/Zuite_waitForActivities"/>
<td/>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>Done.</td>
<td/>
</tr>
<tr>
<td>open</td>
<td>${current_location}</td>
<td></td>
</tr>
<!-- The second post was submitted only once. -->
<tr>
<td>waitForText</td>
<td>//ol[@id="post_list"]//li[1]/p</td>
<td>First Post Content</td>
</tr>
<tr>
<td>waitForText</td>
<td>//ol[@id="post_list"]//li[2]/p</td>
<td>Second Post Content</td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>//ol[@id="post_list"]//li[3]/p</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
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