Commit 3bc2302e authored by Tomáš Peterka's avatar Tomáš Peterka

[renderjs_ui+json] Dialog form handles HTTP responses 202-399

parent 5ee63600
......@@ -6,6 +6,7 @@
data-i18n=Document was not saved! Resubmit when you are online or the document accessible
data-i18n=Encountered an unknown error. Try to resubmit
data-i18n=Data received
data-i18n=Action succeeded
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.56020.52206.40328</string> </value>
<value> <string>962.14191.38290.31931</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1505912615.0</float>
<float>1506093694.63</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -55,7 +55,7 @@
// ignore options.editable because dialog is always editable
erp5_document: options.erp5_document,
form_definition: options.form_definition,
erp5_form: options.erp5_form || {},
erp5_form: options.erp5_form || {}
// ignore global editable state (be always editable)
});
})
......@@ -153,7 +153,8 @@
if (attachment.target.responseType !== "blob") {
attachment_data = new Blob(
[attachment.target.response],
{type: attachment.target.getResponseHeader("Content-Type")});
{type: attachment.target.getResponseHeader("Content-Type")}
);
}
a_tag.style = "display: none";
a_tag.href = URL.createObjectURL(attachment_data);
......@@ -227,7 +228,9 @@
// here we figure out where to go after form submit - indicated
// by X-Location HTTP header placed by Base_redirect script
var jio_key = new URI(
attachment.target.getResponseHeader("X-Location")).segment(2);
attachment.target.getResponseHeader("X-Location")
).segment(2);
if (redirect_to_parent) {
return form_gadget.redirect({command: 'history_previous'});
}
......@@ -271,6 +274,35 @@
return form_gadget.displayFormulatorValidationError(JSON.parse(response_text.target.result));
});
}
// response status > 200 (e.g. 202 "Accepted" or 204 "No Content")
// mean sucessful execution of an action but does not carry any data
// XMLHttpRequest automatically inserts Content-Type="text/xml" thus
// we cannot test based on that
if (attachment.target.response.size === 0 &&
attachment.target.status > 200 &&
attachment.target.status < 400) {
return new RSVP.Queue()
.push(function () {
return form_gadget.notifySubmitted({
"message": "Action succeeded",
"status": "success"
});
})
.push(function () {
if (redirect_to_parent) {
return form_gadget.redirect({command: 'history_previous'});
}
return form_gadget.redirect({
command: 'change',
options: {
"jio_key": form_gadget.state.jio_key,
"view": "view",
"page": undefined
// do not mingle with editable because it isn't necessary
}
});
});
}
// any other attachment type we force to download because it is most
// likely product of export/report (thus PDF, ODT ...)
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.15391.22775.52445</string> </value>
<value> <string>962.17207.35280.11400</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1506008825.18</float>
<float>1506093724.9</float>
<string>UTC</string>
</tuple>
</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