toplevel menu template has support for dropdowns
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 24 Sep 2013 10:48:17 +0000 (12:48 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 24 Sep 2013 10:48:17 +0000 (12:48 +0200)
for now this is used to make the list smaller (read, less wide)

myslice/viewutils.py
views/static/css/topmenu.css
views/templates/widget-topmenu.html

index eaa2dcb..f00a451 100644 (file)
@@ -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):
index 344acdc..f7c7831 100644 (file)
@@ -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; }
index 81a10c5..6403078 100644 (file)
@@ -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>
     <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>