Commit 1a176786 authored by Romain Courteaud's avatar Romain Courteaud

GadgetField: add renderjs_extra parameter

This allows to propagate more options to the render parameters, used in erp5_xhtml_style and erp5_web_renderjs_ui
parent 2da5f3c9
......@@ -295,6 +295,11 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
"url": field.get_value("gadget_url"),
"sandbox": field.get_value("js_sandbox")
})
try:
result["renderjs_extra"] = json.dumps(dict(field.get_value("renderjs_extra")))
except KeyError:
# Ensure compatibility if the products are not yet up to date
result["renderjs_extra"] = json.dumps({})
return result
if meta_type == "ListBox":
......
......@@ -9,6 +9,7 @@
return this.changeState({
key: options.field_json.key,
value: options.field_json.default,
renderjs_extra: options.field_json.renderjs_extra,
editable: options.field_json.editable,
url: options.field_json.url,
sandbox: options.field_json.sandbox || undefined,
......@@ -55,12 +56,17 @@
var gadget = this;
return gadget.getDeclaredGadget(gadget.state.key)
.push(function (result) {
return result.render({
key: gadget.state.key,
value: gadget.state.value,
editable: gadget.state.editable,
hidden: gadget.state.hidden
});
var render_kw;
try {
render_kw = JSON.parse(gadget.state.renderjs_extra);
} catch (e) {
render_kw = {};
}
render_kw.key = gadget.state.key;
render_kw.value = gadget.state.value;
render_kw.editable = gadget.state.editable;
render_kw.hidden = gadget.state.hidden;
return result.render(render_kw);
});
})
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.996.7923.46097</string> </value>
<value> <string>962.24020.58652.57139</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1497343012.54</float>
<float>1507901872.84</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -117,7 +117,8 @@
sandbox: field_element.getAttribute("data-gadget-sandbox"),
editable: (field_element.getAttribute("data-gadget-editable") !== null),
key: field_element.getAttribute("data-gadget-editable"),
value: field_element.getAttribute("data-gadget-value")
value: field_element.getAttribute("data-gadget-value"),
extra: field_element.getAttribute("data-gadget-renderjs-extra")
});
promise_list.push(gadget.getDeclaredGadget(field_scope));
}
......@@ -131,13 +132,23 @@
sub_element,
sub_value,
sub_key,
render_kw,
promise_list = [];
for (i = 0; i < field_list.length; i += 1) {
if (result_list[i].render !== undefined) {
sub_value = field_list[i].value;
sub_key = field_list[i].key;
try {
render_kw = JSON.parse(field_list[i].extra);
} catch (e) {
console.log(e); /* same remark as below (when render() fails) */
render_kw = {};
}
render_kw.key = sub_key;
render_kw.value = sub_value;
render_kw.editable = field_list[i].editable;
promise_list.push(
result_list[i].render({key: sub_key, value: sub_value, editable: field_list[i].editable})
result_list[i].render(render_kw)
.push(undefined, displayFieldError)
/* XXX Highlight the gadget element with a small colored
* error message. Clicking on the element could unroll
......
......@@ -4,16 +4,24 @@ from Products.Formulator.DummyField import fields
from Products.Formulator import Validator
from zLOG import LOG, ERROR
from cStringIO import StringIO
from json import dumps
class GadgetWidget(Widget.Widget):
"""
A widget that displays a renderjs gadget
"""
property_names = Widget.Widget.property_names + \
['gadget_url', 'js_sandbox', 'extra']
['gadget_url', 'js_sandbox', 'extra', 'renderjs_extra']
default = Widget.TextWidget.default
renderjs_extra = fields.ListTextAreaField('renderjs_extra',
title="RenderJS extra",
description=(
"More parameters passed to the renderJS's render method."),
default=[],
required=0)
gadget_url = fields.StringField('gadget_url',
title='Gadget Url',
description=("The url of the html page containing the \
......@@ -35,6 +43,7 @@ class GadgetWidget(Widget.Widget):
'data-gadget-sandbox': field.get_value('js_sandbox'),
'data-gadget-url': field.get_value('gadget_url'),
'data-gadget-value': value,
'data-gadget-renderjs-extra': dumps(dict(field.get_value('renderjs_extra')))
}
if key is not None:
kw['data-gadget-editable'] = key
......@@ -69,8 +78,8 @@ class GadgetFieldValidator(Validator.Validator):
validator_field_id = fields.StringField(
'validator_field_id',
title='Field ID',
description= "Field used to validate REQUEST form data.",
title='Validator Field ID',
description= "ID of the validator field.",
default="",
display_width=40,
required=0
......
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