Commit 13c77d52 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Rerender the existing form if possible

parent d00a76b4
...@@ -67,25 +67,45 @@ ...@@ -67,25 +67,45 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var group_list = options.form_definition.group_list,
rendered_form = options.erp5_document._embedded._view,
i,
j,
hash = "";
// Check the list of field to render
// If the list is different, DOM content will be dropped
// and recreated
for (i = 0; i < group_list.length; i += 1) {
hash += group_list[i][0];
for (j = 0; j < group_list[i][1].length; j += 1) {
if (rendered_form.hasOwnProperty(group_list[i][1][j][0])) {
hash += group_list[i][1][j][0];
}
}
}
return this.changeState({
erp5_document: options.erp5_document,
form_definition: options.form_definition,
hash: hash,
view: options.view
});
})
.declareMethod('updateDOM', function (modification_dict) {
var i, var i,
erp5_document = options.erp5_document, erp5_document = this.state.erp5_document,
form_definition = options.form_definition, form_definition = this.state.form_definition,
rendered_form = erp5_document._embedded._view, rendered_form = erp5_document._embedded._view,
group_list = form_definition.group_list, group_list = form_definition.group_list,
queue = new RSVP.Queue(), queue = new RSVP.Queue(),
form_gadget = this, form_gadget = this,
suboption_dict = {},
parent_element = document.createElement("div"); parent_element = document.createElement("div");
form_gadget.state_parameter_dict = options.form_gadget || {}; if (modification_dict.hasOwnProperty('hash')) {
// XXX Hardcoded for searchfield - remove later!
if (form_definition.extended_search) {
suboption_dict.extended_search = form_definition.extended_search;
}
// XXX Hardcoded for listbox's hide functionality
suboption_dict.hide_enabled = form_definition.hide_enabled;
form_gadget.props.gadget_list = []; form_gadget.props.gadget_list = [];
}
function addGroup(group) { function addGroup(group) {
queue queue
...@@ -104,11 +124,20 @@ ...@@ -104,11 +124,20 @@
sandbox = "public", sandbox = "public",
field_element = document.createElement("div"), field_element = document.createElement("div"),
renderered_field = rendered_form[field[0]], renderered_field = rendered_form[field[0]],
suboptions = options[renderered_field.key] || suboption_dict; // suboptions = options[renderered_field.key] || suboption_dict;
suboptions = {};
// XXX Hardcoded for searchfield - remove later!
if (form_definition.extended_search) {
suboptions.extended_search = form_definition.extended_search;
}
// XXX Hardcoded for listbox's hide functionality
suboptions.hide_enabled = form_definition.hide_enabled;
suboptions.field_url = getFieldTypeGadgetUrl(renderered_field.type); suboptions.field_url = getFieldTypeGadgetUrl(renderered_field.type);
suboptions.label = false; suboptions.label = false;
suboptions.field_json = renderered_field; suboptions.field_json = renderered_field;
suboptions.field_json.view = options.view; suboptions.field_json.view = form_gadget.state.view;
if (group[0] !== "bottom") { if (group[0] !== "bottom") {
suboptions.label = true; suboptions.label = true;
...@@ -116,13 +145,18 @@ ...@@ -116,13 +145,18 @@
return field_queue return field_queue
.push(function () { .push(function () {
if (modification_dict.hasOwnProperty('hash')) {
return form_gadget.declareGadget('gadget_erp5_label_field.html', { return form_gadget.declareGadget('gadget_erp5_label_field.html', {
scope: renderered_field.key, scope: renderered_field.key,
element: field_element, element: field_element,
sandbox: sandbox sandbox: sandbox
}); });
}
return form_gadget.getDeclaredGadget(renderered_field.key);
}) })
.push(function (label_gadget) { .push(function (label_gadget) {
if (modification_dict.hasOwnProperty('hash')) {
//XXXXX Hardcoded to get one listbox gadget //XXXXX Hardcoded to get one listbox gadget
//pt form list gadget will get this listbox's info //pt form list gadget will get this listbox's info
//then pass to search field gadget //then pass to search field gadget
...@@ -130,6 +164,7 @@ ...@@ -130,6 +164,7 @@
form_gadget.props.listbox_gadget = label_gadget; form_gadget.props.listbox_gadget = label_gadget;
} }
form_gadget.props.gadget_list.push(label_gadget); form_gadget.props.gadget_list.push(label_gadget);
}
return label_gadget.render(suboptions); return label_gadget.render(suboptions);
}) })
.push(function () { .push(function () {
...@@ -155,19 +190,17 @@ ...@@ -155,19 +190,17 @@
return queue return queue
.push(function () { .push(function () {
if (modification_dict.hasOwnProperty('hash')) {
var dom_element = form_gadget.element var dom_element = form_gadget.element
.querySelector(".field_container"); .querySelector(".field_container");
while (dom_element.firstChild) { while (dom_element.firstChild) {
dom_element.removeChild(dom_element.firstChild); dom_element.removeChild(dom_element.firstChild);
} }
dom_element.appendChild(parent_element); dom_element.appendChild(parent_element);
// return $(parent_element).trigger("create"); }
}); });
}) })
.declareMethod("getListboxInfo", function () { .declareMethod("getListboxInfo", function () {
//XXXXX get listbox gadget's info //XXXXX get listbox gadget's info
var gadget = this; var gadget = this;
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.24492.61471.3703</string> </value> <value> <string>954.27320.12986.51029</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>1475681076.93</float> <float>1475762090.29</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