Added "navigation" illustration to contents
authorThierry Florac <thierry.florac@onf.fr>
Fri, 15 Jun 2018 18:18:16 +0200
changeset 694 4541a452fd4c
parent 693 26d51b558325
child 695 096cfad5eeb5
Added "navigation" illustration to contents
src/pyams_content/component/illustration/__init__.py
src/pyams_content/component/illustration/interfaces/__init__.py
src/pyams_content/component/illustration/zmi/__init__.py
src/pyams_content/component/illustration/zmi/paragraph.py
src/pyams_content/shared/blog/__init__.py
src/pyams_content/shared/blog/manager.py
src/pyams_content/shared/news/__init__.py
src/pyams_content/shared/site/__init__.py
src/pyams_content/shared/site/folder.py
src/pyams_content/shared/site/manager.py
--- a/src/pyams_content/component/illustration/__init__.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/component/illustration/__init__.py	Fri Jun 15 18:18:16 2018 +0200
@@ -17,7 +17,8 @@
 
 # import interfaces
 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget, \
-    ILLUSTRATION_KEY, ILLUSTRATION_RENDERERS, IBasicIllustration, IBasicIllustrationTarget, BASIC_ILLUSTRATION_KEY
+    ILLUSTRATION_KEY, ILLUSTRATION_RENDERERS, IBasicIllustration, IBasicIllustrationTarget, BASIC_ILLUSTRATION_KEY, \
+    ILinkIllustrationTarget, LINK_ILLUSTRATION_KEY, ILinkIllustration
 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
 from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage
 from pyams_i18n.interfaces import INegotiator, II18n, II18nManager
@@ -109,6 +110,20 @@
                                   callback=illustration_callback)
 
 
+@adapter_config(context=ILinkIllustrationTarget, provides=ILinkIllustration)
+@adapter_config(name='link', context=ILinkIllustrationTarget, provides=IIllustration)
+def link_illustration_factory(context):
+    """Link illustration factory"""
+
+    def illustration_callback(illustration):
+        get_current_registry().notify(ObjectAddedEvent(illustration, context, illustration.__name__))
+
+    return get_annotation_adapter(context, LINK_ILLUSTRATION_KEY, BasicIllustration,
+                                  markers=ILinkIllustration,
+                                  name='++illustration++link',
+                                  callback=illustration_callback)
+
+
 def update_illustration_properties(illustration):
     """Update missing file properties"""
     request = check_request()
--- a/src/pyams_content/component/illustration/interfaces/__init__.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/component/illustration/interfaces/__init__.py	Fri Jun 15 18:18:16 2018 +0200
@@ -37,6 +37,8 @@
 ILLUSTRATION_KEY = 'pyams_content.illustration'
 ILLUSTRATION_RENDERERS = 'PyAMS.illustration.renderers'
 
+LINK_ILLUSTRATION_KEY = '{0}::link'.format(ILLUSTRATION_KEY)
+
 
 class IBasicIllustration(Interface):
     """Basic illustration interface"""
@@ -73,6 +75,10 @@
                       default='default')
 
 
+class ILinkIllustration(IBasicIllustration):
+    """Navigation link illustration interface"""
+
+
 class IBasicIllustrationTarget(IAttributeAnnotatable):
     """Basic illustration target marker interface"""
 
@@ -81,6 +87,14 @@
     """Illustration target interface"""
 
 
+class ILinkIllustrationTarget(IBasicIllustrationTarget):
+    """Link illustration target interface"""
+
+
+#
+# Illustration paragraph
+#
+
 ILLUSTRATION_PARAGRAPH_TYPE = 'Illustration'
 ILLUSTRATION_PARAGRAPH_NAME = _("Illustration")
 
--- a/src/pyams_content/component/illustration/zmi/__init__.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/component/illustration/zmi/__init__.py	Fri Jun 15 18:18:16 2018 +0200
@@ -17,16 +17,15 @@
 
 # import interfaces
 from pyams_content.component.illustration.interfaces import IBasicIllustration, IBasicIllustrationTarget, \
