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