[tabs] from rev 917 - got lost in a merge
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 03 Mar 2009 15:16:04 +0100
changeset 1000 90705536b7c8
parent 999 999198995a53
child 1001 7d0fccdb8125
[tabs] from rev 917 - got lost in a merge
web/views/tabs.py
--- a/web/views/tabs.py	Tue Mar 03 15:06:03 2009 +0100
+++ b/web/views/tabs.py	Tue Mar 03 15:16:04 2009 +0100
@@ -1,7 +1,7 @@
 """base classes to handle tabbed views
 
 :organization: Logilab
-:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 
@@ -11,7 +11,7 @@
 from logilab.mtconverter import html_escape
 
 from cubicweb import NoSelectableObject, role
-from cubicweb.common.view import EntityView
+from cubicweb.common.view import EntityView 
 from cubicweb.common.selectors import has_related_entities
 from cubicweb.common.utils import HTMLHead
 from cubicweb.common.uilib import rql_for_eid
@@ -33,15 +33,22 @@
   });""" % {'event': 'load_%s' % vid, 'vid': vid,
             'reloadable' : str(reloadable).lower()})
 
-    def lazyview(self, vid, eid=None, reloadable=False, show_spinbox=True, w=None):
+    def lazyview(self, vid, rql=None, eid=None, rset=None, static=False,
+                 reloadable=False, show_spinbox=True, w=None):
         """a lazy version of wview
         first version only support lazy viewing for an entity at a time
         """
+        assert rql or eid or rset or static, \
+            'lazyview wants at least : rql, or an eid, or an rset -- or call it with static=True'
         w = w or self.w
         self.req.add_js('cubicweb.lazy.js')
         urlparams = {'vid' : vid, 'mode' : 'html'}
-        if eid:
+        if rql:
+            urlparams['rql'] = rql
+        elif eid:
             urlparams['rql'] = rql_for_eid(eid)
+        elif rset:
+            urlparams['rql'] = rset.printable_rql()
         w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % (
             vid, html_escape(self.build_url('json', **urlparams))))
         if show_spinbox:
@@ -65,12 +72,12 @@
         return str('%s_active_tab' % self.config.appid)
 
     def active_tab(self, tabs, default):
-        cookie = self.req.get_cookie()
+        cookies = self.req.get_cookie()
         cookiename = self.cookie_name
-        activetab = cookie.get(cookiename)
+        activetab = cookies.get(cookiename)
         if activetab is None:
-            cookie[cookiename] = default
-            self.req.set_cookie(cookie, cookiename)
+            cookies[cookiename] = default
+            self.req.set_cookie(cookies, cookiename)
             tab = default
         else:
             tab = activetab.value
@@ -101,7 +108,7 @@
         active_tab = self.active_tab(tabs, default)
         # build the html structure
         w = self.w
-        w(u'<div id="entity-tabs">')
+        w(u'<div id="entity-tabs-%s">' % entity.eid)
         w(u'<ul>')
         for tab in tabs:
             w(u'<li>')
@@ -115,15 +122,16 @@
         w(u'</div>')
         for tab in tabs:
             w(u'<div id="as-%s">' % tab)
-            self.lazyview(tab, entity.eid)
+            self.lazyview(tab, eid=entity.eid)
             w(u'</div>')
         # call the set_tab() JS function *after* each tab is generated
         # because the callback binding needs to be done before
         self.req.html_headers.add_onload(u"""
-   jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
+   jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s });
    set_tab('%(vid)s', '%(cookiename)s');
  """ % {'tabindex'   : tabs.index(active_tab),
         'vid'        : active_tab,
+        'eeid'       : entity.eid,
         'cookiename' : self.cookie_name})
 
 
@@ -143,11 +151,10 @@
         vid = 'gallery'
         __selectors__ = EntityRelationView.__selectors__ + (one_line_rset,)
 
-
     This is the view we want to have in a tab, only if there is something to show.
     Then, just define as below, and declare this being the tab content :
 
-    class ProjectScreenshotTab(DataDependantTab, ProjectScreenshotsView):
+    class ProjectScreenshotTab(EntityRelatedTab, ProjectScreenshotsView):
         id = 'screenshots_tab'
     """
     __selectors__ = EntityView.__selectors__ + (has_related_entities,)