Added width and offset to image map paragraph default renderer settings
authorThierry Florac <tflorac@ulthar.net>
Mon, 21 Oct 2019 11:45:37 +0200
changeset 500 f07423f2dfc4
parent 499 b923f4cfa978
child 501 c07397edf78f
Added width and offset to image map paragraph default renderer settings
src/pyams_default_theme/locales/fr/LC_MESSAGES/pyams_default_theme.mo
src/pyams_default_theme/locales/fr/LC_MESSAGES/pyams_default_theme.po
src/pyams_default_theme/locales/pyams_default_theme.pot
src/pyams_default_theme/shared/imagemap/__init__.py
src/pyams_default_theme/shared/imagemap/interfaces.py
src/pyams_default_theme/shared/imagemap/templates/imagemap-default.pt
Binary file src/pyams_default_theme/locales/fr/LC_MESSAGES/pyams_default_theme.mo has changed
--- a/src/pyams_default_theme/locales/fr/LC_MESSAGES/pyams_default_theme.po	Fri Oct 18 16:56:20 2019 +0200
+++ b/src/pyams_default_theme/locales/fr/LC_MESSAGES/pyams_default_theme.po	Mon Oct 21 11:45:37 2019 +0200
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE 1.0\n"
-"POT-Creation-Date: 2019-10-18 15:15+0200\n"
+"POT-Creation-Date: 2019-10-21 11:30+0200\n"
 "PO-Revision-Date: 2017-06-07 12:41+0200\n"
 "Last-Translator: Thierry Florac <tflorac@ulthar.net>\n"
 "Language-Team: French\n"
@@ -952,10 +952,34 @@
 msgid "Four vertical panels with portrait illustrations"
 msgstr "Quatre panneaux verticaux avec illustrations en portrait"
 
-#: src/pyams_default_theme/shared/imagemap/__init__.py:52
+#: src/pyams_default_theme/shared/imagemap/__init__.py:77
 msgid "Default imagemap renderer"
 msgstr "Par défaut"
 
+#: src/pyams_default_theme/shared/imagemap/interfaces.py:25
+msgid "Paragraph width"
+msgstr "Largeur du bloc"
+
+#: src/pyams_default_theme/shared/imagemap/interfaces.py:26
+msgid "Width of the image map relative to it's parent portlet"
+msgstr ""
+"Largeur de l'image par rapport au bloc, en nombre de "
+"\"colonnes\" (100% équivaut à 12 colonnes)"
+
+#: src/pyams_default_theme/shared/imagemap/interfaces.py:30
+msgid "Left offset"
+msgstr "Décalage à gauche"
+
+#: src/pyams_default_theme/shared/imagemap/interfaces.py:31
+msgid "Left offset width, relative to it's parent portlet"
+msgstr ""
+"Largeur du décalaga à gauche de l'image par rapport au bloc, "
+"en nombre de \"colonnes\""
+
+#: src/pyams_default_theme/shared/imagemap/interfaces.py:38
+msgid "Sum of width and offset shouldn't be higher than 12!"
+msgstr "La somme de la largeur du bloc et de son décalage à gauche ne doit pas dépasser 12 !"
+
 #: src/pyams_default_theme/shared/imagemap/portlet/__init__.py:35
 msgid "Responsive SVG image map"
 msgstr "Par défaut"
--- a/src/pyams_default_theme/locales/pyams_default_theme.pot	Fri Oct 18 16:56:20 2019 +0200
+++ b/src/pyams_default_theme/locales/pyams_default_theme.pot	Mon Oct 21 11:45:37 2019 +0200
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE 1.0\n"
-"POT-Creation-Date: 2019-10-18 15:15+0200\n"
+"POT-Creation-Date: 2019-10-21 11:35+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -918,10 +918,30 @@
 msgid "Four vertical panels with portrait illustrations"
 msgstr ""
 
-#: ./src/pyams_default_theme/shared/imagemap/__init__.py:52
+#: ./src/pyams_default_theme/shared/imagemap/__init__.py:77
 msgid "Default imagemap renderer"
 msgstr ""
 
