From 34395a45b94d115e9912597a9aa7317fb87d0ebb Mon Sep 17 00:00:00 2001
From: Thierry Parmentelat <thierry.parmentelat@inria.fr>
Date: Tue, 24 Sep 2013 12:48:17 +0200
Subject: [PATCH] toplevel menu template has support for dropdowns for now this
 is used to make the list smaller (read, less wide)

---
 myslice/viewutils.py                | 30 ++++++++++++++++++++---------
 views/static/css/topmenu.css        |  5 +++--
 views/templates/widget-topmenu.html | 29 +++++++++++++++++++++-------
 3 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/myslice/viewutils.py b/myslice/viewutils.py
index eaa2dcb5..f00a4515 100644
--- a/myslice/viewutils.py
+++ b/myslice/viewutils.py
@@ -1,25 +1,37 @@
 # a set of utilities to help make the global layout consistent across views
 
+# dropdowns are kind of ad hoc for now, and limited to one level
+# [ 
+# ### a regular first-level button
+# {'label':...,'href':...}, 
+# ### a dropdown
+# { 'label': ..., 'href'=..., 'dropdown':True, 'contents': [ { 'label':.., 'href'} ] }
+# , ..]
 def topmenu_items (current,request=None):
     has_user=request.user.is_authenticated()
     result=[]
     if has_user:
         result.append({'label':'Platforms', 'href': '/portal/platforms/'})
-        result.append({ 'label':'Dashboard', 'href': '/portal/dashboard/'})
+        result.append({'label':'Dashboard', 'href': '/portal/dashboard/'})
         # This should probably go in dashboard at some point
-        result.append({ 'label':'Request a slice', 'href': '/portal/slice_request/'})
-        result.append({'label':'My Account', 'href': '/portal/account/'})
+        dropdown = []
+        dropdown.append({'label':'Request a slice', 'href': '/portal/slice_request/'})
+        dropdown.append({'label':'My Account', 'href': '/portal/account/'})
+        dropdown.append({'label':'Contact Support', 'href': '/portal/contact/'})
+        result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
     else:
         result.append({'label':'Home', 'href': '/login'})
         # looks like this is accessible to non-logged users
         result.append({'label':'Platforms', 'href': '/portal/platforms/'})
-        result.append({ 'label':'Register', 'href': '/portal/register/'})
-    result.append({'label':'Contact Support', 'href': '/portal/contact/'})
+        result.append({'label':'Register', 'href': '/portal/register/'})
+        result.append({'label':'Contact Support', 'href': '/portal/contact/'})
+    # mark active
     for d in result:
-        #if d['label'].lower()find(current)>=0: d['is_active']=True
-        if d['label'] == current: d['is_active']=True
-    if not request: return result
-#    result.append (login_out_items [ has_user] )
+        if 'dropdown' in d:
+            for dd in d['contents']:
+                if dd['label'] == current: dd['is_active']=True
+        else:
+            if d['label'] == current: d['is_active']=True
     return result
 
 def the_user (request):
diff --git a/views/static/css/topmenu.css b/views/static/css/topmenu.css
index 344acdc3..f7c78315 100644
--- a/views/static/css/topmenu.css
+++ b/views/static/css/topmenu.css
@@ -6,9 +6,10 @@ body {
 
 /* center the buttons vertically in the header */
 div.topmenu { padding-top: 7px; }
-ul.logged-in { padding-top: 10px; }
+ul.logged-in { padding-top: 12px; }
 button#logout { 
 /*    margin-left: 8px;  */
     margin-bottom: 10px; 
 }
-ul.logged-in, button.logged-in { font-size: x-small; }
+ul.logged-in { font-size: x-small; }
+button.logged-in { font-size: small; }
diff --git a/views/templates/widget-topmenu.html b/views/templates/widget-topmenu.html
index 81a10c50..64030788 100644
--- a/views/templates/widget-topmenu.html
+++ b/views/templates/widget-topmenu.html
@@ -2,7 +2,8 @@
 {% insert_str prelude "css/bootstrap.css" %}
 {% insert_str prelude "css/topmenu.css" %}
 {% insert_str prelude "js/logout.js" %}
-<div class="navbar navbar-default navbar-fixed-top" role="navigation">
+<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
+  <div class="navbar-header">
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-myslice-collapse">
       <span class="sr-only">Toggle navigation</span>
       <span class="icon-bar"></span>
@@ -12,11 +13,25 @@
     <a class="navbar-brand" href="#">
       <img src="{{ STATIC_URL }}img/onelab-logo.png" height="30" alt="OneLab logo" />
     </a>
-    <div class="collapse navbar-collapse navbar-myslice-collapse topmenu">
+  </div>
+  <div class="collapse navbar-collapse navbar-myslice-collapse topmenu">
     <ul class="nav navbar-nav">
-	{% for d in topmenu_items %} {% if d.is_active %}
-	  <li class='active'> <a href="{{ d.href }}"> {{ d.label }} </a> </li> {% else %}
-	  <li class='other'> <a href="{{ d.href }}"> {{ d.label }} </a> </li> {% endif %} {% endfor %}
+	{% for d in topmenu_items %} 
+	{% if d.dropdown %}
+	<li class="dropdown">
+	  <a class="dropdown-toggle" data-toggle="dropdown" href="{{ d.href }}"> {{ d.label }}</a>
+	  <ul class="dropdown-menu">
+	  {% for dd in d.contents %}
+	  {% if dd.is_active %} <li class='active'> {% else %} <li class='other'> {% endif %}
+	  <a class="dropdown-toggle" href="{{ dd.href }}"> {{ dd.label }} </a> </li>
+	  {% endfor %}
+	</ul>
+        </li>
+        {% else %} 
+	{% if d.is_active %} <li class='active'> {% else %} <li class='other'> {% endif %}
+	<a href="{{ d.href }}"> {{ d.label }} </a> </li>
+	{% endif %}
+	{% endfor %}
     </ul> {# logout.js will attach a click function on that button, which then retrieves the 'username' attribute #}
     <ul class="nav navbar-nav pull-right logged-in">
       <li> {% if username %}
@@ -25,5 +40,5 @@
       Not logged in{% endif %}
       </li>
     </ul>
-    </div>
-</div>
+  </div>
+</nav>
-- 
2.47.0