[tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 01 Aug 2012 09:42:36 +0200
branchstable
changeset 8512 5161573ba806
parent 8511 f15e90b914cd
child 8514 0e012eb80990
[tabbed view] make tabs optionaly lazy: lazy=False on the tabbed view trigger synchronous tabs. Closes #2443038 This is useful for tabs holding a self-posted form for instance.
web/views/tabs.py
--- a/web/views/tabs.py	Thu Aug 02 18:52:27 2012 +0200
+++ b/web/views/tabs.py	Wed Aug 01 09:42:36 2012 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -90,6 +90,7 @@
 
 class TabsMixin(LazyViewMixin):
     """a tab mixin to easily get jQuery based, lazy, ajax tabs"""
+    lazy = True
 
     @property
     def cookie_name(self):
@@ -118,11 +119,11 @@
             else:
                 tabid, tabkwargs = tab
                 tabkwargs = tabkwargs.copy()
-            tabkwargs.setdefault('rset', self.cw_rset)
             vid = tabkwargs.get('vid', tabid)
             domid = uilib.domid(tabid)
             try:
-                viewsvreg.select(vid, self._cw, **tabkwargs)
+                viewsvreg.select(vid, self._cw, rset=self.cw_rset,
+                                 tabid=domid, **tabkwargs)
             except NoSelectableObject:
                 continue
             selected_tabs.append((tabid, domid, tabkwargs))
@@ -157,16 +158,20 @@
         w(u'</ul>')
         for tabid, domid, tabkwargs in tabs:
             w(u'<div id="%s">' % domid)
-            tabkwargs.setdefault('tabid', domid)
-            tabkwargs.setdefault('vid', tabid)
             tabkwargs.setdefault('rset', self.cw_rset)
-            self.lazyview(**tabkwargs)
+            if self.lazy:
+                tabkwargs.setdefault('tabid', domid)
+                tabkwargs.setdefault('vid', tabid)
+                self.lazyview(**tabkwargs)
+            else:
+                self._cw.view(tabid, w=self.w, **tabkwargs)
             w(u'</div>')
         w(u'</div>')
         # call the setTab() JS function *after* each tab is generated
         # because the callback binding needs to be done before
         # XXX make work history: true
-        self._cw.add_onload(u"""
+        if self.lazy:
+            self._cw.add_onload(u"""
   jQuery('#entity-tabs-%(eeid)s').tabs(
     { selected: %(tabindex)s,
       select: function(event, ui) {