Updated illustrations views
authorThierry Florac <thierry.florac@onf.fr>
Tue, 09 Oct 2018 15:05:38 +0200
changeset 1005 107406cb705c
parent 1004 ca57b160d863
child 1006 cbb65b4b8742
Updated illustrations views
src/pyams_content/component/illustration/__init__.py
src/pyams_content/component/illustration/zmi/__init__.py
src/pyams_content/component/illustration/zmi/paragraph.py
--- a/src/pyams_content/component/illustration/__init__.py	Tue Oct 09 09:00:12 2018 +0200
+++ b/src/pyams_content/component/illustration/__init__.py	Tue Oct 09 15:05:38 2018 +0200
@@ -23,7 +23,6 @@
 from zope.schema.fieldproperty import FieldProperty
 from zope.traversing.interfaces import ITraversable
 
-from pyams_content import _
 from pyams_content.component.illustration.interfaces import BASIC_ILLUSTRATION_KEY, IBasicIllustration, \
     IBasicIllustrationTarget, IIllustration, IIllustrationTarget, IIllustrationTargetBase, ILLUSTRATION_KEY, \
     ILLUSTRATION_RENDERERS, ILinkIllustration, ILinkIllustrationTarget, LINK_ILLUSTRATION_KEY
@@ -40,6 +39,8 @@
 from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
 
+from pyams_content import _
+
 
 @implementer(IBasicIllustration)
 @factory_config(provided=IBasicIllustration)
--- a/src/pyams_content/component/illustration/zmi/__init__.py	Tue Oct 09 09:00:12 2018 +0200
+++ b/src/pyams_content/component/illustration/zmi/__init__.py	Tue Oct 09 15:05:38 2018 +0200
@@ -9,37 +9,35 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from zope.interface import implementer
-
-from pyams_content.skin import pyams_content
-from pyams_form.security import ProtectedFormObjectMixin
-from pyams_skin.viewlet.toolbar import JsToolbarAction
-from pyams_utils.fanstatic import get_resource_path
-from pyams_utils.interfaces.data import IObjectData
-
 
 __docformat__ = 'restructuredtext'
 
 from transaction.interfaces import ITransactionManager
 from z3c.form import field
+from zope.interface import implementer
 
-from pyams_content import _
 from pyams_content.component.illustration.interfaces import IBasicIllustration, IBasicIllustrationTarget, \
     IIllustration, IIllustrationTarget, ILinkIllustrationTarget
-# import packages
 from pyams_content.component.illustration.zmi.paragraph import ParagraphContainerIllustrationMarker
 from pyams_content.component.paragraph import IBaseParagraph
 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
+from pyams_content.skin import pyams_content
 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
+from pyams_form.security import ProtectedFormObjectMixin
 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
 from pyams_skin.layer import IPyAMSLayer
+from pyams_skin.viewlet.toolbar import JsToolbarAction
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import viewlet_config, Viewlet, EmptyViewlet
+from pyams_utils.fanstatic import get_resource_path
+from pyams_utils.interfaces.data import IObjectData
+from pyams_viewlet.viewlet import EmptyViewlet, Viewlet, viewlet_config
 from pyams_zmi.form import InnerAdminEditForm
 from pyams_zmi.interfaces import IPropertiesEditForm
 
+from pyams_content import _
+
 
 #
 # Illustration properties inner edit form
@@ -54,10 +52,8 @@
 
     css_class = 'form-group'
     padding_class = ''
-    # fieldset_class = 'bordered margin-top-10 padding-y-5'
 
     legend = _("Illustration")
-    # legend_class = 'illustration switcher no-y-padding padding-right-10'
 
     fields = field.Fields(IBasicIllustration).omit('__parent__', '__name__')
 
@@ -95,12 +91,22 @@
 
     def get_ajax_output(self, changes):
         output = super(BasicIllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
+        events = output.setdefault('events', [])
         updated = changes.get(IBasicIllustration, ())
         if 'data' in updated:
             # we have to commit transaction to be able to handle blobs...
             ITransactionManager(self.context).get().commit()
-            output.setdefault('events', []).append(
-                get_json_form_refresh_event(self.context, self.request, self.__class__))
+            if IBaseParagraph.providedBy(self.context):
+                if self.getContent().data:
+                    events.append(
+                        get_json_paragraph_markers_refresh_event(self.context, self.request, self,
+                                                                 ParagraphContainerIllustrationMarker))
+                else:
+                    events.append(
+                        get_json_paragraph_markers_refresh_event(self.context, self.request, self,
+                                                                 EmptyViewlet,
+                                                                 ParagraphContainerIllustrationMarker.marker_type))
+            events.append(get_json_form_refresh_event(self.context, self.request, self.__class__))
         return output
 
 
@@ -128,19 +134,10 @@
 
     def get_ajax_output(self, changes):
         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
-        events = output.setdefault('events', [])
-        if 'data' in changes.get(IBasicIllustration, ()):
-            if IBaseParagraph.providedBy(self.context):
-                if self.getContent().data:
-                    events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
-                                                                           ParagraphContainerIllustrationMarker))
-                else:
-                    events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
-                                                                           EmptyViewlet,
-                                                                           ParagraphContainerIllustrationMarker.marker_type))
-        elif 'renderer' in changes.get(IIllustration, ()):
-            events.append(get_json_widget_refresh_event(self.context, self.request,
-                                                        IllustrationPropertiesInnerEditForm, 'renderer'))
+        if 'renderer' in changes.get(IIllustration, ()):
+            output.setdefault('events', []).append(
+                get_json_widget_refresh_event(self.context, self.request,
+                                              IllustrationPropertiesInnerEditForm, 'renderer'))
         return output
 
 
@@ -162,7 +159,7 @@
 
 
 @viewlet_config(name='add-illustration.action', context=IBasicIllustrationTarget, layer=IPyAMSLayer,
-                view=IllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
+                view=BasicIllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
 @implementer(IObjectData)
 class AddIllustrationAction(ProtectedFormObjectMixin, JsToolbarAction):
     """Add illustration action"""
--- a/src/pyams_content/component/illustration/zmi/paragraph.py	Tue Oct 09 09:00:12 2018 +0200
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py	Tue Oct 09 15:05:38 2018 +0200
@@ -17,8 +17,8 @@
 from z3c.form.interfaces import INPUT_MODE
 from zope.interface import implementer
 
-from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationParagraph, IIllustrationTarget, \
-    ILLUSTRATION_PARAGRAPH_TYPE
+from pyams_content.component.illustration.interfaces import IBasicIllustrationTarget, IIllustration, \
+    IIllustrationParagraph, ILLUSTRATION_PARAGRAPH_TYPE
 from pyams_content.component.illustration.paragraph import Illustration
 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
@@ -141,7 +141,7 @@
 # Paragraph container illustration marker
 #
 
-@viewlet_config(name='illustration', context=IIllustrationTarget, layer=IPyAMSLayer, view=IParagraphContainerTable,
+@viewlet_config(name='illustration', context=IBasicIllustrationTarget, layer=IPyAMSLayer, view=IParagraphContainerTable,
                 manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=5)
 @template_config(template='templates/paragraph-illustration-icon.pt', layer=IPyAMSLayer)
 class ParagraphContainerIllustrationMarker(Viewlet):