Added renderers to simple navigation portlet
authorThierry Florac <thierry.florac@onf.fr>
Mon, 26 Nov 2018 11:05:48 +0100
changeset 255 20b80d2c592d
parent 254 bcee7f49b3ea
child 256 ab68305914ef
Added renderers to simple navigation portlet
src/pyams_default_theme/features/menu/portlet/navigation/__init__.py
src/pyams_default_theme/features/menu/portlet/navigation/templates/simple-carousel.pt
src/pyams_default_theme/features/menu/portlet/navigation/templates/simple-panels.pt
--- a/src/pyams_default_theme/features/menu/portlet/navigation/__init__.py	Mon Nov 26 11:05:06 2018 +0100
+++ b/src/pyams_default_theme/features/menu/portlet/navigation/__init__.py	Mon Nov 26 11:05:48 2018 +0100
@@ -12,30 +12,34 @@
 
 __docformat__ = 'restructuredtext'
 
+from persistent import Persistent
+from zope.interface import implementer, Interface
+from zope.location.location import Location
+from zope.schema.fieldproperty import FieldProperty
 
-# import standard library
-
-# import interfaces
+from pyams_content.component.association.interfaces import IAssociationInfo
 from pyams_content.features.menu.portlet.navigation.interfaces.double import IDoubleNavigationPortletSettings
 from pyams_content.features.menu.portlet.navigation.interfaces.simple import ISimpleNavigationPortletSettings
 from pyams_default_theme.features.menu.portlet.navigation.interfaces import \
     IDoubleNavigationPortletSelectMenusRendererSettings
-from pyams_portal.interfaces import IPortalContext, IPortletRenderer, PORTLET_RENDERER_SETTINGS_KEY
+from pyams_portal.interfaces import IPortalContext, IPortletRenderer
+from pyams_portal.portlet import PortletRenderer
 from pyams_skin.layer import IPyAMSLayer
-
-# import packages
-from persistent import Persistent
-from pyams_portal.portlet import PortletRenderer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.factory import factory_config
-from zope.interface import implementer, Interface
-from zope.location.location import Location
-from zope.schema.fieldproperty import FieldProperty
 
 from pyams_default_theme import _
 
 
+class BaseNavigationRenderer(PortletRenderer):
+    """Base navigation portlet renderer"""
+
+    @staticmethod
+    def get_link_info(link):
+        return IAssociationInfo(link)
+
+
 #
 # Simple navigation portlet renderers
 #
@@ -43,20 +47,44 @@
 @adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, ISimpleNavigationPortletSettings),
                 provides=IPortletRenderer)
 @template_config(template='templates/simple-horizontal.pt', layer=IPyAMSLayer)
-class SimpleNavigationPortletHorizontalRenderer(PortletRenderer):
+class SimpleNavigationPortletHorizontalRenderer(BaseNavigationRenderer):
     """Simple navigation horizontal portlet renderer"""
 
     label = _("Horizontal list with vertical illustrations")
+    weight = 1
 
 
 @adapter_config(name='horizontal-tabs',
                 context=(IPortalContext, IPyAMSLayer, Interface, ISimpleNavigationPortletSettings),
                 provides=IPortletRenderer)
 @template_config(template='templates/simple-horizontal-tabs.pt', layer=IPyAMSLayer)
-class SimpleNavigationPortletHorizontalTabsRenderer(PortletRenderer):
+class SimpleNavigationPortletHorizontalTabsRenderer(BaseNavigationRenderer):
     """Simple navigation horizontal portlet renderer with tabs"""
 
     label = _("Horizontal list with tabs and horizontal illustrations")
