From 631ab1f6136f7c8bb007d2aaa053675adbcdf328 Mon Sep 17 00:00:00 2001 From: Julien Muchembled Date: Wed, 1 Jun 2016 21:44:48 +0200 Subject: [PATCH] ERP5Form: new gadget boolean option to serialize value to JSON --- .../erp5_xhtml_style/erp5_gadgetfield.js.js | 7 +++++++ .../erp5_xhtml_style/erp5_gadgetfield.js.xml | 4 ++-- product/ERP5Form/GadgetField.py | 13 ++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.js b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.js index 9fe50f5bcb8..59eff8a15d7 100644 --- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.js +++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.js @@ -63,6 +63,13 @@ url = list_gadget[i].getAttribute("data-gadget-url"); key = list_gadget[i].getAttribute("data-gadget-editable"); 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 if (url !== undefined && url !== null) { tmp = {}; diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.xml b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.xml index 55d80b52809..3a4d619034f 100644 --- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.xml +++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/erp5_gadgetfield.js.xml @@ -12,7 +12,7 @@ _EtagSupport__etag - ts64799067.07 + ts64810256.53 __name__ @@ -28,7 +28,7 @@ size - 7383 + 7642 title diff --git a/product/ERP5Form/GadgetField.py b/product/ERP5Form/GadgetField.py index 9167ad6243a..66d931e8fba 100644 --- a/product/ERP5Form/GadgetField.py +++ b/product/ERP5Form/GadgetField.py @@ -4,6 +4,7 @@ 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): """ @@ -11,9 +12,16 @@ class GadgetWidget(Widget.Widget): """ property_names = Widget.Widget.property_names + \ ['gadget_url', 'js_sandbox', 'extra'] + property_names.insert(property_names.index('default') + 1, 'json_value') 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', title='Gadget Url', description=("The url of the html page containing the \ @@ -34,8 +42,11 @@ class GadgetWidget(Widget.Widget): kw = { 'data-gadget-sandbox': field.get_value('js_sandbox'), '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: kw['data-gadget-editable'] = key return Widget.render_element("div", extra=field.get_value('extra'), **kw) -- 2.30.9