Commit c9edbda4 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Do not fetch ERP5 data after formulator validation error

parent 14b7cbfa
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_page_form.js" type="text/javascript"></script> <script src="gadget_erp5_page_form.js" type="text/javascript"></script>
</head> </head>
......
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>romain</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>937.49661.35517.47837</string> </value> <value> <string>952.64761.25287.18397</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,8 +252,8 @@ ...@@ -252,8 +252,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1411465614.17</float> <float>1475148161.21</float>
<string>GMT</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -3,16 +3,13 @@ ...@@ -3,16 +3,13 @@
(function (window, rJS, URI) { (function (window, rJS, URI) {
"use strict"; "use strict";
var gadget_klass = rJS(window);
// DEFAULT_VIEW_REFERENCE = "view";
function loadFormContent(gadget, result) { function loadFormContent(gadget, result) {
var key; var key;
if (gadget.props.options.form_content) { if (gadget.state.options.form_content) {
for (key in result) { for (key in result) {
if (result.hasOwnProperty(key)) { if (result.hasOwnProperty(key)) {
if (gadget.props.options.form_content[result[key].key]) { if (gadget.state.options.form_content[result[key].key]) {
result[key].default = gadget.props.options.form_content[result[key].key]; result[key].default = gadget.state.options.form_content[result[key].key];
} }
} }
} }
...@@ -20,22 +17,7 @@ ...@@ -20,22 +17,7 @@
} }
gadget_klass rJS(window)
/////////////////////////////////////////////////////////////////
// ready
/////////////////////////////////////////////////////////////////
// Init local properties
.ready(function (g) {
g.props = {};
})
// Assign the element to a variable
.ready(function (g) {
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -60,6 +42,9 @@ ...@@ -60,6 +42,9 @@
return result; return result;
}); });
}) })
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.declareMethod('triggerSubmit', function () { .declareMethod('triggerSubmit', function () {
return this.getDeclaredGadget('fg') return this.getDeclaredGadget('fg')
.push(function (g) { .push(function (g) {
...@@ -67,42 +52,24 @@ ...@@ -67,42 +52,24 @@
}); });
}) })
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this;
element = gadget.props.element, return gadget.jio_getAttachment(options.jio_key, options.view)
erp5_document,
erp5_form,
queue,
form_gadget;
gadget.props.jio_key = options.jio_key;
gadget.props.options = options;
queue = gadget.jio_getAttachment(options.jio_key, options.view);
queue
.push(function (result) { .push(function (result) {
var uri; var uri;
if (!result._embedded) { if (!result._embedded) {
return gadget.jio_getAttachment(options.jio_key, "links") return gadget.jio_getAttachment(options.jio_key, "links")
.push(function (result) { .push(function (result2) {
return gadget.redirect({command: 'change', options: { return gadget.redirect({command: 'change', options: {
view: result._links.view[0].href, view: result2._links.view[0].href,
editable: undefined, editable: undefined,
page: undefined page: undefined
}}); }});
}); });
} }
if (options.hasOwnProperty("form_validation_error")) {
result._embedded._view = options.form_validation_error;
}
uri = new URI(result._embedded._view._links.form_definition.href); uri = new URI(result._embedded._view._links.form_definition.href);
erp5_document = result; return gadget.jio_getAttachment(uri.segment(2), "view")
queue .push(function (erp5_form) {
.push(function () {
return gadget.jio_getAttachment(uri.segment(2), "view");
})
.push(function (result) {
erp5_form = result;
loadFormContent(gadget, erp5_document._embedded._view);
var url = "gadget_erp5_pt_" + erp5_form.pt; var url = "gadget_erp5_pt_" + erp5_form.pt;
// XXX Hardcoded specific behaviour for form_view // XXX Hardcoded specific behaviour for form_view
if ((options.editable !== undefined) && (erp5_form.pt === "form_view")) { if ((options.editable !== undefined) && (erp5_form.pt === "form_view")) {
...@@ -110,40 +77,69 @@ ...@@ -110,40 +77,69 @@
} }
url += ".html"; url += ".html";
return gadget.declareGadget(url, { return gadget.changeState({
scope: "fg" jio_key: options.jio_key,
options: options,
view: options.view,
url: url,
erp5_document: result,
erp5_form: erp5_form
}); });
})
.push(function (result) {
var sub_options = options.fg || {};
sub_options.erp5_document = erp5_document;
sub_options.form_definition = erp5_form;
sub_options.view = options.view;
sub_options.action_view = options.action_view;
sub_options.jio_key = options.jio_key;
sub_options.editable = options.editable;
form_gadget = result;
return form_gadget.render(sub_options);
})
.push(function () {
return form_gadget.getElement();
})
.push(function (fragment) {
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(fragment);
}); });
}); });
return queue;
}) })
.declareMethod('updateDOM', function (modification_dict) {
var queue,
gadget = this,
options = this.state.options,
page_template_gadget,
clean_dom = modification_dict.hasOwnProperty('url');
if (clean_dom) {
queue = gadget.declareGadget(gadget.state.url, {scope: "fg"});
} else {
queue = gadget.getDeclaredGadget("fg");
}
return queue
.push(function (result) {
page_template_gadget = result;
var sub_options = options.fg || {},
erp5_document = gadget.state.erp5_document,
erp5_form = gadget.state.erp5_form;
// Render the page template form
if (options.hasOwnProperty("form_validation_error")) {
erp5_document._embedded._view = options.form_validation_error;
}
loadFormContent(gadget, erp5_document._embedded._view);
sub_options.erp5_document = erp5_document;
sub_options.form_definition = erp5_form;
sub_options.view = options.view;
sub_options.action_view = options.action_view;
sub_options.jio_key = options.jio_key;
sub_options.editable = options.editable;
return page_template_gadget.render(sub_options);
})
.push(function () {
if (clean_dom) {
return page_template_gadget.getElement()
.push(function (fragment) {
var element = gadget.element;
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(fragment);
});
}
});
})
.allowPublicAcquisition("displayFormulatorValidationError", function (param_list) { .allowPublicAcquisition("displayFormulatorValidationError", function (param_list) {
var options = this.props.options; return this.changeState({form_validation_error: param_list[0]});
options.form_validation_error = param_list[0];
return this.render(options);
}); });
}(window, rJS, URI)); }(window, rJS, URI));
\ No newline at end of file
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Gadget ERP5 Doc JS</string> </value> <value> <string>Gadget ERP5 Page Form JS</string> </value>
</item> </item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>952.10025.24641.8430</string> </value> <value> <string>954.15904.46164.40277</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>1467032278.85</float> <float>1475503870.23</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