+    weight = 2
+
+
+@adapter_config(name='carousel',
+                context=(IPortalContext, IPyAMSLayer, Interface, ISimpleNavigationPortletSettings),
+                provides=IPortletRenderer)
+@template_config(template='templates/simple-carousel.pt', layer=IPyAMSLayer)
+class SimpleNavigationPortletCarouselRenderer(BaseNavigationRenderer):
+    """Simple navigation portlet carousel renderer"""
+
+    label = _("Horizontal carousel with full width illustrations")
+    weight = 3
+
+
+@adapter_config(name='vertical-panels',
+                context=(IPortalContext, IPyAMSLayer, Interface, ISimpleNavigationPortletSettings),
+                provides=IPortletRenderer)
+@template_config(template='templates/simple-panels.pt', layer=IPyAMSLayer)
+class SimpleNavigationPortletVerticalPanelsRenderer(BaseNavigationRenderer):
+    """Simple navigation portlet vertical panels renderer"""
+
+    label = _("Vertical panels with panoramic illustrations")
+    weight = 4
 
 
 #
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/menu/portlet/navigation/templates/simple-carousel.pt	Mon Nov 26 11:05:48 2018 +0100
@@ -0,0 +1,40 @@
+<section class="wrapper" i18n:domain="pyams_default_theme"
+	 tal:define="settings view.settings;
+				 cache_key tales:cache_key(settings);">
+	<div id="carousel-${cache_key}"
+		 class="carousel slide"
+	 	 data-ride="carousel">
+		<ol class="carousel-indicators">
+			<li tal:repeat="link settings.links.get_visible_items()"
+				class="${'active' if repeat.link.start() else None}"
+				data-target="#carousel-${cache_key}"
+				data-slide-to="${repeat.link.index}"></li>
+		</ol>
+		<div class="carousel-inner">
+			<div tal:repeat="link settings.links.get_visible_items()"
+				 class="item ${'active' if repeat.link.start() else None}">
+				<tal:var define="illustration tales:pyams_illustration(link);
+								 img_data i18n:illustration.data;
+								 alt i18n:illustration.alt_title;
+								 link_info view.get_link_info(link);">
+					${structure:tales:picture(img_data, lg_thumb='pano', md_thumb='pano',
+											  sm_thumb='pano', xs_thumb='pano', alt=alt)}
+					<a class="carousel-caption"
+					   href="${link.get_url(request)}">
+						<h3>${link_info.user_title}</h3>
+					</a>
+				</tal:var>
+			</div>
+		</div>
+		<a class="left carousel-control" role="button"
+		   data-target="#carousel-${cache_key}" data-slide="prev">
+			<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
+			<span class="sr-only" i18n:translate="">Previous</span>
+		</a>
+		<a class="right carousel-control" role="button"
+		   data-target="#carousel-${cache_key}" data-slide="next">
+			<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
+			<span class="sr-only" i18n:translate="">Next</span>
+		</a>
+	</div>
+</section>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/menu/portlet/navigation/templates/simple-panels.pt	Mon Nov 26 11:05:48 2018 +0100
@@ -0,0 +1,24 @@
+<div class="panels" i18n:domain="pyams_default_theme"
+	 tal:define="settings view.settings">
+	<h2>${i18n:settings.title}</h2>
+	<div tal:repeat="link settings.links.get_visible_items()"
+		 class="col-sm-4">
+		<tal:var define="illustration tales:pyams_illustration(link);
+						 img_data i18n:illustration.data;
+						 alt i18n:illustration.alt_title;
+						 link_info view.get_link_info(link);">
+			<a href="${link.get_url(request)}">
+				${structure:tales:picture(img_data, lg_thumb='pano', lg_width=4, md_thumb='pano', md_width=4,
+										  sm_thumb='pano', sm_width=4, xs_thumb='pano', xs_width=4, alt=alt)}
+			</a>
+			<a class="caption"
+			   href="${link.get_url(request)}">
+				<h3>${link_info.user_title}</h3>
+			</a>
+			<tal:var define="description i18n:link.description">
+				${structure:tales:html(description)}
+			</tal:var>
+		</tal:var>
+	</div>
+	<div class="clearfix"></div>
+</div>
\ No newline at end of file