-    IIllustration, IIllustrationTarget
+    IIllustration, IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.component.paragraph import IBaseParagraph
-from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
 from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_zmi.interfaces import IPropertiesEditForm
 from transaction.interfaces import ITransactionManager
 
 # import packages
+from pyams_content.component.illustration.zmi.paragraph import ParagraphContainerIllustrationMarker
 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
@@ -43,41 +42,19 @@
 # Illustration properties inner edit form
 #
 
-@viewlet_config(name='illustration', context=IIllustrationTarget, 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):
-    """Paragraph container illustration marker column"""
-
-    weight = 5
-    action_class = 'action illustration nowrap width-40'
-    icon_class = 'fa fa-fw fa-picture-o'
-    icon_hint = _("Illustration")
-
-    marker_type = 'illustration'
-
-    def render(self):
-        illustration = IIllustration(self.context, None)
-        if illustration and illustration.data:
-            for value in illustration.data.values():
-                if value:
-                    return super(ParagraphContainerIllustrationMarker, self).render()
-        return ''
-
-
 @adapter_config(name='illustration', context=(IBasicIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
                 provides=IInnerSubForm)
 class BasicIllustrationPropertiesInnerEditForm(InnerAdminEditForm):
     """Basic illustration properties inner edit form"""
 
-    prefix = 'illustration_form.'
+    prefix = 'basic_illustration_form.'
 
     css_class = 'form-group'
     padding_class = ''
-    fieldset_class = 'margin-top-10 padding-y-5'
+    fieldset_class = 'bordered margin-top-10 padding-y-5'
 
     legend = _("Illustration")
-    legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto'
+    legend_class = 'illustration switcher no-y-padding padding-right-10'
 
     fields = field.Fields(IBasicIllustration).omit('__parent__', '__name__')
 
@@ -93,18 +70,17 @@
     @property
     def switcher_state(self):
         content = self.getContent()
-        for value in (content.data or {}).values():
-            if value:
-                return 'open'
+        if content.has_data():
+            return 'open'
 
     def get_ajax_output(self, changes):
         output = super(BasicIllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
-        updated = changes.get(IIllustration, ())
-        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()
-            events.append(get_json_form_refresh_event(self.context, self.request, self.__class__))
+            output.setdefault('events', []).append(
+                get_json_form_refresh_event(self.context, self.request, self.__class__))
         return output
 
 
@@ -113,6 +89,11 @@
 class IllustrationPropertiesInnerEditForm(BasicIllustrationPropertiesInnerEditForm):
     """Illustration properties inner edit form"""
 
+    prefix = 'illustration_form.'
+
+    fields = field.Fields(IIllustration).omit('__parent__', '__name__')
+    fields['renderer'].widgetFactory = RendererFieldWidget
+
     @property
     def legend(self):
         if IBaseParagraph.providedBy(self.context):
@@ -125,13 +106,22 @@
         if IBaseParagraph.providedBy(self.context):
             return 'illustration switcher no-y-padding padding-right-10 pull-left width-auto'
         else:
-            return 'illustration no-y-padding'
+            return 'illustration switcher no-y-padding'
 
-    fields = field.Fields(IIllustration).omit('__parent__', '__name__')
-    fields['renderer'].widgetFactory = RendererFieldWidget
+    @property
+    def fieldset_class(self):
+        result = 'margin-top-10 padding-y-5'
+        if not IBaseParagraph.providedBy(self.context):
+            result += ' bordered'
+        return result
 
     hide_widgets_prefix_div = True
 
+    @property
+    def switcher_state(self):
+        if not IBaseParagraph.providedBy(self.context):
+            return 'open'
+
     def updateWidgets(self, prefix=None):
         super(IllustrationPropertiesInnerEditForm, self).updateWidgets(prefix)
         if 'description' in self.widgets:
@@ -139,9 +129,8 @@
 
     def get_ajax_output(self, changes):
         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
-        updated = changes.get(IIllustration, ())
         events = output.setdefault('events', [])
-        if 'data' in updated:
+        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,
@@ -150,12 +139,29 @@
                     events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
                                                                            EmptyViewlet,
                                                                            ParagraphContainerIllustrationMarker.marker_type))
