Commit d2202287 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Eteri

[renderjs_ui] Move gadget url resolution (from its ERP5 type) to from Form to Label Gadget

parent 8197c99a
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, document, rJS, RSVP*/ /*global window, document, rJS, RSVP*/
/** Form is one of a complicated gadget!
*
* Editability - the form overrides editability of its fields. Editability is
* hard-coded changed either in Page Templates or soft-coded
* changed in FormBox gadget which renders form as a subgadget
**/
(function (window, document, rJS, RSVP) { (function (window, document, rJS, RSVP) {
"use strict"; "use strict";
/** Form is one of a complicated gadget!
*
* Editability - the form overrides editability of its fields. Editability is
* hard-coded changed either in Page Templates or soft-coded
* changed in FormBox gadget which renders form as a subgadget
**/
function getFieldTypeGadgetUrl(type) {
var field_url = 'gadget_erp5_field_readonly.html';
if (type === 'ListField') {
field_url = 'gadget_erp5_field_list.html';
} else if ((type === 'ParallelListField') ||
(type === 'MultiListField')) {
field_url = 'gadget_erp5_field_multilist.html';
} else if (type === 'CheckBoxField') {
field_url = 'gadget_erp5_field_checkbox.html';
} else if (type === 'MultiCheckBoxField') {
field_url = 'gadget_erp5_field_multicheckbox.html';
} else if (type === 'StringField') {
field_url = 'gadget_erp5_field_string.html';
} else if (type === 'PasswordField') {
field_url = 'gadget_erp5_field_password.html';
} else if (type === 'RelationStringField') {
field_url = 'gadget_erp5_field_relationstring.html';
} else if (type === 'MultiRelationStringField') {
field_url = 'gadget_erp5_field_multirelationstring.html';
} else if (type === 'TextAreaField') {
field_url = 'gadget_erp5_field_textarea.html';
} else if (type === 'DateTimeField') {
field_url = 'gadget_erp5_field_datetime.html';
} else if (type === 'FloatField') {
field_url = 'gadget_erp5_field_float.html';
} else if (type === 'FileField') {
field_url = 'gadget_erp5_field_file.html';
} else if (type === 'IntegerField') {
field_url = 'gadget_erp5_field_integer.html';
} else if (type === 'ListBox') {
field_url = 'gadget_erp5_field_listbox.html';
} else if (type === 'EditorField') {
field_url = 'gadget_erp5_field_editor.html';
// field_url = 'gadget_codemirror.html';
// sandbox = 'iframe';
} else if (type === 'GadgetField') {
field_url = 'gadget_erp5_field_gadget.html';
} else if (type === 'RadioField') {
field_url = 'gadget_erp5_field_radio.html';
} else if (type === 'ImageField') {
field_url = 'gadget_erp5_field_image.html';
} else if (type === 'EmailField') {
field_url = 'gadget_erp5_field_email.html';
} else if (type === 'FormBox') {
field_url = 'gadget_erp5_field_formbox.html';
}
return field_url;
}
/** /**
* Physically append rendered field to DOM. * Physically append rendered field to DOM.
* *
...@@ -79,7 +30,7 @@ ...@@ -79,7 +30,7 @@
suboptions = { suboptions = {
hide_enabled: form_definition.hide_enabled, // listbox specific hide_enabled: form_definition.hide_enabled, // listbox specific
extended_search: form_definition.extended_search, // searchfield specific extended_search: form_definition.extended_search, // searchfield specific
field_url: getFieldTypeGadgetUrl(rendered_document[field_name].type), field_type: rendered_document[field_name].type,
label: ((group_name !== "bottom") && (rendered_document[field_name].title.length > 0)), // no label for bottom group and field without title label: ((group_name !== "bottom") && (rendered_document[field_name].title.length > 0)), // no label for bottom group and field without title
field_json: rendered_document[field_name] // pass field_json: rendered_document[field_name] // pass
}; };
...@@ -111,9 +62,11 @@ ...@@ -111,9 +62,11 @@
// 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_type === 'ListBox') {
form_gadget.props.listbox_gadget = label_gadget; form_gadget.props.listbox_gadget = label_gadget;
} }
// gadget_list hold references to all created gadgets
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);
...@@ -169,9 +122,6 @@ ...@@ -169,9 +122,6 @@
editable: undefined editable: undefined
}) })
.allowPublicAcquisition("getFieldTypeGadgetUrl", function (param_list) {
return getFieldTypeGadgetUrl(param_list[0]);
})
.allowPublicAcquisition("getFormContent", function (param_list) { .allowPublicAcquisition("getFormContent", function (param_list) {
return this.getContent(param_list[0]); return this.getContent(param_list[0]);
}) })
......
...@@ -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.18982.46006.23483</string> </value> <value> <string>961.37896.39526.64290</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>1502268077.5</float> <float>1503478842.83</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -16,6 +16,59 @@ ...@@ -16,6 +16,59 @@
var SCOPE = 'field'; var SCOPE = 'field';
function getFieldTypeGadgetUrl(field_type) {
var field_url = 'gadget_erp5_field_readonly.html';
if (field_type === 'ListField') {
field_url = 'gadget_erp5_field_list.html';
} else if ((field_type === 'ParallelListField') ||
(field_type === 'MultiListField')) {
field_url = 'gadget_erp5_field_multilist.html';
} else if (field_type === 'CheckBoxField') {
field_url = 'gadget_erp5_field_checkbox.html';
} else if (field_type === 'MultiCheckBoxField') {
field_url = 'gadget_erp5_field_multicheckbox.html';
} else if (field_type === 'StringField') {
field_url = 'gadget_erp5_field_string.html';
} else if (field_type === 'LinesField') {
field_url = 'gadget_erp5_field_lines.html';
} else if (field_type === 'PasswordField') {
field_url = 'gadget_erp5_field_password.html';
} else if (field_type === 'RelationStringField') {
field_url = 'gadget_erp5_field_relationstring.html';
} else if (field_type === 'MultiRelationStringField') {
field_url = 'gadget_erp5_field_multirelationstring.html';
} else if (field_type === 'TextAreaField') {
field_url = 'gadget_erp5_field_textarea.html';
} else if (field_type === 'DateTimeField') {
field_url = 'gadget_erp5_field_datetime.html';
} else if (field_type === 'FloatField') {
field_url = 'gadget_erp5_field_float.html';
} else if (field_type === 'FileField') {
field_url = 'gadget_erp5_field_file.html';
} else if (field_type === 'IntegerField') {
field_url = 'gadget_erp5_field_integer.html';
} else if (field_type === 'ListBox') {
field_url = 'gadget_erp5_field_listbox.html';
} else if (field_type === 'EditorField') {
field_url = 'gadget_erp5_field_editor.html';
// field_url = 'gadget_codemirror.html';
// sandbox = 'iframe';
} else if (field_type === 'GadgetField') {
field_url = 'gadget_erp5_field_gadget.html';
} else if (field_type === 'RadioField') {
field_url = 'gadget_erp5_field_radio.html';
} else if (field_type === 'ImageField') {
field_url = 'gadget_erp5_field_image.html';
} else if (field_type === 'EmailField') {
field_url = 'gadget_erp5_field_email.html';
} else if (field_type === 'FormBox') {
field_url = 'gadget_erp5_field_formbox.html';
} else if (field_type === 'MatrixBox') {
field_url = 'gadget_erp5_field_matrixbox.html';
}
return field_url;
}
rJS(window) rJS(window)
.setState({ .setState({
label_text: '', label_text: '',
...@@ -35,7 +88,7 @@ ...@@ -35,7 +88,7 @@
var state_dict = { var state_dict = {
label_text: options.field_json.title || '', label_text: options.field_json.title || '',
label: options.label, label: options.label,
field_url: options.field_url, field_url: getFieldTypeGadgetUrl(options.field_type),
error_text: options.field_json.error_text || '', error_text: options.field_json.error_text || '',
options: options, options: options,
scope: options.field_json.key, scope: options.field_json.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>961.17833.11141.14523</string> </value> <value> <string>961.46539.43459.6519</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>1502198959.61</float> <float>1503932157.58</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -50,13 +50,13 @@ ...@@ -50,13 +50,13 @@
gadget.props.cell_gadget_list = []; gadget.props.cell_gadget_list = [];
function renderSubCell(element, sub_field_json) { function renderSubCell(element, sub_field_json) {
sub_field_json.editable = sub_field_json.editable && gadget.state.editable; // XXX sub_field_json.editable = sub_field_json.editable && gadget.state.editable; // XXX
return gadget.getFieldTypeGadgetUrl(sub_field_json.type) return gadget.declareGadget('gadget_erp5_label_field.html', {element: element, scope: sub_field_json.key})
.push(function (gadget_url) {
return gadget.declareGadget(gadget_url, {element: element});
})
.push(function (cell_gadget) { .push(function (cell_gadget) {
gadget.props.cell_gadget_list.push(cell_gadget); gadget.props.cell_gadget_list.push(cell_gadget);
return cell_gadget.render({field_json: sub_field_json}); return cell_gadget.render({
field_type: sub_field_json.type,
field_json: sub_field_json,
label: false});
}); });
} }
for (i = 0; i < element_list.length; i += 1) { for (i = 0; i < element_list.length; i += 1) {
...@@ -144,7 +144,6 @@ ...@@ -144,7 +144,6 @@
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter") .declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getFieldTypeGadgetUrl", "getFieldTypeGadgetUrl")
.declareAcquiredMethod("renderEditorPanel", "renderEditorPanel") .declareAcquiredMethod("renderEditorPanel", "renderEditorPanel")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("translate", "translate") .declareAcquiredMethod("translate", "translate")
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>960.57664.50157.3293</string> </value> <value> <string>961.37896.32571.61832</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1500656708.46</float> <float>1503406544.43</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