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 @@
.allowPublicAcquisition('notifySubmit', function () {
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) {
var gadget = this,
promise_queue = new RSVP.Queue(),
......@@ -82,6 +89,7 @@
// if we get erp5 document during rendering then no need to fetch it
new_state.erp5_document = options.erp5_document;
// remove reference to erp5_document from options (and new_state.options)
// otherwise we get infinite loop
delete options.erp5_document;
} else {
promise_queue
......@@ -136,12 +144,10 @@
gadget = this,
options = this.state.options,
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_form = JSON.parse(gadget.state.erp5_form);
if (clean_dom) {
if (modification_dict.hasOwnProperty('url')) {
queue = gadget.declareGadget(gadget.state.url, {scope: "fg"});
} else {
queue = gadget.getDeclaredGadget("fg");
......@@ -164,7 +170,7 @@
return page_template_gadget.render(sub_options);
})
.push(function () {
if (clean_dom) {
if (modification_dict.hasOwnProperty('url')) {
return page_template_gadget.getElement()
.push(function (fragment) {
var element = gadget.element;
......@@ -189,12 +195,20 @@
});
})
.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];
// Force refresh
erp5_document._now = Date.now();
return this.changeState({erp5_document: JSON.stringify(erp5_document)});
});
erp5_document._now = Date.now(); // force refresh
// We choose render instead of changeState because the new form can use
// different page_template (reports are setup in form_dialog but rendered
// 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));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.16455.47614.10018</string> </value>
<value> <string>962.15790.20434.8686</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1502198575.84</float>
<float>1506008583.91</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -23,7 +23,7 @@
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("forcePageChange", "displayFormulatorValidationError")
.declareAcquiredMethod("displayFormulatorValidationError", "displayFormulatorValidationError")
/////////////////////////////////////////////////////////////////
// Proxy methods to the child gadget
......@@ -268,7 +268,7 @@
return jIO.util.readBlobAsText(attachment.target.response);
})
.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 @@
return {target: {result: error.target.response}};
})
.push(function (event) {
return form_gadget.forcePageChange(JSON.parse(event.target.result));
return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
});
}
return promise;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.15378.64583.40345</string> </value>
<value> <string>962.15391.22775.52445</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1505984600.8</float>
<float>1506008825.18</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