Added SVG image-map portlet
authorThierry Florac <tflorac@ulthar.net>
Fri, 18 Oct 2019 15:12:25 +0200
changeset 1375 112904420dc2
parent 1374 0bf83e0553c4
child 1376 0155c71d38f0
Added SVG image-map portlet
src/pyams_content/shared/imagemap/portlet/__init__.py
src/pyams_content/shared/imagemap/portlet/interfaces.py
src/pyams_content/shared/imagemap/portlet/zmi/__init__.py
src/pyams_content/shared/imagemap/portlet/zmi/templates/imagemap-preview.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/imagemap/portlet/__init__.py	Fri Oct 18 15:12:25 2019 +0200
@@ -0,0 +1,48 @@
+#
+# 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.schema.fieldproperty import FieldProperty
+
+from pyams_content.component.links import InternalReferenceMixin
+from pyams_content.shared.imagemap.portlet.interfaces import IImageMapPortletSettings
+from pyams_portal.portlet import PortletSettings, portlet_config, Portlet
+from pyams_utils.factory import factory_config
+from pyams_utils.interfaces import VIEW_PERMISSION
+
+
+__docformat__ = 'restructuredtext'
+
+from pyams_content import _
+
+
+IMAGEMAP_PORTLET_NAME = 'pyams_content.portlet.imagemap'
+
+
+@factory_config(provided=IImageMapPortletSettings)
+class ImageMapPortletSettings(PortletSettings, InternalReferenceMixin):
+    """Image map portlet settings"""
+
+    title = FieldProperty(IImageMapPortletSettings['title'])
+    reference = FieldProperty(IImageMapPortletSettings['reference'])
+
+
+@portlet_config(permission=VIEW_PERMISSION)
+class ImageMapPortlet(Portlet):
+    """Image map portlet"""
+
+    name = IMAGEMAP_PORTLET_NAME
+    label = _("Image map")
+
+    toolbar_image = None
+    toolbar_css_class = 'fa fa-fw fa-2x fa-location-arrow'
+
+    settings_factory = IImageMapPortletSettings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/imagemap/portlet/interfaces.py	Fri Oct 18 15:12:25 2019 +0200
@@ -0,0 +1,33 @@
+#
+# 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 pyams_content.shared.imagemap import IMAGEMAP_CONTENT_TYPE
+from pyams_i18n.schema import I18nTextLineField
+from pyams_portal.interfaces import IPortletSettings
+from pyams_sequence.interfaces import IInternalReference
+from pyams_sequence.schema import InternalReferenceField
+
+
+__docformat__ = 'restructuredtext'
+
+from pyams_content import _
+
+
+class IImageMapPortletSettings(IPortletSettings, IInternalReference):
+    """Image map portlet settings interface"""
+
+    title = I18nTextLineField(title=_("Title"),
+                              required=False)
+
+    reference = InternalReferenceField(title=_("Internal reference"),
+                                       description=_("Reference to image map object"),
+                                       content_type=IMAGEMAP_CONTENT_TYPE)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/imagemap/portlet/zmi/__init__.py	Fri Oct 18 15:12:25 2019 +0200
@@ -0,0 +1,48 @@
+#
+# 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
+
+from pyams_content.shared.imagemap.portlet import IImageMapPortletSettings
+from pyams_form.form import AJAXEditForm
+from pyams_pagelet.interfaces import IPagelet
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_portal.interfaces import IPortletPreviewer
+from pyams_portal.portlet import PortletPreviewer
+from pyams_portal.zmi.portlet import PortletSettingsEditor
+from pyams_skin.layer import IPyAMSLayer
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+
+
+__docformat__ = 'restructuredtext'
+
+
+@pagelet_config(name='properties.html', context=IImageMapPortletSettings, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class ImageMapPortletSettingsEditor(PortletSettingsEditor):
+    """Image map portlet settings editor"""
+
+    settings = IImageMapPortletSettings
+
+
+@adapter_config(name='properties.json', context=(IImageMapPortletSettings, IPyAMSLayer),
+                provides=IPagelet)
+class ImageMapPortletSettingsAJAXEditor(AJAXEditForm, ImageMapPortletSettingsEditor):
+    """Image mpa portlet settings editor, JSON renderer"""
+
+
+@adapter_config(context=(Interface, IPyAMSLayer, Interface, IImageMapPortletSettings),
+                provides=IPortletPreviewer)
+@template_config(template='templates/imagemap-preview.pt', layer=IPyAMSLayer)
+class ImageMapPortletPreviewer(PortletPreviewer):
+    """Image map portlet previewer"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/imagemap/portlet/zmi/templates/imagemap-preview.pt	Fri Oct 18 15:12:25 2019 +0200
@@ -0,0 +1,22 @@
+<div class="padding-x-5" i18n:domain="pyams_content"
+	 tal:define="settings view.settings">
+	<strong tal:define="title i18n:settings.title"
+			tal:condition="title">
+		${title}<br />
+	</strong>
+	<div class="wrapper-imagemap"
+		 tal:define="target settings.target">
+		<tal:if condition="target is not None">
+			<img tal:define="image i18n:target.image;"
+				 src="${tales:absolute_url(image)}" />
+		</tal:if>
+		<tal:if condition="target is None">
+			<div class="text-center padding-y-5">
+				<span class="fa-stack fa-lg">
+					<i class="fa fa-picture-o fa-stack-1x"></i>
+					<i class="fa fa-ban fa-stack-2x text-danger"></i>
+				</span>
+			</div>
+		</tal:if>
+	</div>
+</div>
\ No newline at end of file