web/views/tabs.py
changeset 490 b84d64db2350
parent 489 21183fc36b39
child 494 c47229797d0d
equal deleted inserted replaced
489:21183fc36b39 490:b84d64db2350
    62             tab = default
    62             tab = default
    63         else:
    63         else:
    64             tab = activetab.value
    64             tab = activetab.value
    65         return tab if tab in tabs else default
    65         return tab if tab in tabs else default
    66 
    66 
       
    67     def prune_tabs(self, tabs):
       
    68         selected_tabs = []
       
    69         for tab in tabs:
       
    70             try:
       
    71                 tabview = self.vreg.select_view(tab, self.req, self.rset)
       
    72                 selected_tabs.append(tab)
       
    73             except NoSelectableObject:
       
    74                 continue
       
    75         return selected_tabs
       
    76 
    67     def render_tabs(self, tabs, default, entity):
    77     def render_tabs(self, tabs, default, entity):
    68         self.req.add_css('ui.tabs.css')
    78         self.req.add_css('ui.tabs.css')
    69         self.req.add_js(('ui.core.js', 'ui.tabs.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js'))
    79         self.req.add_js(('ui.core.js', 'ui.tabs.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js'))
       
    80         # prune tabs : not all are to be shown
       
    81         tabs = self.prune_tabs(tabs)
       
    82         # select a tab
    70         active_tab = self.active_tab(tabs, default)
    83         active_tab = self.active_tab(tabs, default)
    71         self.req.html_headers.add_post_inline_script(u"""
    84         self.req.html_headers.add_post_inline_script(u"""
    72  jQuery(document).ready(function() {
    85  jQuery(document).ready(function() {
    73    jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
    86    jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
    74    set_tab('%(vid)s');
    87    set_tab('%(vid)s');
    77         'vid'      : active_tab})
    90         'vid'      : active_tab})
    78         # build the html structure
    91         # build the html structure
    79         w = self.w
    92         w = self.w
    80         w(u'<div id="entity-tabs">')
    93         w(u'<div id="entity-tabs">')
    81         w(u'<ul>')
    94         w(u'<ul>')
    82         selected_tabs = []
       
    83         for tab in tabs:
    95         for tab in tabs:
    84             try:
       
    85                 tabview = self.vreg.select_view(tab, self.req, self.rset)
       
    86                 selected_tabs.append(tab)
       
    87             except NoSelectableObject:
       
    88                 self.info('no selectable view for id %s', tab)
       
    89                 continue
       
    90             w(u'<li>')
    96             w(u'<li>')
    91             w(u'<a href="#as-%s">' % tab)
    97             w(u'<a href="#as-%s">' % tab)
    92             w(u'<span onclick="set_tab(\'%s\')">' % tab)
    98             w(u'<span onclick="set_tab(\'%s\')">' % tab)
    93             w(self.req._(tab))
    99             w(self.req._(tab))
    94             w(u'</span>')
   100             w(u'</span>')
    95             w(u'</a>')
   101             w(u'</a>')
    96             w(u'</li>')
   102             w(u'</li>')
    97         w(u'</ul>')
   103         w(u'</ul>')
    98         w(u'</div>')
   104         w(u'</div>')
    99         for tab in selected_tabs:
   105         for tab in tabs:
   100             w(u'<div id="as-%s">' % tab)
   106             w(u'<div id="as-%s">' % tab)
   101             self.lazyview(tab, entity.eid)
   107             self.lazyview(tab, entity.eid)
   102             w(u'</div>')
   108             w(u'</div>')
   103 
   109 
   104 
   110