+#: ./src/pyams_default_theme/shared/imagemap/interfaces.py:25
+msgid "Paragraph width"
+msgstr ""
+
+#: ./src/pyams_default_theme/shared/imagemap/interfaces.py:26
+msgid "Width of the image map relative to it's parent portlet"
+msgstr ""
+
+#: ./src/pyams_default_theme/shared/imagemap/interfaces.py:30
+msgid "Left offset"
+msgstr ""
+
+#: ./src/pyams_default_theme/shared/imagemap/interfaces.py:31
+msgid "Left offset width, relative to it's parent portlet"
+msgstr ""
+
+#: ./src/pyams_default_theme/shared/imagemap/interfaces.py:38
+msgid "Sum of width and offset shouldn't be higher than 12!"
+msgstr ""
+
 #: ./src/pyams_default_theme/shared/imagemap/portlet/__init__.py:35
 msgid "Responsive SVG image map"
 msgstr ""
--- a/src/pyams_default_theme/shared/imagemap/__init__.py	Fri Oct 18 16:56:20 2019 +0200
+++ b/src/pyams_default_theme/shared/imagemap/__init__.py	Mon Oct 21 11:45:37 2019 +0200
@@ -10,19 +10,26 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
+from persistent import Persistent
+from zope.container.contained import Contained
+from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content.component.association.interfaces import IAssociationInfo
 from pyams_content.features.renderer.interfaces import IContentRenderer
 from pyams_content.shared.imagemap.interfaces import IImageMapParagraph, IWfImageMap
 from pyams_default_theme.features.renderer import BaseContentRenderer
 from pyams_default_theme.page import BasePreviewPage
+from pyams_default_theme.shared.imagemap.interfaces import IImageMapParagraphDefaultRendererSettings
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.layer import IPyAMSLayer, IPyAMSUserLayer
 from pyams_template.template import template_config
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, get_annotation_adapter
+from pyams_utils.factory import factory_config
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 
+
+__docformat__ = 'restructuredtext'
+
 from pyams_default_theme import _
 
 
@@ -33,8 +40,8 @@
 @pagelet_config(name='preview.html', context=IWfImageMap, layer=IPyAMSUserLayer,
                 permission=VIEW_SYSTEM_PERMISSION)
 @template_config(template='templates/render.pt', layer=IPyAMSLayer)
-class ImagemapRenderer(BasePreviewPage):
-    """Image map renderer"""
+class ImageMapPreviewer(BasePreviewPage):
+    """Image map preview renderer"""
 
     def get_item_info(self, item):
         return IAssociationInfo(item, None)
@@ -44,12 +51,31 @@
 # Imagemap paragraph renderer
 #
 
+IMAGEMAP_DEFAULT_RENDERER_SETTINGS_KEY = 'pyams_content.imagemap.renderer:default'
+
+
+@factory_config(IImageMapParagraphDefaultRendererSettings)
+class ImageMapParagraphDefaultRendererSettings(Persistent, Contained):
+    """Image map paragraph default renderer settings"""
+
+    width = FieldProperty(IImageMapParagraphDefaultRendererSettings['width'])
+    offset = FieldProperty(IImageMapParagraphDefaultRendererSettings['offset'])
+
+
+@adapter_config(context=IImageMapParagraph, provides=IImageMapParagraphDefaultRendererSettings)
+def imagemap_paragraph_default_renderer_settings_factory(context):
+    """Image map paragraph default renderer settings factory"""
+    return get_annotation_adapter(context, IMAGEMAP_DEFAULT_RENDERER_SETTINGS_KEY,
+                                  IImageMapParagraphDefaultRendererSettings)
+
+
 @adapter_config(name='default', context=(IImageMapParagraph, IPyAMSLayer), provides=IContentRenderer)
 @template_config(template='templates/imagemap-default.pt', layer=IPyAMSLayer)
-class ImagemapDefaultParagraphRenderer(BaseContentRenderer):
+class ImageMapParagraphDefaultRenderer(BaseContentRenderer):
     """Image map default paragraph renderer"""
 
     label = _("Default imagemap renderer")
