Added tabs viewlets manager in header panel
authorThierry Florac <thierry.florac@onf.fr>
Wed, 02 Jul 2014 10:30:01 +0200
changeset 51 dbed1ff1e070
parent 50 ed38f50045e7
child 52 3d75d7c04593
Added tabs viewlets manager in header panel
src/ztfy/myams/viewlet/toplinks/__init__.py
src/ztfy/myams/viewlet/toplinks/configure.zcml
src/ztfy/myams/viewlet/toplinks/interfaces.py
src/ztfy/myams/viewlet/toplinks/toplinks.pt
src/ztfy/myams/viewlet/toplinks/toptabs.pt
--- a/src/ztfy/myams/viewlet/toplinks/__init__.py	Wed Jul 02 10:29:06 2014 +0200
+++ b/src/ztfy/myams/viewlet/toplinks/__init__.py	Wed Jul 02 10:30:01 2014 +0200
@@ -9,22 +9,28 @@
 # import Zope3 interfaces
 
 # import local interfaces
-from ztfy.myams.viewlet.toplinks.interfaces import ITopLinksViewletManager, ITopLinksViewlet, ITopLinksMenu
+from ztfy.myams.viewlet.toplinks.interfaces import ITopLinksViewletManager, ITopLinksViewlet, ITopLinksMenu, \
+    ITopTabsViewlet, ITopTabsTab
 
 # import Zope3 packages
 from zope.i18n import translate
 from zope.interface import implements
+from zope.viewlet.manager import WeightOrderedViewletManager
 
 # import local packages
 from ztfy.baseskin.viewlet import WeightViewletManagerBase, ViewletBase
 
 
-class TopLinksViewletManager(WeightViewletManagerBase):
+class TopLinksViewletManager(WeightOrderedViewletManager):
     """Top links viewlet manager"""
 
     implements(ITopLinksViewletManager)
 
 
+#
+# Top links viewlet
+#
+
 class TopLinksViewlet(WeightViewletManagerBase, ViewletBase):
     """Top links viewlet"""
 
@@ -70,3 +76,50 @@
         if self.click_handler:
             data.update({'data-ams-click-handler': self.click_handler})
         return ' '.join('%s=%s' % item for item in data.iteritems())
+
+
+#
+# Top tabs viewlet
+#
+
+class TopTabsViewlet(WeightViewletManagerBase, ViewletBase):
+    """Top tabs viewlet"""
+
+    implements(ITopTabsViewlet)
+
+    label = u"Label:"
+    css_class = u'top-tabs'
+
+    def __init__(self, context, request, view, manager=None):
+        WeightViewletManagerBase.__init__(self, context, request, view)
+        ViewletBase.__init__(self, context, request, view, manager)
+
+    def update(self):
+        WeightViewletManagerBase.update(self)
+
+
+class TopTabsTab(ViewletBase):
+    """Top tabs tab"""
+
+    implements(ITopTabsTab)
+
+    css_class = u""
+    label = u"Tab label"
+    click_handler = None
+    url = u"#"
+    data = {'data-toggle': 'tab'}
+
+    def render(self):
+        label = translate(self.label, context=self.request)
+        return u'''<li class="%s">
+                    <a href="%s" %s>%s</a>
+                </li>''' % (self.css_class,
+                            self.url,
+                            self.getDataAttributes(),
+                            unicode(label, 'utf-8') if isinstance(label, str) else label)
+
+    def getDataAttributes(self):
+        data = self.data.copy()
+        if self.click_handler:
+            data.update({'data-ams-click-handler': self.click_handler})
+        return ' '.join('%s=%s' % item for item in data.iteritems())
--- a/src/ztfy/myams/viewlet/toplinks/configure.zcml	Wed Jul 02 10:29:06 2014 +0200
+++ b/src/ztfy/myams/viewlet/toplinks/configure.zcml	Wed Jul 02 10:30:01 2014 +0200
@@ -11,7 +11,12 @@
 
 	<z3c:template
 		template="toplinks.pt"
