Include menus in header renderer
authorThierry Florac <thierry.florac@onf.fr>
Fri, 23 Nov 2018 15:27:10 +0100
changeset 249 b75d74082044
parent 248 44d8c16d9617
child 250 cea48573d9b6
Include menus in header renderer
src/pyams_default_theme/features/header/skin/__init__.py
src/pyams_default_theme/features/header/skin/templates/simple-header.pt
--- a/src/pyams_default_theme/features/header/skin/__init__.py	Fri Nov 23 15:26:01 2018 +0100
+++ b/src/pyams_default_theme/features/header/skin/__init__.py	Fri Nov 23 15:27:10 2018 +0100
@@ -13,7 +13,6 @@
 __docformat__ = 'restructuredtext'
 
 import logging
-logger = logging.getLogger('PyAMS (content)')
 
 from pyramid.decorator import reify
 from pyramid.location import lineage
@@ -21,7 +20,6 @@
 
 from pyams_cache.beaker import get_cache
 from pyams_content.component.association.interfaces import IAssociationInfo
-from pyams_content.component.links.interfaces import IInternalLink
 from pyams_content.features.header.interfaces import IHeaderRenderer, IHeaderRendererSettings, IHeaderSettings, \
     IHeaderTarget
 from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
@@ -31,6 +29,7 @@
 from pyams_default_theme.features.renderer import BaseContentRenderer
 from pyams_portal.interfaces import PREVIEW_MODE
 from pyams_portal.portlet import PORTLETS_CACHE_KEY, PORTLETS_CACHE_NAME, PORTLETS_CACHE_REGION
+from pyams_sequence.interfaces import IInternalReference
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
@@ -39,6 +38,8 @@
 
 from pyams_default_theme import _
 
+logger = logging.getLogger('PyAMS (content)')
+
 
 #
 # Base header renderer
@@ -146,7 +147,7 @@
         return IAssociationInfo(link)
 
     def is_active(self, link):
-        if IInternalLink.providedBy(link):
+        if IInternalReference.providedBy(link):
             target = link.get_target()
             if target is not None:
                 return target in self.request.annotations['REQUEST_PATH']
--- a/src/pyams_default_theme/features/header/skin/templates/simple-header.pt	Fri Nov 23 15:26:01 2018 +0100
+++ b/src/pyams_default_theme/features/header/skin/templates/simple-header.pt	Fri Nov 23 15:27:10 2018 +0100
@@ -19,14 +19,33 @@
 			</div>
 			<div class="collapse navbar-collapse" id="navbar-collapser">
 				<ul class="nav navbar-nav" role="tablist">
-					<tal:loop repeat="link settings.tabs.get_visible_items(request)">
-						<li role="presentation"
-							tal:attributes="class 'active' if view.is_active(link) else ''">
-							<a tal:define="info view.get_link_info(link);
-										   href link.get_url(request);"
+					<tal:loop repeat="menu settings.menus.get_visible_items(request)">
+						<li tal:condition="menu.reference"
+							tal:attributes="class 'active' if view.is_active(menu) else ''">
+							<a tal:define="info view.get_link_info(menu);
+										   href menu.get_url(request);"
 							   tal:condition="href"
 							   href="${href}">${info.user_title}</a>
 						</li>
+						<li class="dropdown"
+							tal:condition="not:menu.reference">
+							<a href="#" class="dropdown-toggle"
+							   data-toggle="dropdown" role="button"
+							   aria-haspopup="true" aria-expanded="false">
+								${i18n:menu.title}
+								<span class="caret"></span>
+							</a>
+							<ul class="dropdown-menu">
+								<tal:loop repeat="link menu.get_visible_items(request)">
+									<li>
+										<a tal:define="info view.get_link_info(link);
+													   href link.get_url(request);"
+										   tal:condition="href"
+										   href="${href}">${info.user_title}</a>
+									</li>
+								</tal:loop>
+							</ul>
+						</li>
 					</tal:loop>
 				</ul>
 			</div>