Commit 990a3253 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Create form fields in parallel

parent b1c79faf
......@@ -3,6 +3,7 @@
(function (window, document, rJS, RSVP) {
"use strict";
function getFieldTypeGadgetUrl(type) {
var field_url = 'gadget_erp5_field_readonly.html';
if (type === 'ListField') {
......@@ -50,6 +51,92 @@
return field_url;
}
function addField(field, rendered_form, form_definition, form_gadget, group, modification_dict) {
if (rendered_form.hasOwnProperty(field[0])) {
// Field is enabled in this context
var sandbox = "public",
field_element = document.createElement("div"),
renderered_field = rendered_form[field[0]],
// 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.label = false;
suboptions.field_json = renderered_field;
suboptions.field_json.view = form_gadget.state.view;
if (group[0] !== "bottom") {
suboptions.label = true;
}
return new RSVP.Queue()
.push(function () {
if (modification_dict.hasOwnProperty('hash')) {
return form_gadget.declareGadget('gadget_erp5_label_field.html', {
scope: renderered_field.key,
element: field_element,
sandbox: sandbox
});
}
return form_gadget.getDeclaredGadget(renderered_field.key);
})
.push(function (label_gadget) {
if (modification_dict.hasOwnProperty('hash')) {
// XXX Hardcoded to get one listbox gadget
//pt form list gadget will get this listbox's info
//then pass to search field gadget
if (suboptions.field_url === "gadget_erp5_field_listbox.html") {
form_gadget.props.listbox_gadget = label_gadget;
}
form_gadget.props.gadget_list.push(label_gadget);
}
return label_gadget.render(suboptions);
})
.push(function () {
return field_element;
// return fieldset_element;
// fieldset_element.appendChild(field_element);
});
}
}
function addGroup(group, rendered_form, form_definition, form_gadget, modification_dict) {
// XXX: > Romain: fieldset will be needed later for menus
var fieldset_element = document.createElement("div"),
promise_field_list = [],
j;
fieldset_element.setAttribute("class", group[0]);
for (j = 0; j < group[1].length; j += 1) {
promise_field_list.push(addField(group[1][j], rendered_form, form_definition, form_gadget, group, modification_dict));
}
return new RSVP.Queue()
.push(function () {
return RSVP.all(promise_field_list);
})
.push(function (result_list) {
var i;
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i]) {
fieldset_element.appendChild(result_list[i]);
}
}
return fieldset_element;
});
}
rJS(window)
.ready(function (g) {
g.props = {};
......@@ -94,105 +181,35 @@
})
.onStateChange(function (modification_dict) {
var i,
erp5_document = this.state.erp5_document,
var erp5_document = this.state.erp5_document,
form_definition = this.state.form_definition,
rendered_form = erp5_document._embedded._view,
group_list = form_definition.group_list,
queue = new RSVP.Queue(),
form_gadget = this,
parent_element = document.createElement("div");
form_gadget = this;
if (modification_dict.hasOwnProperty('hash')) {
form_gadget.props.gadget_list = [];
}
function addGroup(group) {
queue
.push(function () {
var j,
// XXX: > Romain: fieldset will be needed later for menus
fieldset_element = document.createElement("div"),
group_queue = new RSVP.Queue();
function addField(field) {
group_queue.push(function () {
if (rendered_form.hasOwnProperty(field[0])) {
// Field is enabled in this context
var field_queue = new RSVP.Queue(),
sandbox = "public",
field_element = document.createElement("div"),
renderered_field = rendered_form[field[0]],
// 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.label = false;
suboptions.field_json = renderered_field;
suboptions.field_json.view = form_gadget.state.view;
if (group[0] !== "bottom") {
suboptions.label = true;
}
return field_queue
.push(function () {
if (modification_dict.hasOwnProperty('hash')) {
return form_gadget.declareGadget('gadget_erp5_label_field.html', {
scope: renderered_field.key,
element: field_element,
sandbox: sandbox
});
}
return form_gadget.getDeclaredGadget(renderered_field.key);
})
.push(function (label_gadget) {
if (modification_dict.hasOwnProperty('hash')) {
//XXXXX Hardcoded to get one listbox gadget
//pt form list gadget will get this listbox's info
//then pass to search field gadget
if (suboptions.field_url === "gadget_erp5_field_listbox.html") {
form_gadget.props.listbox_gadget = label_gadget;
}
form_gadget.props.gadget_list.push(label_gadget);
}
return label_gadget.render(suboptions);
})
.push(function () {
fieldset_element.appendChild(field_element);
});
}
});
}
fieldset_element.setAttribute("class", group[0]);
for (j = 0; j < group[1].length; j += 1) {
addField(group[1][j]);
}
return group_queue.push(function () {
parent_element.appendChild(fieldset_element);
});
});
}
for (i = 0; i < group_list.length; i += 1) {
addGroup(group_list[i]);
}
return queue
return new RSVP.Queue()
.push(function () {
var group_promise_list = [],
j;
for (j = 0; j < group_list.length; j += 1) {
group_promise_list.push(addGroup(group_list[j], rendered_form, form_definition, form_gadget, modification_dict));
}
return RSVP.all(group_promise_list);
})
.push(function (result_list) {
if (modification_dict.hasOwnProperty('hash')) {
var dom_element = form_gadget.element
.querySelector(".field_container");
.querySelector(".field_container"),
j,
parent_element = document.createDocumentFragment();
// Add all fieldset into the fragment
for (j = 0; j < result_list.length; j += 1) {
parent_element.appendChild(result_list[j]);
}
while (dom_element.firstChild) {
dom_element.removeChild(dom_element.firstChild);
}
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>955.49459.46929.49339</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1478189239.8</float>
<float>1480936090.54</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