Updated preview management
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 08:40:13 +0200
changeset 229 c9e2d01b0f8b
parent 228 f70686f44c7b
child 230 dabf155776a9
Updated preview management
src/pyams_content/shared/form/zmi/preview.py
src/pyams_content/shared/form/zmi/summary.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/form/zmi/preview.py	Fri Oct 13 08:40:13 2017 +0200
@@ -0,0 +1,93 @@
+#
+# Copyright (c) 2008-2015 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_content.shared.common.interfaces.zmi import IPreviewForm
+from pyams_content.shared.form.interfaces import IFormFieldContainerTarget, IFormFieldContainer
+from pyams_form.interfaces.form import IFormHelp, IWidgetsSuffixViewletsManager
+from pyams_i18n.interfaces import II18n
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+
+# import packages
+from pyams_form.help import FormHelp
+from pyams_utils.adapter import adapter_config
+from pyams_viewlet.viewlet import viewlet_config, Viewlet
+from pyams_zmi.form import InnerAdminAddForm
+from z3c.form import field, button
+from zope.interface import Interface
+
+
+class FormFieldContainerPreviewDisplayForm(InnerAdminAddForm):
+    """Form fields container preview display form"""
+
+    @property
+    def legend(self):
+        return II18n(self.context).query_attribute('user_title', request=self.request)
+
+    @property
+    def fields(self):
+        fields = field.Fields(*IFormFieldContainer(self.context).get_fields())
+        if self.context.use_captcha:
+            # TODO: add captcha
+            # fields += field.Fields(Captcha(title='', description='', required=True))
+            pass
+        return fields
+
+    buttons = button.Buttons(Interface)
+
+    def updateWidgets(self, prefix=None):
+        super(FormFieldContainerPreviewDisplayForm, self).updateWidgets(prefix)
+        for widget in self.widgets.values():
+            field = IFormFieldContainer(self.context).get(widget.field.__name__)
+            if field is not None:
+                widget.placeholder = field.placeholder
+                if field.field_type == 'text':
+                    widget.widget_css_class = 'textarea'
+
+
+@adapter_config(context=(IFormFieldContainerTarget, IPyAMSLayer, FormFieldContainerPreviewDisplayForm), provides=IFormHelp)
+class FormFieldContainerPreviewHelp(FormHelp):
+    """Form field container preview help adapter"""
+
+    def __new__(cls, context, request, view):
+        if not context.header:
+            return None
+        return FormHelp.__new__(cls)
+
+    @property
+    def message(self):
+        return II18n(self.context).query_attribute('header', request=self.request)
+
+    message_format = 'text'
+
+
+@viewlet_config(name='form-fields-preview', context=IFormFieldContainerTarget, layer=IPyAMSLayer,
+                view=IPreviewForm, manager=IWidgetsSuffixViewletsManager,
+                permission=VIEW_SYSTEM_PERMISSION, weight=80)
+class FormFieldContainerPreview(Viewlet):
+    """Form field container preview"""
+
+    display_form = None
+
+    def update(self):
+        super(FormFieldContainerPreview, self).update()
+        self.display_form = FormFieldContainerPreviewDisplayForm(self.context, self.request)
+        self.display_form.update()
+
+    def render(self):
+        return self.display_form.render()
--- a/src/pyams_content/shared/form/zmi/summary.py	Fri Oct 13 08:39:29 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-#
-# Copyright (c) 2008-2015 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_content.shared.common.interfaces.zmi import IInnerSummaryView
-from pyams_content.shared.form.interfaces import IFormFieldContainerTarget, IFormFieldContainer
-from pyams_form.interfaces.form import IInnerTabForm, IFormHelp
-from pyams_i18n.interfaces import II18n
-from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
-
-# import packages
-from pyams_content.shared.common.zmi.summary import SharedContentSummaryForm
-from pyams_form.help import FormHelp
-from pyams_pagelet.pagelet import pagelet_config
-from pyams_utils.adapter import adapter_config
-from pyams_zmi.form import InnerAdminDisplayForm, InnerAdminAddForm
-from z3c.form import field, button
-from zope.interface import implementer, Interface
-
-from pyams_content import _
-
-
-@adapter_config(name='form-fields-summary',
-                context=(IFormFieldContainerTarget, IPyAMSLayer, SharedContentSummaryForm),
-                provides=IInnerTabForm)
-class FormFieldContainerSummary(InnerAdminDisplayForm):
-    """Form fields container summary"""
-
-    weight = 20
-    tab_label = _("Quick preview")
-    tab_target = 'form-fields-summary.html'
-
-    fields = field.Fields(Interface)
-
-
-@pagelet_config(name='form-fields-summary.html', context=IFormFieldContainerTarget, layer=IPyAMSLayer,
-                permission=VIEW_SYSTEM_PERMISSION)
-@implementer(IInnerSummaryView)
-class FormFieldContainerSummaryView(InnerAdminAddForm):
-    """Form fields container summary view"""
-
-    @property
-    def legend(self):
-        return II18n(self.context).query_attribute('user_title', request=self.request)
-
-    @property
-    def fields(self):
-        fields = field.Fields(*IFormFieldContainer(self.context).get_fields())
-        if self.context.use_captcha:
-            # TODO: add captcha
-            # fields += field.Fields(Captcha(title='', description='', required=True))
-            pass
-        return fields
-
-    buttons = button.Buttons(Interface)
-
-    def updateWidgets(self, prefix=None):
-        super(FormFieldContainerSummaryView, self).updateWidgets(prefix)
-        for widget in self.widgets.values():
-            field = IFormFieldContainer(self.context).get(widget.field.__name__)
-            if field is not None:
-                widget.placeholder = field.placeholder
-                if field.field_type == 'text':
-                    widget.widget_css_class = 'textarea'
-
-
-@adapter_config(context=(IFormFieldContainerTarget, IPyAMSLayer, FormFieldContainerSummaryView), provides=IFormHelp)
-class FormFieldContainerSummaryHelp(FormHelp):
-    """Form field container summary help adapter"""
-
-    def __new__(cls, context, request, view):
-        if not context.header:
-            return None
-        return FormHelp.__new__(cls)
-
-    @property
-    def message(self):
-        return II18n(self.context).query_attribute('header', request=self.request)
-
-    message_format = 'text'