-        elif 'renderer' in updated:
+        elif 'renderer' in changes.get(IIllustration, ()):
             events.append(get_json_widget_refresh_event(self.context, self.request,
                                                         IllustrationPropertiesInnerEditForm, 'renderer'))
         return output
 
 
+@adapter_config(name='link-illustration', context=(ILinkIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
+                provides=IInnerSubForm)
+class LinkIllustrationPropertiesInnerEditForm(BasicIllustrationPropertiesInnerEditForm):
+    """Link illustration properties inner edit form"""
+
+    prefix = 'link_illustration_form.'
+
+    legend = _("Navigation link illustration")
+    legend_class = 'illustration switcher no-y-padding'
+
+    weight = 11
+
+    def getContent(self):
+        registry = self.request.registry
+        return registry.getAdapter(self.context, IIllustration, name='link')
+
+
 @viewlet_config(name='illustration-thumbnail', context=IBasicIllustrationTarget, layer=IPyAMSLayer,
                 view=BasicIllustrationPropertiesInnerEditForm, manager=IWidgetsPrefixViewletsManager)
 @template_config(template='templates/illustration-thumbnail.pt', layer=IPyAMSLayer)
--- a/src/pyams_content/component/illustration/zmi/paragraph.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py	Fri Jun 15 18:18:16 2018 +0200
@@ -18,13 +18,15 @@
 # import interfaces
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, \
     IParagraphContainer
-from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationParagraph, \
-    ILLUSTRATION_PARAGRAPH_TYPE
-from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView
+from pyams_content.component.illustration.interfaces import IIllustrationTarget, IIllustration, \
+    IIllustrationParagraph, ILLUSTRATION_PARAGRAPH_TYPE
+from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphContainerView, \
+    IParagraphContainerTable, IParagraphTitleToolbar
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_form.interfaces.form import IInnerForm
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from transaction.interfaces import ITransactionManager
 from z3c.form.interfaces import INPUT_MODE
 
@@ -36,8 +38,9 @@
 from pyams_form.form import ajax_config
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.event import get_json_form_refresh_event
+from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import viewlet_config
+from pyams_viewlet.viewlet import viewlet_config, Viewlet
 from pyams_zmi.form import AdminDialogAddForm
 from z3c.form import field, button
 from zope.interface import implementer
@@ -147,3 +150,29 @@
             output.setdefault('events', []).append(get_json_form_refresh_event(self.context, self.request,
                                                                                IllustrationInnerEditForm))
         return output
+
+
+#
+# Paragraph container illustration marker
+#
+
+@viewlet_config(name='illustration', context=IIllustrationTarget, 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):
+    """Paragraph container illustration marker column"""
+
+    weight = 5
+    action_class = 'action illustration nowrap width-40'
+    icon_class = 'fa fa-fw fa-picture-o'
+    icon_hint = _("Illustration")
+
+    marker_type = 'illustration'
+
+    def render(self):
+        illustration = IIllustration(self.context, None)
+        if illustration and illustration.data:
+            for value in illustration.data.values():
+                if value:
+                    return super(ParagraphContainerIllustrationMarker, self).render()
+        return ''
--- a/src/pyams_content/shared/blog/__init__.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/shared/blog/__init__.py	Fri Jun 15 18:18:16 2018 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration import IIllustrationTarget
+from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
 from pyams_content.component.theme.interfaces import IThemesTarget
 from pyams_content.features.preview.interfaces import IPreviewTarget
@@ -32,7 +32,7 @@
 
 
 @implementer(IWfBlogPost, IParagraphContainerTarget, IThemesTarget, IIllustrationTarget,
-             IPreviewTarget, IReviewTarget)
+             ILinkIllustrationTarget, IPreviewTarget, IReviewTarget)
 class WfBlogPost(WfSharedContent):
     """Base blog post"""
 
--- a/src/pyams_content/shared/blog/manager.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/shared/blog/manager.py	Fri Jun 15 18:18:16 2018 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration import IIllustrationTarget
+from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.component.paragraph.interfaces import IParagraphFactorySettings
 from pyams_content.component.theme.interfaces import IThemesManagerTarget
 from pyams_content.features.footer.interfaces import IFooterTarget
