web/views/tabs.py
branchtreeview-tabs
changeset 917 51d5224b1698
parent 606 40c7c2cf0797
child 923 7c184924d492
child 939 ad72e06320e2
child 997 ee71c2ba73e6
--- a/web/views/tabs.py	Fri Feb 20 20:48:33 2009 +0100
+++ b/web/views/tabs.py	Fri Feb 20 20:50:05 2009 +0100
@@ -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
@@ -96,7 +103,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>')
@@ -110,15 +117,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})
 
 
@@ -138,11 +146,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,)