Updated default header settings
authorThierry Florac <thierry.florac@onf.fr>
Mon, 26 Nov 2018 11:05:06 +0100
changeset 254 bcee7f49b3ea
parent 253 b6ff1877cb48
child 255 20b80d2c592d
Updated default header settings
src/pyams_default_theme/features/header/__init__.py
src/pyams_default_theme/features/header/interfaces.py
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/__init__.py	Mon Nov 26 11:04:35 2018 +0100
+++ b/src/pyams_default_theme/features/header/__init__.py	Mon Nov 26 11:05:06 2018 +0100
@@ -16,6 +16,7 @@
 from zope.interface import implementer
 from zope.location import Location
 from zope.location.interfaces import ISublocations
+from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content.component.association.interfaces import ASSOCIATION_CONTAINER_KEY
 from pyams_content.features.header.interfaces import IHeaderSettings, IHeaderTarget
@@ -62,8 +63,14 @@
 class SimpleHeaderRendererSettings(Persistent, Location):
     """Simple header renderer settings"""
 
+    apply_on_root = FieldProperty(ISimpleHeaderRendererSettings['apply_on_root'])
     banner = FileProperty(ISimpleHeaderRendererSettings['banner'])
     logo = FileProperty(ISimpleHeaderRendererSettings['logo'])
+    search_target = FieldProperty(ISimpleHeaderRendererSettings['search_target'])
+
+    @property
+    def can_apply_on_root(self):
+        return self.apply_on_root
 
     @property
     def menus(self):
--- a/src/pyams_default_theme/features/header/interfaces.py	Mon Nov 26 11:04:35 2018 +0100
+++ b/src/pyams_default_theme/features/header/interfaces.py	Mon Nov 26 11:05:06 2018 +0100
@@ -13,9 +13,11 @@
 __docformat__ = 'restructuredtext'
 
 from zope.interface import Interface, Attribute
+from zope.schema import Bool
 
 from pyams_content.features.header.interfaces import IHeaderRendererSettings
 from pyams_file.schema import ImageField
+from pyams_sequence.schema import InternalReferenceField
 
 from pyams_default_theme import _
 
@@ -23,6 +25,12 @@
 class ISimpleHeaderRendererSettings(IHeaderRendererSettings):
     """Simple header renderer settings"""
 
+    apply_on_root = Bool(title=_("Apply on root?"),
+                         description=_("If 'no', header settings will not be applied on site root but only "
+                                       "on inner sites"),
+                         required=True,
+                         default=True)
+
     banner = ImageField(title=_("Banner image"),
                         description=_("Image displayed as header background"),
                         required=False)
@@ -31,6 +39,10 @@
                       description=_("Logo displayed in header"),
                       required=False)
 
+    search_target = InternalReferenceField(title=_("Search form target"),
+                                           description=_("Site or folder handling site search"),
+                                           required=False)
+
     tabs = Attribute("Top tabs list")
 
     menus = Attribute("Top tabs menus list")
--- a/src/pyams_default_theme/features/header/skin/__init__.py	Mon Nov 26 11:04:35 2018 +0100
+++ b/src/pyams_default_theme/features/header/skin/__init__.py	Mon Nov 26 11:05:06 2018 +0100
@@ -23,6 +23,7 @@
 from pyams_content.features.header.interfaces import IHeaderRenderer, IHeaderRendererSettings, IHeaderSettings, \
     IHeaderTarget
 from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
+from pyams_content.root import ISiteRoot
 from pyams_default_theme.features.header import SimpleHeaderRendererSettings
 from pyams_default_theme.features.header.interfaces import ISimpleHeaderRendererSettings
 from pyams_default_theme.features.header.skin.interfaces import IHeaderClass
@@ -30,6 +31,7 @@
 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_sequence.reference import get_reference_target
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
@@ -81,7 +83,13 @@
         request = self.request
         return request.registry.queryMultiAdapter((request.context, request), IHeaderClass, default='')
 
+    @property
+    def search_target(self):
+        return get_reference_target(self.settings.search_target, request=self.request)
+
     def render(self):
+        if ISiteRoot.providedBy(self.request.context) and not self.settings.can_apply_on_root:
+            return ''
         preview_mode = self.request.annotations.get(PREVIEW_MODE, False)
         if preview_mode:
             return super(BaseHeaderRenderer, self).render()
--- a/src/pyams_default_theme/features/header/skin/templates/simple-header.pt	Mon Nov 26 11:04:35 2018 +0100
+++ b/src/pyams_default_theme/features/header/skin/templates/simple-header.pt	Mon Nov 26 11:05:06 2018 +0100
@@ -20,7 +20,7 @@
 			<div class="collapse navbar-collapse" id="navbar-collapser">
 				<ul class="nav navbar-nav" role="tablist">
 					<tal:loop repeat="menu settings.menus.get_visible_items(request)">
-						<li tal:condition="menu.reference"
+						<li tal:condition="menu.reference and not menu.dynamic_menu"
 							tal:attributes="class 'active' if view.is_active(menu) else ''">
 							<a tal:define="info view.get_link_info(menu);
 										   href menu.get_url(request);"
@@ -28,7 +28,7 @@
 							   href="${href}">${info.user_title}</a>
 						</li>
 						<li class="dropdown"
-							tal:condition="not:menu.reference">
+							tal:condition="(not menu.reference) or menu.dynamic_menu">
 							<a href="#" class="dropdown-toggle"
 							   data-toggle="dropdown" role="button"
 							   aria-haspopup="true" aria-expanded="false">
@@ -48,6 +48,16 @@
 						</li>
 					</tal:loop>
 				</ul>
+				<form class="navbar-form navbar-right"
+					  tal:define="target view.search_target"
+					  tal:condition="target is not None"
+					  action="${tales:absolute_url(target)}">
+					<div class="form-group">
+						<input type="text" class="form-control" name="user_search"
+							   placeholder="Search..." i18n:attributes="placeholder">
+					</div>
+					<button type="submit" class="btn btn-default" i18n:translate="">Search</button>
+				</form>
 			</div>
 		</div>
 	</nav>