--- a/src/pyams_portal/zmi/portlet.py Thu Jun 14 17:30:40 2018 +0200
+++ b/src/pyams_portal/zmi/portlet.py Thu Jun 14 17:33:55 2018 +0200
@@ -9,6 +9,8 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from pyams_form.form import ajax_config
+from pyams_pagelet.pagelet import pagelet_config
__docformat__ = 'restructuredtext'
@@ -17,10 +19,12 @@
# import interfaces
from pyams_form.interfaces.form import IInnerTabForm
-from pyams_portal.interfaces import IPortlet, IPortalTemplate, IPortalPage, MANAGE_TEMPLATE_PERMISSION
+from pyams_portal.interfaces import IPortlet, IPortalTemplate, IPortalPage, MANAGE_TEMPLATE_PERMISSION, \
+ IPortletSettings, IPortletRendererSettings
from pyams_skin.layer import IPyAMSLayer
# import packages
+from pyams_portal.zmi.widget import PortletRendererFieldWidget
from pyams_template.template import template_config
from pyams_utils.adapter import adapter_config
from pyams_utils.url import absolute_url
@@ -96,6 +100,35 @@
@property
def fields(self):
- return field.Fields(self.parent_form.settings).omit('__name__')
+ fields = field.Fields(self.parent_form.settings).omit('__name__', 'renderer') + \
+ field.Fields(self.parent_form.settings).select('renderer')
+ fields['renderer'].widgetFactory = PortletRendererFieldWidget
+ return fields
weight = 10
+
+
+#
+# Portlet renderer properties edit form
+#
+
+@pagelet_config(name='renderer-properties.html', context=IPortletSettings, layer=IPyAMSLayer,
+ permission=MANAGE_TEMPLATE_PERMISSION)
+@ajax_config(name='renderer-properties.json', context=IPortletSettings, layer=IPyAMSLayer)
+class PortletRendererPropertiesEditForm(AdminDialogEditForm):
+ """Portlet renderer properties edit form"""
+
+ prefix = 'portlet_renderer_properties.'
+
+ legend = _("Edit renderer properties")
+ icon_css_class = 'fa fa-fw fa-pencil-square-o'
+
+ @property
+ def fields(self):
+ renderer = self.context.get_renderer(self.request)
+ return field.Fields(renderer.settings_interface or Interface)
+
+ edit_permission = MANAGE_TEMPLATE_PERMISSION
+
+ def getContent(self):
+ return IPortletRendererSettings(self.context)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_portal/zmi/templates/renderer-input.pt Thu Jun 14 17:33:55 2018 +0200
@@ -0,0 +1,43 @@
+<label class="input bordered with-icon" i18n:domain="pyams_portal">
+ <tal:var define="render view/show_renderer_properties">
+ <i class="icon-append fa fa-fw fa-pencil-square-o text-primary hint align-base opaque"
+ title="Edit renderer properties" i18n:attributes="title"
+ data-ams-hint-gravity="se" data-toggle="modal"
+ tal:condition="render"
+ tal:attributes="data-ams-url extension:absolute_url(context, 'renderer-properties.html');"></i>
+ <i class="icon-append fa fa-fw fa-pencil-square-o opacity-25"
+ tal:condition="not:render"></i>
+ </tal:var>
+ <div class="select2-parent">
+ <select class="select2"
+ tal:attributes='id view/id;
+ name string:${view/name}:list;
+ class string:${view/klass} select2;
+ style view/style;
+ title view/title;
+ lang view/lang;
+ onclick view/onclick;
+ ondblclick view/ondblclick;
+ onmousedown view/onmousedown;
+ onmouseup view/onmouseup;
+ onmouseover view/onmouseover;
+ onmousemove view/onmousemove;
+ onmouseout view/onmouseout;
+ onkeypress view/onkeypress;
+ onkeydown view/onkeydown;
+ onkeyup view/onkeyup;
+ disabled view/disabled;
+ tabindex view/tabindex;
+ onfocus view/onfocus;
+ onblur view/onblur;
+ onchange view/onchange;
+ multiple view/multiple;
+ size view/size;
+ data-ams-data extension:object_data(view);'>
+ <option tal:repeat="entry view/items"
+ tal:attributes="value entry/value;
+ selected python:entry['value'] in view.value;"
+ tal:content="python:view.get_content(entry) if hasattr(view, 'get_content') else entry['content']"></option>
+ </select>
+ </div>
+</label>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_portal/zmi/widget.py Thu Jun 14 17:33:55 2018 +0200
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_form.interfaces import IFormLayer
+from z3c.form.interfaces import INPUT_MODE
+
+# import packages
+from pyams_form.widget import widgettemplate_config, Select2Widget
+from z3c.form.widget import FieldWidget
+
+
+@widgettemplate_config(mode=INPUT_MODE, template='templates/renderer-input.pt', layer=IFormLayer)
+class PortletRendererWidget(Select2Widget):
+ """Portlet renderer selection widget"""
+
+ @property
+ def show_renderer_properties(self):
+ renderer = self.context.get_renderer(self.request)
+ return (renderer is not None) and (renderer.settings_interface is not None)
+
+
+def PortletRendererFieldWidget(field, request):
+ return FieldWidget(field, PortletRendererWidget(request))