web/views/tabs.py
changeset 606 40c7c2cf0797
parent 559 7cfd3d11edc8
child 688 cddfbdee0eb3
child 917 51d5224b1698
equal deleted inserted replaced
605:1a23781534a2 606:40c7c2cf0797
    58         self.req.html_headers.add_onload("trigger_load('%s');" % vid)
    58         self.req.html_headers.add_onload("trigger_load('%s');" % vid)
    59 
    59 
    60 
    60 
    61 class TabsMixin(LazyViewMixin):
    61 class TabsMixin(LazyViewMixin):
    62 
    62 
       
    63     @property
       
    64     def cookie_name(self):
       
    65         return str('%s_active_tab' % self.config.appid)
       
    66 
    63     def active_tab(self, tabs, default):
    67     def active_tab(self, tabs, default):
    64         cookie = self.req.get_cookie()
    68         cookie = self.req.get_cookie()
    65         cookiename = '%s_active_tab' % self.config.appid
    69         cookiename = self.cookie_name
    66         activetab = cookie.get(cookiename)
    70         activetab = cookie.get(cookiename)
    67         if activetab is None:
    71         if activetab is None:
    68             cookie[cookiename] = default
    72             cookie[cookiename] = default
    69             self.req.set_cookie(cookie, cookiename)
    73             self.req.set_cookie(cookie, cookiename)
    70             tab = default
    74             tab = default
    95         w(u'<div id="entity-tabs">')
    99         w(u'<div id="entity-tabs">')
    96         w(u'<ul>')
   100         w(u'<ul>')
    97         for tab in tabs:
   101         for tab in tabs:
    98             w(u'<li>')
   102             w(u'<li>')
    99             w(u'<a href="#as-%s">' % tab)
   103             w(u'<a href="#as-%s">' % tab)
   100             w(u'<span onclick="set_tab(\'%s\')">' % tab)
   104             w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name))
   101             w(self.req._(tab))
   105             w(self.req._(tab))
   102             w(u'</span>')
   106             w(u'</span>')
   103             w(u'</a>')
   107             w(u'</a>')
   104             w(u'</li>')
   108             w(u'</li>')
   105         w(u'</ul>')
   109         w(u'</ul>')
   110             w(u'</div>')
   114             w(u'</div>')
   111         # call the set_tab() JS function *after* each tab is generated
   115         # call the set_tab() JS function *after* each tab is generated
   112         # because the callback binding needs to be done before
   116         # because the callback binding needs to be done before
   113         self.req.html_headers.add_onload(u"""
   117         self.req.html_headers.add_onload(u"""
   114    jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
   118    jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
   115    set_tab('%(vid)s');
   119    set_tab('%(vid)s', '%(cookiename)s');
   116  """ % {'tabindex' : tabs.index(active_tab),
   120  """ % {'tabindex'   : tabs.index(active_tab),
   117         'vid'      : active_tab})
   121         'vid'        : active_tab,
       
   122         'cookiename' : self.cookie_name})
   118 
   123 
   119 
       
   120 @monkeypatch(JSonController)
       
   121 def js_remember_active_tab(self, tabname):
       
   122     cookie = self.req.get_cookie()
       
   123     cookiename = '%s_active_tab' % self.config.appid
       
   124     cookie[cookiename] = tabname
       
   125     self.req.set_cookie(cookie, cookiename)
       
   126 
   124 
   127 class EntityRelatedTab(EntityView):
   125 class EntityRelatedTab(EntityView):
   128     """A view you should inherit from leftmost,
   126     """A view you should inherit from leftmost,
   129     to wrap another actual view displaying entity related stuff.
   127     to wrap another actual view displaying entity related stuff.
   130     Such a view _must_ provide the rtype, target and vid attributes :
   128     Such a view _must_ provide the rtype, target and vid attributes :