@@ -54,7 +54,7 @@
 
 
 @implementer(IBlogManager, IParagraphFactorySettings, IThemesManagerTarget, IPictogramManagerTarget,
-             IIllustrationTarget, IHeaderTarget, IFooterTarget, IPortalContext, IPreviewTarget)
+             IIllustrationTarget, ILinkIllustrationTarget, IHeaderTarget, IFooterTarget, IPortalContext, IPreviewTarget)
 class BlogManager(Folder, BaseSharedTool, UserSkinnableContent):
     """Nlog manager class"""
 
--- a/src/pyams_content/shared/news/__init__.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/shared/news/__init__.py	Fri Jun 15 18:18:16 2018 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration import IIllustrationTarget
+from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
 from pyams_content.component.theme.interfaces import IThemesTarget
 from pyams_content.features.preview.interfaces import IPreviewTarget
@@ -30,7 +30,7 @@
 from zope.interface import implementer, provider
 
 
-@implementer(IWfNewsEvent, IIllustrationTarget, IParagraphContainerTarget, IThemesTarget,
+@implementer(IWfNewsEvent, IIllustrationTarget, ILinkIllustrationTarget, IParagraphContainerTarget, IThemesTarget,
              IPreviewTarget, IReviewTarget)
 class WfNewsEvent(WfSharedContent):
     """Base news event"""
--- a/src/pyams_content/shared/site/__init__.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/shared/site/__init__.py	Fri Jun 15 18:18:16 2018 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration import IIllustrationTarget
+from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
 from pyams_content.component.theme.interfaces import IThemesTarget
 from pyams_content.features.preview.interfaces import IPreviewTarget
@@ -31,8 +31,8 @@
 from zope.interface import implementer, provider
 
 
-@implementer(IWfTopic, IIllustrationTarget, IParagraphContainerTarget, IThemesTarget,
-             IPreviewTarget, IReviewTarget)
+@implementer(IWfTopic, IIllustrationTarget, ILinkIllustrationTarget, IParagraphContainerTarget,
+             IThemesTarget, IPreviewTarget, IReviewTarget)
 class WfTopic(WfSharedContent):
     """Base topic"""
 
--- a/src/pyams_content/shared/site/folder.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/shared/site/folder.py	Fri Jun 15 18:18:16 2018 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration import IIllustrationTarget
+from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.features.preview.interfaces import IPreviewTarget
 from pyams_content.interfaces import MANAGE_SITE_PERMISSION
 from pyams_content.shared.site.interfaces import ISiteFolder, ISiteManager, ISiteFolderRoles
@@ -44,7 +44,7 @@
 
 
 @implementer(IDefaultProtectionPolicy, ISiteFolder, ISiteFolderRoles,
-             IIllustrationTarget, IPortalContext, IPreviewTarget)
+             IIllustrationTarget, ILinkIllustrationTarget, IPortalContext, IPreviewTarget)
 class SiteFolder(SiteContainerMixin, OrderedContainer, BaseSharedTool):
     """Site folder persistent class"""
 
--- a/src/pyams_content/shared/site/manager.py	Fri Jun 15 15:29:30 2018 +0200
+++ b/src/pyams_content/shared/site/manager.py	Fri Jun 15 18:18:16 2018 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration import IIllustrationTarget
+from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
 from pyams_content.component.paragraph.interfaces import IParagraphFactorySettings
 from pyams_content.component.theme.interfaces import IThemesManagerTarget
 from pyams_content.features.footer.interfaces import IFooterTarget
@@ -52,7 +52,8 @@
 
 
 @implementer(ISiteManager, IParagraphFactorySettings, IThemesManagerTarget, IPictogramManagerTarget,
-             IIllustrationTarget, IPortalContext, IHeaderTarget, IFooterTarget, IPreviewTarget)
+             IIllustrationTarget, ILinkIllustrationTarget, IPortalContext, IHeaderTarget,
+             IFooterTarget, IPreviewTarget)
 class SiteManager(SiteContainerMixin, OrderedContainer, BaseSharedTool, UserSkinnableContent):
     """Site manager persistent class"""