-		for=".interfaces.ITopLinksViewletManager"
+		for=".interfaces.ITopLinksViewlet"
+		layer="ztfy.myams.layer.MyAMSLayer" />
+
+	<z3c:template
+		template="toptabs.pt"
+		for=".interfaces.ITopTabsViewlet"
 		layer="ztfy.myams.layer.MyAMSLayer" />
 
 </configure>
--- a/src/ztfy/myams/viewlet/toplinks/interfaces.py	Wed Jul 02 10:29:06 2014 +0200
+++ b/src/ztfy/myams/viewlet/toplinks/interfaces.py	Wed Jul 02 10:30:01 2014 +0200
@@ -23,6 +23,10 @@
     """Top links viewlet manager interface"""
 
 
+#
+# Top dropdown menus viewlet
+#
+
 class ITopLinksMenu(IViewlet):
     """Top link menu"""
 
@@ -51,3 +55,35 @@
 
     viewlets = List(title=_("Top links menus"),
                     value_type=Object(schema=ITopLinksMenu))
+
+
+#
+# Top tabs viewlet
+#
+
+class ITopTabsTab(IViewlet):
+    """Top tabs tab"""
+
+    css_class = TextLine(title=_("Tab CSS class"),
+                         required=False)
+
+    label = TextLine(title=_("Tab label"))
+
+    click_handler = TextLine(title=_("Tab click handler"))
+
+    url = TextLine(title=_("Tab link location"))
+
+    data = Dict(title=_("Tab data attributes"),
+                key_type=TextLine(),
+                value_type=TextLine())
+
+
+class ITopTabsViewlet(IViewlet):
+    """Top tabs viewlet"""
+
+    label = TextLine(title=_("Main label"))
+
+    css_class = TextLine(title=_("Main CSS class"))
+
+    viewlets = List(title=_("Top tabs items"),
+                    value_type=Object(schema=ITopTabsTab))
--- a/src/ztfy/myams/viewlet/toplinks/toplinks.pt	Wed Jul 02 10:29:06 2014 +0200
+++ b/src/ztfy/myams/viewlet/toplinks/toplinks.pt	Wed Jul 02 10:30:01 2014 +0200
@@ -1,15 +1,13 @@
-<tal:loop repeat="viewlet view/viewlets" i18n:domain="ztfy.myams">
-	<div class="top-menu" tal:attributes="class viewlet/css_class">
-		<span class="label" tal:content="viewlet/label | default">Label:</span>
-		<span class="top-selector" class="popover-trigger-element dropdown-toggle"
-			  data-toggle="dropdown">
-			<span class="title" tal:content="viewlet/dropdown_label | default">Dropdown label</span>
-			<i class="fa fa-angle-down"></i>
-		</span>
-		<ul class="dropdown-menu">
-			<tal:loop repeat="menu viewlet/viewlets">
-				<tal:li replace="structure menu/render" />
-			</tal:loop>
-		</ul>
-	</div>
-</tal:loop>
+<div class="top-menu" tal:attributes="class view/css_class" i18n:domain="ztfy.myams">
+	<span class="label" tal:content="view/label | default">Label:</span>
+	<span class="top-selector" class="popover-trigger-element dropdown-toggle"
+		  data-toggle="dropdown">
+		<span class="title" tal:content="view/dropdown_label | default">Dropdown label</span>
+		<i class="fa fa-angle-down"></i>
+	</span>
+	<ul class="dropdown-menu">
+		<tal:loop repeat="menu view/viewlets">
+			<tal:li replace="structure menu/render" />
+		</tal:loop>
+	</ul>
+</div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/myams/viewlet/toplinks/toptabs.pt	Wed Jul 02 10:30:01 2014 +0200
@@ -0,0 +1,8 @@
+<div class="top-tabs" tal:attributes="class view/css_class" i18n:domain="ztfy.myams">
+	<span class="label" tal:content="view/label | default">Label:</span>
+	<ul class="nav nav-tabs">
+		<tal:loop repeat="tab view/viewlets">
+			<tal:li replace="structure tab/render" />
+		</tal:loop>
+	</ul>
+</div>