author | Sylvain Thenault <sylvain.thenault@logilab.fr> |
Fri, 19 Dec 2008 14:54:35 +0100 | |
changeset 235 | b43362d92a1d |
parent 220 | web/views/tabview.py@196df28218dc |
child 485 | 0f830732be19 |
permissions | -rw-r--r-- |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
1 |
"""base classes to handle tabbed views |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
2 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
3 |
:organization: Logilab |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
4 |
:copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
6 |
""" |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
7 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
9 |
|
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
10 |
from logilab.mtconverter import html_escape |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
11 |
|
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
12 |
from cubicweb import NoSelectableObject, role |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
13 |
from cubicweb.common.selectors import has_related_entities |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
14 |
from cubicweb.common.view import EntityView |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
15 |
|
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
16 |
class TabsMixIn(object): |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
17 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
18 |
def active_tab(self, default): |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
19 |
cookie = self.req.get_cookie() |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
20 |
activetab = cookie.get('active_tab') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
21 |
if activetab is None: |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
22 |
cookie['active_tab'] = default |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
23 |
self.req.set_cookie(cookie, 'active_tab') |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
24 |
return default |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
25 |
return activetab.value |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
26 |
|
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
27 |
def render_tabs(self, tabs, default, **kwargs): |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
28 |
self.req.add_css('ui.tabs.css') |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
29 |
self.req.add_js( ('ui.core.js', 'ui.tabs.js', 'cubicweb.tabs.js') ) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
30 |
active_tab = self.active_tab(default) |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
31 |
self.req.html_headers.add_post_inline_script(u""" |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
32 |
jQuery(document).ready(function() { |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
33 |
jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
34 |
set_tab('%(vid)s'); |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
35 |
}); |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
36 |
""" % {'tabindex' : tabs.index(active_tab), |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
37 |
'vid' : active_tab}) |
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
38 |
# build the html structure |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
39 |
w = self.w |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
40 |
w(u'<div id="entity-tabs">') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
41 |
w(u'<ul>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
42 |
tabviews = [] |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
43 |
for tab in tabs: |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
44 |
try: |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
45 |
tabview = self.vreg.select_view(tab, self.req, self.rset, **kwargs) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
46 |
except NoSelectableObject: |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
47 |
continue |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
48 |
tabviews.append(tabview) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
49 |
w(u'<li>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
50 |
w(u'<a href="#as-%s">' % tab) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
51 |
w(u'<span onclick="set_tab(\'%s\')">' % tab) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
52 |
w(self.req._(tab)) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
53 |
w(u'</span>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
54 |
w(u'</a>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
55 |
w(u'</li>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
56 |
w(u'</ul>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
57 |
w(u'</div>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
58 |
# XXX ajaxify ! |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
59 |
for tabview in tabviews: |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
60 |
w(u'<div id="as-%s">' % tabview.id) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
61 |
tabview.dispatch(w=self.w, **kwargs) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
62 |
w(u'</div>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
63 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
64 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
65 |
class EntityRelationTab(EntityView): |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
66 |
__selectors__ = EntityView.__selectors__ + (has_related_entities,) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
67 |
vid = 'list' |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
68 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
69 |
def cell_call(self, row, col): |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
70 |
rset = self.rset.get_entity(row, col).related(self.rtype, role(self)) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
71 |
self.w(u'<div class="mainInfo">') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
72 |
self.wview(self.vid, rset, 'noresult') |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
73 |
self.w(u'</div>') |