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 @@ ...@@ -3,6 +3,7 @@
(function (window, document, rJS, RSVP) { (function (window, document, rJS, RSVP) {
"use strict"; "use strict";
function getFieldTypeGadgetUrl(type) { function getFieldTypeGadgetUrl(type) {
var field_url = 'gadget_erp5_field_readonly.html'; var field_url = 'gadget_erp5_field_readonly.html';
if (type === 'ListField') { if (type === 'ListField') {
...@@ -50,78 +51,11 @@ ...@@ -50,78 +51,11 @@
return field_url; return field_url;
} }
rJS(window)
.ready(function (g) {
g.props = {};
})
.allowPublicAcquisition("getFieldTypeGadgetUrl", function (param_list) {
return getFieldTypeGadgetUrl(param_list[0]);
})
.allowPublicAcquisition("getFormContent", function (param_list) {
return this.getContent(param_list[0]);
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('render', function (options) { function addField(field, rendered_form, form_definition, form_gadget, group, modification_dict) {
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
});
})
.onStateChange(function (modification_dict) {
var i,
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");
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])) { if (rendered_form.hasOwnProperty(field[0])) {
// Field is enabled in this context // Field is enabled in this context
var field_queue = new RSVP.Queue(), var 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;
...@@ -143,7 +77,7 @@ ...@@ -143,7 +77,7 @@
suboptions.label = true; suboptions.label = true;
} }
return field_queue return new RSVP.Queue()
.push(function () { .push(function () {
if (modification_dict.hasOwnProperty('hash')) { if (modification_dict.hasOwnProperty('hash')) {
return form_gadget.declareGadget('gadget_erp5_label_field.html', { return form_gadget.declareGadget('gadget_erp5_label_field.html', {
...@@ -157,7 +91,7 @@ ...@@ -157,7 +91,7 @@
.push(function (label_gadget) { .push(function (label_gadget) {
if (modification_dict.hasOwnProperty('hash')) { if (modification_dict.hasOwnProperty('hash')) {
//XXXXX Hardcoded to get one listbox gadget // XXX 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
if (suboptions.field_url === "gadget_erp5_field_listbox.html") { if (suboptions.field_url === "gadget_erp5_field_listbox.html") {
...@@ -168,31 +102,114 @@ ...@@ -168,31 +102,114 @@
return label_gadget.render(suboptions); return label_gadget.render(suboptions);
}) })
.push(function () { .push(function () {
fieldset_element.appendChild(field_element); 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]); fieldset_element.setAttribute("class", group[0]);
for (j = 0; j < group[1].length; j += 1) { for (j = 0; j < group[1].length; j += 1) {
addField(group[1][j]); promise_field_list.push(addField(group[1][j], rendered_form, form_definition, form_gadget, group, modification_dict));
} }
return group_queue.push(function () { return new RSVP.Queue()
parent_element.appendChild(fieldset_element); .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 = {};
})
.allowPublicAcquisition("getFieldTypeGadgetUrl", function (param_list) {
return getFieldTypeGadgetUrl(param_list[0]);
})
.allowPublicAcquisition("getFormContent", function (param_list) {
return this.getContent(param_list[0]);
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.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) { for (i = 0; i < group_list.length; i += 1) {
addGroup(group_list[i]); 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 queue return this.changeState({
erp5_document: options.erp5_document,
form_definition: options.form_definition,
hash: hash,
view: options.view
});
})
.onStateChange(function (modification_dict) {
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,
form_gadget = this;
if (modification_dict.hasOwnProperty('hash')) {
form_gadget.props.gadget_list = [];
}
return new RSVP.Queue()
.push(function () { .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')) { if (modification_dict.hasOwnProperty('hash')) {
var dom_element = form_gadget.element 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) { while (dom_element.firstChild) {
dom_element.removeChild(dom_element.firstChild); dom_element.removeChild(dom_element.firstChild);
} }
......
...@@ -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.45675.44850.53452</string> </value> <value> <string>955.49459.46929.49339</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>1478189239.8</float> <float>1480936090.54</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