Commit 617457e1 authored by Tomáš Peterka's avatar Tomáš Peterka

[renderjs_ui] Refactoring of Form + one new feature - empty labels will not...

[renderjs_ui] Refactoring of Form + one new feature - empty labels will not show at all (+ forgotten XML files)
parent cba476fd
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.10605.65461.53367</string> </value> <value> <string>961.17832.13281.59733</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>1501769352.85</float> <float>1502199696.37</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -60,88 +60,88 @@ ...@@ -60,88 +60,88 @@
return field_url; return field_url;
} }
/**
* Physically append rendered field to DOM.
*
* Wraps every field in label gadget.
* @argument field: array<tuple<str, object>> where first item is name, second meta info of the field
* (obsolete to specify the meta information which is returned by JSON style since it is duplicate of information in document instance)
*/
function addField(field, rendered_document, form_definition, form_gadget, group_name, modification_dict) {
var field_name = field[0],
field_element,
suboptions;
function addField(field, rendered_form, form_definition, form_gadget, group, modification_dict) { if (!rendered_document.hasOwnProperty(field_name)) {
if (rendered_form.hasOwnProperty(field[0])) { return;
// Field is enabled in this context }
var sandbox = "public",
field_element = document.createElement("div"),
rendered_field = rendered_form[field[0]],
// suboptions = options[rendered_field.key] || suboption_dict;
suboptions = {};
// XXX Hardcoded for searchfield - remove later! suboptions = {
if (form_definition.extended_search) { hide_enabled: form_definition.hide_enabled, // listbox specific
suboptions.extended_search = form_definition.extended_search; extended_search: form_definition.extended_search, // searchfield specific
} field_url: getFieldTypeGadgetUrl(rendered_document[field_name].type),
// XXX Hardcoded for listbox's hide functionality label: ((group_name !== "bottom") && (rendered_document[field_name].title.length > 0)), // no label for bottom group and field without title
suboptions.hide_enabled = form_definition.hide_enabled; field_json: rendered_document[field_name] // pass
};
suboptions.field_url = getFieldTypeGadgetUrl(rendered_field.type); // XXX: what is the purpose of this?
suboptions.label = false; suboptions.field_json.view = form_gadget.state.view;
suboptions.field_json = rendered_field;
suboptions.field_json.view = form_gadget.state.view;
// if the whole form is non-editable than every field has to be non-editable // if the whole form is non-editable than every field has to be non-editable
if (form_gadget.state.editable === 0) { if (form_gadget.state.editable === 0) {
suboptions.field_json.editable = 0; suboptions.field_json.editable = 0;
} }
return new RSVP.Queue() field_element = document.createElement("div");
.push(function () { return new RSVP.Queue()
if (modification_dict.hasOwnProperty('hash')) { .push(function () {
return form_gadget.declareGadget('gadget_erp5_label_field.html', { if (modification_dict.hasOwnProperty('hash')) {
scope: rendered_field.key, return form_gadget.declareGadget('gadget_erp5_label_field.html', {
element: field_element, scope: field_name,
sandbox: sandbox element: field_element,
}); sandbox: "public"
} });
return form_gadget.getDeclaredGadget(rendered_field.key); }
}) return form_gadget.getDeclaredGadget(field_name);
.push(function (label_gadget) { })
if (modification_dict.hasOwnProperty('hash')) { .push(function (label_gadget) {
if (modification_dict.hasOwnProperty('hash')) {
// XXX 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") {
form_gadget.props.listbox_gadget = label_gadget; form_gadget.props.listbox_gadget = label_gadget;
}
form_gadget.props.gadget_list.push(label_gadget);
} }
return label_gadget.render(suboptions); form_gadget.props.gadget_list.push(label_gadget);
}) }
.push(function () { return label_gadget.render(suboptions);
return field_element; })
// return fieldset_element; .push(function () {
// fieldset_element.appendChild(field_element); return field_element;
}); });
}
} }
function addGroup(group, rendered_form, form_definition, form_gadget, modification_dict) { function addGroup(group, rendered_document, form_definition, form_gadget, modification_dict) {
// XXX: > Romain: fieldset will be needed later for menus // XXX: > Romain: fieldset will be needed later for menus
var fieldset_element = document.createElement("div"), var fieldset_element = document.createElement("div"),
promise_field_list = [], group_name = group[0],
j; field_list = group[1];
fieldset_element.setAttribute("class", group[0]); fieldset_element.setAttribute("class", group_name);
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() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all(promise_field_list); return RSVP.all(field_list.map(function (field) {
return addField(field, rendered_document, form_definition, form_gadget, group_name, modification_dict);
}));
}) })
.push(function (result_list) { .push(function (result_list) {
var i; // append all rendered fields into DOM
for (i = 0; i < result_list.length; i += 1) { result_list.forEach(function (result) {
if (result_list[i]) { if (result) {fieldset_element.appendChild(result); }
fieldset_element.appendChild(result_list[i]); });
}
}
return fieldset_element; return fieldset_element;
}); });
} }
...@@ -152,6 +152,20 @@ ...@@ -152,6 +152,20 @@
g.props = {}; g.props = {};
}) })
.setState({
// erp5 document is an instance of a document referenced by jio_key
erp5_document: undefined,
jio_key: undefined,
// form definition holds positioning of fields
form_definition: undefined,
view: undefined, // Kato: still have no idea what that means
// hash is used to spot changes in positioning of fields
hash: "",
// attributes of the form - no magic there
title: undefined,
editable: undefined
})
.allowPublicAcquisition("getFieldTypeGadgetUrl", function (param_list) { .allowPublicAcquisition("getFieldTypeGadgetUrl", function (param_list) {
return getFieldTypeGadgetUrl(param_list[0]); return getFieldTypeGadgetUrl(param_list[0]);
}) })
...@@ -165,19 +179,24 @@ ...@@ -165,19 +179,24 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var group_list = options.form_definition.group_list, var group_list = options.form_definition.group_list,
rendered_form = options.erp5_document._embedded._view, rendered_document = options.erp5_document._embedded._view,
hash = "",
group_name,
group_field_list,
i, i,
j, j;
hash = "";
// Check the list of field to render // Contruct a hash of <placement>+<field names> to snapshot rendering.
// If the list is different, DOM content will be dropped // The `hash` will make it to the `onStateChange` only if it has changed.
// and recreated // If so, 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) {
hash += group_list[i][0]; group_name = group_list[i][0];
for (j = 0; j < group_list[i][1].length; j += 1) { group_field_list = group_list[i][1];
if (rendered_form.hasOwnProperty(group_list[i][1][j][0])) { hash += group_name;
hash += group_list[i][1][j][0];
for (j = 0; j < group_field_list.length; j += 1) {
if (rendered_document.hasOwnProperty(group_field_list[j][0])) {
hash += group_field_list[j][0];
} }
} }
} }
...@@ -196,7 +215,7 @@ ...@@ -196,7 +215,7 @@
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
var erp5_document = this.state.erp5_document, var erp5_document = this.state.erp5_document,
form_definition = this.state.form_definition, form_definition = this.state.form_definition,
rendered_form = erp5_document._embedded._view, rendered_document = erp5_document._embedded._view,
group_list = form_definition.group_list, group_list = form_definition.group_list,
form_gadget = this; form_gadget = this;
...@@ -206,12 +225,9 @@ ...@@ -206,12 +225,9 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var group_promise_list = [], return RSVP.all(group_list.map(function (group) {
j; return addGroup(group, rendered_document, form_definition, form_gadget, modification_dict);
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) { .push(function (result_list) {
if (modification_dict.hasOwnProperty('hash')) { if (modification_dict.hasOwnProperty('hash')) {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.9083.63657.29132</string> </value> <value> <string>961.17824.16764.21521</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>1501749851.19</float> <float>1502198463.15</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