1 from logilab.mtconverter import html_escape |
|
2 |
|
3 from cubicweb.common.view import EntityView |
|
4 |
|
5 # XXX |
|
6 # This is premature & tied to JPL |
|
7 # It should go away & be replaced by something like |
|
8 # a TabbedPrimaryView (that would really a primary view) |
|
9 |
|
10 class TabView(EntityView): |
|
11 id = 'tabview' |
|
12 accepts = ('Project',) |
|
13 |
|
14 def active_tab(self): |
|
15 cookie = self.req.get_cookie() |
|
16 cookietab = cookie.get('active_tab') |
|
17 if cookietab is None: |
|
18 cookie['active_tab'] = 'project_main' |
|
19 self.req.set_cookie(cookie, 'active_tab') |
|
20 return cookietab and cookietab.value or 'project_main' |
|
21 |
|
22 def cell_call(self, row, col, tabs): |
|
23 self.req.add_css('ui.tabs.css') |
|
24 self.req.add_js( ('ui.core.js', 'ui.tabs.js', 'cubes.jpl.primary.js') ) |
|
25 active_tab = self.active_tab() |
|
26 self.req.html_headers.add_post_inline_script(u""" |
|
27 jQuery(document).ready(function() { |
|
28 jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); |
|
29 set_tab('%(vid)s'); |
|
30 }); |
|
31 """ % {'tabindex' : tabs.index(active_tab), |
|
32 'vid' : active_tab}) |
|
33 # build the html structure |
|
34 self.w(u'<div id="entity-tabs">') |
|
35 self.w(u'<ul>') |
|
36 for tab in tabs: |
|
37 self.w(u'<li>') |
|
38 self.w(u'<a href="#as-%s">' % tab) |
|
39 cookie_setter = "set_tab('%s')" % tab |
|
40 self.w(u'<span onclick="%s">' % cookie_setter) |
|
41 self.w('%s' % self.req._(tab)) |
|
42 self.w(u'</span>') |
|
43 self.w(u'</a>') |
|
44 self.w(u'</li>') |
|
45 self.w(u'</ul>') |
|
46 self.w(u'</div>') |
|
47 for tab in tabs: |
|
48 self.w(u'<div id="as-%s">' % tab) |
|
49 self.wview(tab, self.rset) |
|
50 self.w(u'</div>') |
|
51 |
|