+    settings_interface = IImageMapParagraphDefaultRendererSettings
 
     i18n_context_attrs = ('title',)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/imagemap/interfaces.py	Mon Oct 21 11:45:37 2019 +0200
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2008-2019 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.
+#
+
+from zope.interface import Interface, invariant, Invalid
+from zope.schema import Choice
+
+
+__docformat__ = 'restructuredtext'
+
+from pyams_default_theme import _
+
+
+class IImageMapParagraphDefaultRendererSettings(Interface):
+    """Image map paragraph default renderer settings interface"""
+
+    width = Choice(title=_("Paragraph width"),
+                   description=_("Width of the image map relative to it's parent portlet"),
+                   values=(12, 11, 10, 9, 8, 7, 6, 5, 4),
+                   default=12)
+
+    offset = Choice(title=_("Left offset"),
+                    description=_("Left offset width, relative to it's parent portlet"),
+                    values=(0, 1, 2, 3, 4, 5, 6, 7, 8),
+                    default=0)
+
+    @invariant
+    def check_offset(self):
+        if (self.width + self.offset) > 12:
+            raise Invalid(_("Sum of width and offset shouldn't be higher than 12!"))
--- a/src/pyams_default_theme/shared/imagemap/templates/imagemap-default.pt	Fri Oct 18 16:56:20 2019 +0200
+++ b/src/pyams_default_theme/shared/imagemap/templates/imagemap-default.pt	Mon Oct 21 11:45:37 2019 +0200
@@ -1,26 +1,30 @@
-<h3 tal:content="view.title">title</h3>
-<div class="no-padding wrapper-imagemap" i18n:domain="pyams_default_theme"
-	 tal:define="imagemap context.target;
-				 image i18n:imagemap.image;
-				 size image.get_image_size();">
-	<img src="${tales:absolute_url(image)}" alt="" />
-	<svg version="1.1"
-		 xmlns="http://www.w3.org/2000/svg"
-		 xmlns:xlink="http://www.w3.org/1999/xlink"
-		 class="imagemap-areas"
-		 viewBox="0 0 ${size[0]} ${size[1]}">
-		<tal:loop repeat="area imagemap.areas.values()">
-			<tal:var define="item imagemap.get_association(area)"
-					 condition="item and item.visible">
-				<a tal:define="info view.get_item_info(item);
-							   area_title i18n:area.title;
-							   item_title i18n:info.user_title;
-							   title area_title or item_title;"
-				   xlink:href="${item.get_url(request)}"
-				   xlink:title="${title}">
-					<polygon points="${area.svg_points}" />
-				</a>
-			</tal:var>
-		</tal:loop>
-	</svg>
-</div>
+<h3 tal:define="title view.title"
+	tal:condition="title">${title}</h3>
+<div tal:define="settings view.settings"
+	 class="col col-md-${settings.width} col-md-offset-${settings.offset}">
+	<div class="no-padding wrapper-imagemap" i18n:domain="pyams_default_theme"
+		 tal:define="imagemap context.target;
+					 image i18n:imagemap.image;
+					 size image.get_image_size();">
+		<img src="${tales:absolute_url(image)}" alt="" />
+		<svg version="1.1"
+			 xmlns="http://www.w3.org/2000/svg"
+			 xmlns:xlink="http://www.w3.org/1999/xlink"
+			 class="imagemap-areas"
+			 viewBox="0 0 ${size[0]} ${size[1]}">
+			<tal:loop repeat="area imagemap.areas.values()">
+				<tal:var define="item imagemap.get_association(area)"
+						 condition="item and item.visible">
+					<a tal:define="info view.get_item_info(item);
+								   area_title i18n:area.title;
+								   item_title i18n:info.user_title;
+								   title area_title or item_title;"
+					   xlink:href="${item.get_url(request)}"
+					   xlink:title="${title}">
+						<polygon points="${area.svg_points}" />
+					</a>
+				</tal:var>
+			</tal:loop>
+		</svg>
+	</div>
+</div>
\ No newline at end of file