web/views/basetemplates.py
changeset 6389 72ba82a26e05
parent 6225 a176e68b7d0d
child 6428 de95bbed8781
--- a/web/views/basetemplates.py	Mon Oct 04 18:55:57 2010 +0200
+++ b/web/views/basetemplates.py	Mon Oct 04 18:56:05 2010 +0200
@@ -276,11 +276,12 @@
         logo = self._cw.vreg['components'].select_or_none('logo', self._cw,
                                                           rset=self.cw_rset)
         if logo and logo.cw_propval('visible'):
-            self.w(u'<table id="header"><tr>\n')
-            self.w(u'<td>')
-            logo.render(w=self.w)
-            self.w(u'</td>\n')
-            self.w(u'</tr></table>\n')
+            w = self.w
+            w(u'<table id="header"><tr>\n')
+            w(u'<td>')
+            logo.render(w=w)
+            w(u'</td>\n')
+            w(u'</tr></table>\n')
 
 
 # page parts templates ########################################################
@@ -335,35 +336,31 @@
 
     def main_header(self, view):
         """build the top menu with authentification info and the rql box"""
-        self.w(u'<table id="header"><tr>\n')
-        self.w(u'<td id="firstcolumn">')
+        w = self.w
+        w(u'<table id="header"><tr>\n')
+        w(u'<td id="firstcolumn">')
         logo = self._cw.vreg['components'].select_or_none(
             'logo', self._cw, rset=self.cw_rset)
         if logo and logo.cw_propval('visible'):
-            logo.render(w=self.w)
-        self.w(u'</td>\n')
+            logo.render(w=w)
+        w(u'</td>\n')
         # appliname and breadcrumbs
-        self.w(u'<td id="headtext">')
+        w(u'<td id="headtext">')
         for cid in self.main_cell_components:
             comp = self._cw.vreg['components'].select_or_none(
                 cid, self._cw, rset=self.cw_rset)
             if comp and comp.cw_propval('visible'):
                 comp.render(w=self.w)
-        self.w(u'</td>')
+        w(u'</td>')
         # logged user and help
-        self.w(u'<td>\n')
-        comp = self._cw.vreg['components'].select_or_none(
+        login_components = self._cw.vreg['components'].selectable(
             'loggeduserlink', self._cw, rset=self.cw_rset)
-        if comp and comp.cw_propval('visible'):
-            comp.render(w=self.w)
-        self.w(u'</td>')
-        # lastcolumn
-        self.w(u'<td id="lastcolumn">')
-        self.w(u'</td>\n')
-        self.w(u'</tr></table>\n')
-        if self._cw.session.anonymous_session:
-            self.wview('logform', rset=self.cw_rset, id='popupLoginBox',
-                       klass='hidden', title=False, showmessage=False)
+        for comp in login_components:
+            w(u'<td>\n')
+            if comp.cw_propval('visible'):
+                comp.render(w=w)
+            w(u'</td>')
+        w(u'</tr></table>\n')
 
     def state_header(self):
         state = self._cw.search_state
@@ -380,7 +377,6 @@
         return self.w(u'<div class="stateMessage">%s</div>' % msg)
 
 
-
 class HTMLPageFooter(View):
     """default html page footer: include footer actions
     """
@@ -438,12 +434,16 @@
     __regid__ = 'logform'
     domid = 'loginForm'
     needs_css = ('cubicweb.login.css',)
+    onclick = "javascript: cw.htmlhelpers.popupLoginBox('%s', '%s');"
     # XXX have to recall fields name since python is mangling __login/__password
     __login = ff.StringField('__login', widget=fw.TextInput({'class': 'data'}))
     __password = ff.StringField('__password', label=_('password'),
                                 widget=fw.PasswordSingleInput({'class': 'data'}))
     form_buttons = [fw.SubmitButton(label=_('log in'),
-                                    attrs={'class': 'loginButton'})]
+                                    attrs={'class': 'loginButton'}),
+                    fw.ResetButton(label=_('cancel'),
+                                   attrs={'class': 'loginButton',
+                                          'onclick': onclick % ('popupLoginBox', '__login')}),]
 
     def form_action(self):
         if self.action is None:
@@ -452,32 +452,35 @@
 
 
 class LogFormView(View):
+    # XXX an awfull lot of hardcoded assumptions there
+    #     makes it unobvious to reuse/specialize
     __regid__ = 'logform'
     __select__ = match_kwargs('id', 'klass')
 
     title = 'log in'
 
     def call(self, id, klass, title=True, showmessage=True):
-        self.w(u'<div id="%s" class="%s">' % (id, klass))
+        w = self.w
+        w(u'<div id="%s" class="popupLoginBox %s">' % (id, klass))
         if title:
             stitle = self._cw.property_value('ui.site-title')
             if stitle:
                 stitle = xml_escape(stitle)
             else:
                 stitle = u'&#160;'
-            self.w(u'<div id="loginTitle">%s</div>' % stitle)
-        self.w(u'<div id="loginContent">\n')
+            w(u'<div class="loginTitle">%s</div>' % stitle)
+        w(u'<div class="loginContent">\n')
         if showmessage and self._cw.message:
-            self.w(u'<div class="loginMessage">%s</div>\n' % self._cw.message)
+            w(u'<div class="loginMessage">%s</div>\n' % self._cw.message)
         config = self._cw.vreg.config
         if config['auth-mode'] != 'http':
             self.login_form(id) # Cookie authentication
-        self.w(u'</div>')
+        w(u'</div>')
         if self._cw.https and config.anonymous_user()[0]:
             path = xml_escape(config['base-url'] + self._cw.relative_path())
-            self.w(u'<div class="loginMessage"><a href="%s">%s</a></div>\n'
-                   % (path, self._cw._('No account? Try public access at %s') % path))
-        self.w(u'</div>\n')
+            w(u'<div class="loginMessage"><a href="%s">%s</a></div>\n'
+              % (path, self._cw._('No account? Try public access at %s') % path))
+        w(u'</div>\n')
 
     def login_form(self, id):
         cw = self._cw