Commit 631ab1f6 authored by Julien Muchembled's avatar Julien Muchembled

ERP5Form: new gadget boolean option to serialize value to JSON

parent 9e55f4aa
...@@ -63,6 +63,13 @@ ...@@ -63,6 +63,13 @@
url = list_gadget[i].getAttribute("data-gadget-url"); url = list_gadget[i].getAttribute("data-gadget-url");
key = list_gadget[i].getAttribute("data-gadget-editable"); key = list_gadget[i].getAttribute("data-gadget-editable");
value = list_gadget[i].getAttribute("data-gadget-value"); value = list_gadget[i].getAttribute("data-gadget-value");
if (value === null)
try {
value = JSON.parse(list_gadget[i].getAttribute("data-gadget-json"));
} catch(e) {
console.log(e); /* same remark as below (when render() fails) */
continue;
}
//renderable //renderable
if (url !== undefined && url !== null) { if (url !== undefined && url !== null) {
tmp = {}; tmp = {};
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts64799067.07</string> </value> <value> <string>ts64810256.53</string> </value>
</item> </item>
<item> <item>
<key> <string>__name__</string> </key> <key> <string>__name__</string> </key>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>7383</int> </value> <value> <int>7642</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
...@@ -4,6 +4,7 @@ from Products.Formulator.DummyField import fields ...@@ -4,6 +4,7 @@ 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):
""" """
...@@ -11,9 +12,16 @@ class GadgetWidget(Widget.Widget): ...@@ -11,9 +12,16 @@ class GadgetWidget(Widget.Widget):
""" """
property_names = Widget.Widget.property_names + \ property_names = Widget.Widget.property_names + \
['gadget_url', 'js_sandbox', 'extra'] ['gadget_url', 'js_sandbox', 'extra']
property_names.insert(property_names.index('default') + 1, 'json_value')
default = Widget.TextWidget.default default = Widget.TextWidget.default
json_value = fields.CheckBoxField('json_value',
title='JSON Value',
description='Serialize value to JSON.',
default=0,
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 \
...@@ -34,8 +42,11 @@ class GadgetWidget(Widget.Widget): ...@@ -34,8 +42,11 @@ class GadgetWidget(Widget.Widget):
kw = { kw = {
'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,
} }
if field.get_value('json_value'):
kw['data-gadget-json'] = dumps(value)
else:
kw['data-gadget-value'] = value
if key is not None: if key is not None:
kw['data-gadget-editable'] = key kw['data-gadget-editable'] = key
return Widget.render_element("div", extra=field.get_value('extra'), **kw) return Widget.render_element("div", extra=field.get_value('extra'), **kw)
......
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