Commit 3bf9d9d1 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs] Page Form rechecks form page template on "displayValidationErrors"

parent 40848b9e
...@@ -68,6 +68,13 @@ ...@@ -68,6 +68,13 @@
.allowPublicAcquisition('notifySubmit', function () { .allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit(); return this.triggerSubmit();
}) })
/**
* Render obtain ERP5 Document and assigned Form Definition.
*
* Arguments:
* `erp5_document` or parameters to obtain one: `jio_key`, `view`
* `editable`
*/
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
promise_queue = new RSVP.Queue(), promise_queue = new RSVP.Queue(),
...@@ -82,6 +89,7 @@ ...@@ -82,6 +89,7 @@
// if we get erp5 document during rendering then no need to fetch it // if we get erp5 document during rendering then no need to fetch it
new_state.erp5_document = options.erp5_document; new_state.erp5_document = options.erp5_document;
// remove reference to erp5_document from options (and new_state.options) // remove reference to erp5_document from options (and new_state.options)
// otherwise we get infinite loop
delete options.erp5_document; delete options.erp5_document;
} else { } else {
promise_queue promise_queue
...@@ -136,12 +144,10 @@ ...@@ -136,12 +144,10 @@
gadget = this, gadget = this,
options = this.state.options, options = this.state.options,
page_template_gadget, page_template_gadget,
// clean_dom === false only in case of displaying errors
clean_dom = modification_dict.hasOwnProperty('url'),
erp5_document = JSON.parse(gadget.state.erp5_document), erp5_document = JSON.parse(gadget.state.erp5_document),
erp5_form = JSON.parse(gadget.state.erp5_form); erp5_form = JSON.parse(gadget.state.erp5_form);
if (clean_dom) { if (modification_dict.hasOwnProperty('url')) {
queue = gadget.declareGadget(gadget.state.url, {scope: "fg"}); queue = gadget.declareGadget(gadget.state.url, {scope: "fg"});
} else { } else {
queue = gadget.getDeclaredGadget("fg"); queue = gadget.getDeclaredGadget("fg");
...@@ -164,7 +170,7 @@ ...@@ -164,7 +170,7 @@
return page_template_gadget.render(sub_options); return page_template_gadget.render(sub_options);
}) })
.push(function () { .push(function () {
if (clean_dom) { if (modification_dict.hasOwnProperty('url')) {
return page_template_gadget.getElement() return page_template_gadget.getElement()
.push(function (fragment) { .push(function (fragment) {
var element = gadget.element; var element = gadget.element;
...@@ -189,12 +195,20 @@ ...@@ -189,12 +195,20 @@
}); });
}) })
.allowPublicAcquisition("displayFormulatorValidationError", function (param_list) { .allowPublicAcquisition("displayFormulatorValidationError", function (param_list) {
var erp5_document = JSON.parse(this.state.erp5_document); var erp5_document = JSON.parse(this.state.erp5_document),
options = this.state.options;
erp5_document._embedded._view = param_list[0]; erp5_document._embedded._view = param_list[0];
// Force refresh erp5_document._now = Date.now(); // force refresh
erp5_document._now = Date.now(); // We choose render instead of changeState because the new form can use
// different page_template (reports are setup in form_dialog but rendered
return this.changeState({erp5_document: JSON.stringify(erp5_document)}); // in report_view).
}); // Validation provides document updated for error texts but uses the same
// form thus the same view thus the same url - no DOM modifications
//
// We modify inplace state.options because in render we remove this
// exceeding document.
options.erp5_document = erp5_document;
return this.render(options);
})
}(window, rJS, URI, RSVP)); }(window, rJS, URI, RSVP));
\ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.16455.47614.10018</string> </value> <value> <string>962.15790.20434.8686</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>1502198575.84</float> <float>1506008583.91</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
.declareAcquiredMethod("notifySubmitted", "notifySubmitted") .declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("translate", "translate") .declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("notifyChange", "notifyChange") .declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("forcePageChange", "displayFormulatorValidationError") .declareAcquiredMethod("displayFormulatorValidationError", "displayFormulatorValidationError")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Proxy methods to the child gadget // Proxy methods to the child gadget
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
return jIO.util.readBlobAsText(attachment.target.response); return jIO.util.readBlobAsText(attachment.target.response);
}) })
.push(function (response_text) { .push(function (response_text) {
return form_gadget.forcePageChange(JSON.parse(response_text.target.result)); return form_gadget.displayFormulatorValidationError(JSON.parse(response_text.target.result));
}); });
} }
...@@ -321,7 +321,7 @@ ...@@ -321,7 +321,7 @@
return {target: {result: error.target.response}}; return {target: {result: error.target.response}};
}) })
.push(function (event) { .push(function (event) {
return form_gadget.forcePageChange(JSON.parse(event.target.result)); return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
}); });
} }
return promise; return promise;
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.15378.64583.40345</string> </value> <value> <string>962.15391.22775.52445</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>1505984600.8</float> <float>1506008825.18</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