Commit 1039d977 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Display formulator validation errors

In case of HTTP error 400, rerender the page with the new JSON returned by ERP5.
parent bb95152c
......@@ -258,6 +258,9 @@
label_element.setAttribute(\'for\', renderered_field.key);\n
label_element.textContent = renderered_field.title;\n
label_element.setAttribute(\'data-i18n\', renderered_field.title);\n
if (renderered_field.hasOwnProperty(\'error_text\')) {\n
error_element.textContent = " (" + renderered_field.error_text + ")";\n
}\n
// error_element.setAttribute(\'class\', \'ui-state-error ui-corner-all\');\n
label_element.appendChild(error_element);\n
if (group[0] !== "bottom") {\n
......@@ -529,7 +532,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>947.36619.54273.47138</string> </value>
<value> <string>948.17341.58767.64750</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -547,7 +550,7 @@
</tuple>
<state>
<tuple>
<float>1451917036.79</float>
<float>1452009359.45</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -139,6 +139,9 @@
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")\n
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")\n
.declareAcquiredMethod("translateHtml", "translateHtml")\n
.declareAcquiredMethod("notifyChange", "notifyChange")\n
.declareAcquiredMethod("displayFormulatorValidationError",\n
"displayFormulatorValidationError")\n
\n
\n
/////////////////////////////////////////////////////////////////\n
......@@ -271,6 +274,18 @@
form_gadget.notifySubmitted(),\n
form_gadget.redirect({command: \'push_history\', options: {jio_key: new URI(location).segment(2), editable: form_gadget.props.editable}})\n
]);\n
})\n
.push(undefined, function (error) {\n
if ((error.target !== undefined) && (error.target.status === 400)) {\n
return form_gadget.notifySubmitted()\n
.push(function () {\n
return form_gadget.notifyChange();\n
})\n
.push(function () {\n
return form_gadget.displayFormulatorValidationError(JSON.parse(error.target.responseText));\n
});\n
}\n
throw error;\n
});\n
}\n
\n
......@@ -406,7 +421,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -420,7 +435,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>946.39113.715.59340</string> </value>
<value> <string>948.17482.34241.44117</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -438,8 +453,8 @@
</tuple>
<state>
<tuple>
<float>1445530221.33</float>
<string>GMT</string>
<float>1452010264.83</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -99,7 +99,9 @@
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>/*global window, rJS, RSVP, loopEventListener, document */\n
<value> <string encoding="cdata"><![CDATA[
/*global window, rJS, RSVP, loopEventListener, document */\n
/*jslint nomen: true, indent: 2, maxerr: 3 */\n
(function (window, rJS, RSVP, loopEventListener) {\n
"use strict";\n
......@@ -127,6 +129,9 @@
.declareAcquiredMethod("updateHeader", "updateHeader")\n
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")\n
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")\n
.declareAcquiredMethod("notifyChange", "notifyChange")\n
.declareAcquiredMethod("displayFormulatorValidationError",\n
"displayFormulatorValidationError")\n
\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
......@@ -217,7 +222,19 @@
)\n
]);\n
})\n
.push(form_gadget.notifySubmitted.bind(form_gadget));\n
.push(form_gadget.notifySubmitted.bind(form_gadget))\n
.push(undefined, function (error) {\n
if ((error.target !== undefined) && (error.target.status === 400)) {\n
return form_gadget.notifySubmitted()\n
.push(function () {\n
return form_gadget.notifyChange();\n
})\n
.push(function () {\n
return form_gadget.displayFormulatorValidationError(JSON.parse(error.target.responseText));\n
});\n
}\n
throw error;\n
});\n
}\n
});\n
}\n
......@@ -231,7 +248,9 @@
);\n
});\n
\n
}(window, rJS, RSVP, loopEventListener));</string> </value>
}(window, rJS, RSVP, loopEventListener));
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
......@@ -352,7 +371,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -366,7 +385,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>946.30054.11308.16162</string> </value>
<value> <string>948.17477.48819.45363</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -384,8 +403,8 @@
</tuple>
<state>
<tuple>
<float>1445329477.85</float>
<string>GMT</string>
<float>1452009999.57</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -101,9 +101,9 @@
<key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*global window, rJS, URI */\n
/*global window, rJS, URI, jQuery */\n
/*jslint nomen: true, indent: 2, maxerr: 3 */\n
(function (window, rJS, URI) {\n
(function (window, rJS, URI, $) {\n
"use strict";\n
\n
var gadget_klass = rJS(window);\n
......@@ -149,9 +149,13 @@
form_gadget;\n
\n
gadget.props.jio_key = options.jio_key;\n
gadget.props.options = options;\n
\n
return gadget.jio_getAttachment(options.jio_key, options.view)\n
.push(function (result) {\n
if (options.hasOwnProperty("form_validation_error")) {\n
result._embedded._view = options.form_validation_error;\n
}\n
var uri = new URI(result._embedded._view._links.form_definition.href);\n
erp5_document = result;\n
return gadget.jio_getAttachment(uri.segment(2), "view");\n
......@@ -191,10 +195,19 @@
element.removeChild(element.firstChild);\n
}\n
element.appendChild(fragment);\n
if (options.hasOwnProperty("form_validation_error")) {\n
$(element).trigger("create");\n
}\n
});\n
})\n
\n
.allowPublicAcquisition("displayFormulatorValidationError", function (param_list) {\n
var options = this.props.options;\n
options.form_validation_error = param_list[0];\n
return this.render(options);\n
});\n
\n
}(window, rJS, URI));
}(window, rJS, URI, jQuery));
]]></string> </value>
</item>
......@@ -317,7 +330,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -331,7 +344,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>946.30055.63361.39150</string> </value>
<value> <string>948.17480.10033.55347</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -349,8 +362,8 @@
</tuple>
<state>
<tuple>
<float>1445267203.04</float>
<string>GMT</string>
<float>1452010103.81</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
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