Commit 1c2682f2 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Romain Courteaud

[erp5_web_renderjs_ui] Prevent (dialog) form to crash badly in most cases

parent 30341500
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
<html> <html>
<!-- <!--
data-i18n=Input data has errors data-i18n=Input data has errors
data-i18n=You do not have the permissions to edit the object
data-i18n=Document was not saved! Resubmit when you are online or the document accessible
data-i18n=Encountered an unknown error. Try to resubmit
--> -->
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>957.40660.8707.11059</string> </value> <value> <string>960.5523.58984.43537</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1488277468.66</float> <float>1499432111.39</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -272,24 +272,43 @@ ...@@ -272,24 +272,43 @@
return RSVP.all(list); return RSVP.all(list);
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
if ((error.target !== undefined) && (error.target.status === 400)) { if (error.target !== undefined) {
return form_gadget.notifySubmitted() var error_text = 'Encountered an unknown error. Try to resubmit',
promise;
// if we know what the error was, try to precise it for the user
if (error.target.status === 400) {
error_text = 'Input data has errors';
} else if (error.target.status === 403) {
error_text = 'You do not have the permissions to edit the object';
} else if (error.target.status === 0) {
error_text = 'Document was not saved! Resubmit when you are online or the document accessible';
}
// display translated error_text to user
promise = form_gadget.notifySubmitted()
.push(function () { .push(function () {
return form_gadget.translate('Input data has errors'); return form_gadget.translate(error_text);
}) })
.push(function (message) { .push(function (message) {
return form_gadget.notifyChange(message + '.'); return form_gadget.notifyChange(message + '.');
}) });
// if server validation of form data failed (indicated by response code 400)
// we parse out field errors and display them to the user
if (error.target.status === 400) {
promise
.push(function () { .push(function () {
// when the server-side validation returns the error description
if (error.target.responseType === "blob") { if (error.target.responseType === "blob") {
return jIO.util.readBlobAsText(error.target.response); return jIO.util.readBlobAsText(error.target.response);
} }
// otherwise return (most-likely) textual response of the server
return {target: {result: error.target.response}}; return {target: {result: error.target.response}};
}) })
.push(function (event) { .push(function (event) {
return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result)); return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
}); });
} }
return promise;
}
throw error; throw error;
}); });
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.28347.56387.25600</string> </value> <value> <string>960.5523.58984.43537</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1491225124.12</float> <float>1499170448.42</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
<!-- <!--
data-i18n=Input data has errors data-i18n=Input data has errors
data-i18n=You do not have the permissions to edit the object data-i18n=You do not have the permissions to edit the object
data-i18n=Document was not saved! Resubmit when you are online or the document accessible
data-i18n=Encountered an unknown error. Try to resubmit
--> -->
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>956.58742.58866.48708</string> </value> <value> <string>960.5523.58984.43537</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1490372079.18</float> <float>1499432130.91</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -121,6 +121,7 @@ ...@@ -121,6 +121,7 @@
.push(function (validity) { .push(function (validity) {
if (validity) { if (validity) {
return erp5_form.getContent() return erp5_form.getContent()
// try to send the form data over the network to jIO storage
.push(function (data) { .push(function (data) {
data[form_id.key] = form_id['default']; data[form_id.key] = form_id['default'];
...@@ -134,6 +135,7 @@ ...@@ -134,6 +135,7 @@
) )
]); ]);
}) })
// handle response from the server
.push(function (result_list) { .push(function (result_list) {
if (result_list[1].target.responseType === "blob") { if (result_list[1].target.responseType === "blob") {
return jIO.util.readBlobAsText(result_list[1].target.response); return jIO.util.readBlobAsText(result_list[1].target.response);
...@@ -153,31 +155,45 @@ ...@@ -153,31 +155,45 @@
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
if (error.target !== undefined) { if (error.target !== undefined) {
var error_text; var error_text = 'Encountered an unknown error. Try to resubmit',
promise;
// improve error message if we can
if (error.target.status === 400) { if (error.target.status === 400) {
error_text = 'Input data has errors'; error_text = 'Input data has errors';
} else if (error.target.status === 403) { } else if (error.target.status === 403) {
error_text = 'You do not have the permissions to edit the object'; error_text = 'You do not have the permissions to edit the object';
} else if (error.target.status === 0) {
// no/default=0 status means a network connection problem
error_text = 'Document was not saved! Resubmit when you are online or the document accessible';
} }
if (error_text !== undefined) { // display translated error_text to user
return form_gadget.notifySubmitted() promise = form_gadget.notifySubmitted()
.push(function () { .push(function () {
return form_gadget.translate(error_text); return form_gadget.translate(error_text);
}) })
.push(function (message) { .push(function (message) {
return form_gadget.notifyChange(message + '.'); return form_gadget.notifyChange(message + '.');
}) });
// if server validation of form data failed (indicated by response code 400)
// we parse out field errors and display them to the user
if (error.target.status === 400) {
promise
.push(function () { .push(function () {
// when the server-side validation returns the error description
if (error.target.responseType === "blob") { if (error.target.responseType === "blob") {
return jIO.util.readBlobAsText(error.target.response); return jIO.util.readBlobAsText(error.target.response);
} }
// otherwise return (most-likely) textual response of the server
return {target: {result: error.target.response}}; return {target: {result: error.target.response}};
}) })
.push(function (event) { .push(function (event) {
return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result)); return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
}); });
} }
return promise;
} }
// throwing an error is the last desperate option
throw error; throw error;
}); });
} }
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.31331.40640.10291</string> </value> <value> <string>960.32739.63971.65297</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1491385195.38</float> <float>1499430902.76</float>
<string>UTC</string> <string>UTC</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