[tabs] reuse the new set_cookie controller method
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 11 Feb 2009 19:11:55 +0100
changeset 606 40c7c2cf0797
parent 605 1a23781534a2
child 607 47f2ee781d6d
[tabs] reuse the new set_cookie controller method
web/data/cubicweb.tabs.js
web/views/tabs.py
--- a/web/data/cubicweb.tabs.js	Wed Feb 11 18:47:12 2009 +0100
+++ b/web/data/cubicweb.tabs.js	Wed Feb 11 19:11:55 2009 +0100
@@ -1,7 +1,6 @@
-function set_tab(tabname) {
+function set_tab(tabname, cookiename) {
     // set appropriate cookie
-    // XXX see if we can no just do it with jQuery
-    async_remote_exec('remember_active_tab', tabname);
+    async_remote_exec('set_cookie', cookiename, tabname);
     // trigger show + tabname event
     trigger_load(tabname);
 }
--- a/web/views/tabs.py	Wed Feb 11 18:47:12 2009 +0100
+++ b/web/views/tabs.py	Wed Feb 11 19:11:55 2009 +0100
@@ -60,9 +60,13 @@
 
 class TabsMixin(LazyViewMixin):
 
+    @property
+    def cookie_name(self):
+        return str('%s_active_tab' % self.config.appid)
+
     def active_tab(self, tabs, default):
         cookie = self.req.get_cookie()
-        cookiename = '%s_active_tab' % self.config.appid
+        cookiename = self.cookie_name
         activetab = cookie.get(cookiename)
         if activetab is None:
             cookie[cookiename] = default
@@ -97,7 +101,7 @@
         for tab in tabs:
             w(u'<li>')
             w(u'<a href="#as-%s">' % tab)
-            w(u'<span onclick="set_tab(\'%s\')">' % tab)
+            w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name))
             w(self.req._(tab))
             w(u'</span>')
             w(u'</a>')
@@ -112,17 +116,11 @@
         # because the callback binding needs to be done before
         self.req.html_headers.add_onload(u"""
    jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
-   set_tab('%(vid)s');
- """ % {'tabindex' : tabs.index(active_tab),
-        'vid'      : active_tab})
-
+   set_tab('%(vid)s', '%(cookiename)s');
+ """ % {'tabindex'   : tabs.index(active_tab),
+        'vid'        : active_tab,
+        'cookiename' : self.cookie_name})
 
-@monkeypatch(JSonController)
-def js_remember_active_tab(self, tabname):
-    cookie = self.req.get_cookie()
-    cookiename = '%s_active_tab' % self.config.appid
-    cookie[cookiename] = tabname
-    self.req.set_cookie(cookie, cookiename)
 
 class EntityRelatedTab(EntityView):
     """A view you should inherit from leftmost,