[basetemplate] Update navbar
authorVincent Michel <vincent.michel@logilab.fr>
Wed, 17 Jul 2013 13:24:44 +0200
changeset 299 3413ea19754f
parent 298 5303de3db9e2
child 300 80b8e99351ff
[basetemplate] Update navbar
data/cubes.brainomics.css
views/basetemplates.py
views/components.py
--- a/data/cubes.brainomics.css	Tue Jul 16 15:17:15 2013 +0200
+++ b/data/cubes.brainomics.css	Wed Jul 17 13:24:44 2013 +0200
@@ -5,4 +5,13 @@
 
 #header-right li{
  list-style-type: none;
- }
\ No newline at end of file
+ }
+
+.navbar a.brand {
+    display: block;
+    padding: 15px 20px;
+}
+
+div#header-center {
+    padding: 0 0 0;
+}
\ No newline at end of file
--- a/views/basetemplates.py	Tue Jul 16 15:17:15 2013 +0200
+++ b/views/basetemplates.py	Wed Jul 17 13:24:44 2013 +0200
@@ -136,24 +136,48 @@
 @monkeypatch(basetemplates.HTMLPageHeader)
 def main_header(self, view):
     """build the top menu with authentification info and the rql box"""
-    spans = {'headtext': 'span2',
-             'header-center': 'span8',
-             'header-right': 'span2',
+    spans = {'headtext': 3,
+             'header-center': 7,
+             'header-right': 2,
              }
     w = self.w
     w(u'<div id="header" class="navbar">'
       u'<div class="navbar-inner">'
       u'<div class="container">'
       u'<div class="row-fluid">')
+    prev_span_size = 0
     for colid, context in self.headers:
-        w(u'<div id="%s" class="%s">' % (colid, spans.get(colid, 'span2')))
         components = self._cw.vreg['ctxcomponents'].poss_visible_objects(
             self._cw, rset=self.cw_rset, view=view, context=context)
-        for comp in components:
-            comp.render(w=w)
-            w(u'&#160;')
-        w(u'</div>')
+        if components:
+            span_size = spans.get(colid, 2) + prev_span_size
+            prev_span_size = 0
+            w(u'<div id="%s" class="span%s">' % (colid, span_size))
+            klass = ' pull-right' if context in ('header-center', 'header-right') else ''
+            w(u'<ul class="nav%s">' % klass)
+            for comp in components:
+                w(u'<li>')
+                comp.render(w=w)
+                w(u'</li>')
+            w(u'</ul>')
+            w(u'</div>')
+        else:
+            # Keep size to make a bigger span the next time
+            prev_span_size += spans.get(colid, 2)
     w(u'</div></div></div></div>\n')
+    # get login form to display it as modal window / Backport from Orbui
+    login = self._cw.vreg['forms'].select('logform', self._cw)
+    self.w(u'<div id="loginModal" class="modal hide fade in">'
+           u'<div class="modal-header">'
+           u'<a class="close" data-dismiss="modal">x</a>'
+           u'<h3>%s</h3>'
+           u'</div>'
+           u'<div class="modal-body">' % self._cw._('log in'))
+    login.render(w=self.w)
+    self.w(u'</div>'
+           u' <div class="modal-footer"></div>'
+           u'</div>')
+
 
 
 ###############################################################################
--- a/views/components.py	Tue Jul 16 15:17:15 2013 +0200
+++ b/views/components.py	Wed Jul 17 13:24:44 2013 +0200
@@ -24,6 +24,7 @@
 from cubicweb.web import component
 from cubicweb.web.views.boxes import SearchBox, EditBox
 from cubicweb.web.views.bookmark import BookmarksBox
+from cubicweb.web.views.basecomponents import ApplicationName
 
 from cubes.brainomics import COMMENTED_ENTITIES, WIKI_ENTITIES
 
@@ -223,6 +224,8 @@
 ### REGISTRATION CALLBACK #####################################################
 ###############################################################################
 BookmarksBox.__select__ = BookmarksBox.__select__ & ~anonymous_user()
+ApplicationName.context = 'header-left'
+
 
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (BrainomicsSearchBox,