# 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):
{% 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 %}
Not logged in{% endif %}
</li>
</ul>
- </div>
-</div>
+ </div>
+</nav>