author | sylvain.thenault@logilab.fr |
Wed, 22 Apr 2009 16:54:23 +0200 | |
branch | tls-sprint |
changeset 1421 | 77ee26df178f |
parent 1263 | 01152fffd593 |
child 1477 | b056a49c16dc |
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 |
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
4 |
:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
235
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 |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
13 |
from cubicweb.selectors import partial_has_related_entities |
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
940
diff
changeset
|
14 |
from cubicweb.view import EntityView |
1135 | 15 |
from cubicweb.common import tags, uilib |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
16 |
|
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
17 |
|
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
18 |
class LazyViewMixin(object): |
510
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
19 |
"""provides two convenience methods for the tab machinery |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
20 |
can also be used to lazy-load arbitrary views |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
21 |
caveat : lazyview is not recursive, i.e : you can't (successfully) |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
22 |
lazyload a view that in turns does the same |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
23 |
""" |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
24 |
|
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
25 |
def _prepare_bindings(self, vid, reloadable): |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
26 |
self.req.html_headers.add_onload(u""" |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
27 |
jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
28 |
load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s); |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
29 |
});""" % {'event': 'load_%s' % vid, 'vid': vid, |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
30 |
'reloadable' : str(reloadable).lower()}) |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
31 |
|
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
32 |
def lazyview(self, vid, rql=None, eid=None, rset=None, static=False, |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
33 |
reloadable=False, show_spinbox=True, w=None): |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
34 |
"""a lazy version of wview |
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
35 |
first version only support lazy viewing for an entity at a time |
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
36 |
""" |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
37 |
assert rql or eid or rset or static, \ |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
38 |
'lazyview wants at least : rql, or an eid, or an rset -- or call it with static=True' |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
39 |
w = w or self.w |
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
40 |
self.req.add_js('cubicweb.lazy.js') |
545
73aab1d2a27a
[tabs] fix the no-eid case, remove unused code
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
544
diff
changeset
|
41 |
urlparams = {'vid' : vid, 'mode' : 'html'} |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
42 |
if rql: |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
43 |
urlparams['rql'] = rql |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
44 |
elif eid: |
1135 | 45 |
urlparams['rql'] = uilib.rql_for_eid(eid) |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
46 |
elif rset: |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
47 |
urlparams['rql'] = rset.printable_rql() |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
48 |
w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
545
73aab1d2a27a
[tabs] fix the no-eid case, remove unused code
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
544
diff
changeset
|
49 |
vid, html_escape(self.build_url('json', **urlparams)))) |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
50 |
if show_spinbox: |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
51 |
w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>' |
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
52 |
% (vid, self.req._('loading'))) |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
53 |
w(u'</div>') |
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
54 |
self._prepare_bindings(vid, reloadable) |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
55 |
|
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
56 |
def forceview(self, vid): |
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
57 |
"""trigger an event that will force immediate loading of the view |
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
58 |
on dom readyness |
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
59 |
""" |
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
60 |
self.req.add_js('cubicweb.lazy.js') |
544
890e8d016d12
fix js syntax in tabs.forceview()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
543
diff
changeset
|
61 |
self.req.html_headers.add_onload("trigger_load('%s');" % vid) |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
62 |
|
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
63 |
|
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
64 |
class TabsMixin(LazyViewMixin): |
1079
452cb76fe07a
backport typo fix
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1000
diff
changeset
|
65 |
"""a tab mixin |
452cb76fe07a
backport typo fix
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1000
diff
changeset
|
66 |
""" |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
67 |
|
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
68 |
@property |
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
69 |
def cookie_name(self): |
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
70 |
return str('%s_active_tab' % self.config.appid) |
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
71 |
|
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
72 |
def active_tab(self, tabs, default): |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
73 |
cookies = self.req.get_cookie() |
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
74 |
cookiename = self.cookie_name |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
75 |
activetab = cookies.get(cookiename) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
76 |
if activetab is None: |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
77 |
cookies[cookiename] = default |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
78 |
self.req.set_cookie(cookies, cookiename) |
487
355356b781d7
[tabs] avoid nasty surprises when tab name change & the cookie remembers the past
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
485
diff
changeset
|
79 |
tab = default |
355356b781d7
[tabs] avoid nasty surprises when tab name change & the cookie remembers the past
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
485
diff
changeset
|
80 |
else: |
355356b781d7
[tabs] avoid nasty surprises when tab name change & the cookie remembers the past
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
485
diff
changeset
|
81 |
tab = activetab.value |
494
c47229797d0d
python 2.4 compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
490
diff
changeset
|
82 |
return tab in tabs and tab or default |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
83 |
|
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
84 |
def prune_tabs(self, tabs): |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
85 |
selected_tabs = [] |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
86 |
for tab in tabs: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
87 |
try: |
510
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
88 |
self.vreg.select_view(tab, self.req, self.rset) |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
89 |
selected_tabs.append(tab) |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
90 |
except NoSelectableObject: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
91 |
continue |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
92 |
return selected_tabs |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
93 |
|
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
94 |
def render_tabs(self, tabs, default, entity): |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
95 |
self.req.add_css('ui.tabs.css') |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
96 |
self.req.add_js(('ui.core.js', 'ui.tabs.js', |
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
97 |
'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) |
997
ee71c2ba73e6
[tabs] tabbed views don't support concatenation; when vid=primary is forced, delegate to the default tab/view #32176
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
917
diff
changeset
|
98 |
# tabbed views do no support concatenation |
ee71c2ba73e6
[tabs] tabbed views don't support concatenation; when vid=primary is forced, delegate to the default tab/view #32176
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
917
diff
changeset
|
99 |
# hence we delegate to the default tab |
1112
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
100 |
form = self.req.form |
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
101 |
if form.get('vid') == 'primary': |
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
102 |
entity.view(default, w=self.w) |
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
103 |
return |
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
104 |
rql = form.get('rql') |
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
105 |
if rql: |
3cfc208e385b
[tabs] don't spin madly when called in ajaxy/facet context; defer to default view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1079
diff
changeset
|
106 |
self.req.execute(rql).get_entity(0,0).view(default, w=self.w) |
997
ee71c2ba73e6
[tabs] tabbed views don't support concatenation; when vid=primary is forced, delegate to the default tab/view #32176
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
917
diff
changeset
|
107 |
return |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
108 |
# prune tabs : not all are to be shown |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
109 |
tabs = self.prune_tabs(tabs) |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
110 |
# select a tab |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
111 |
active_tab = self.active_tab(tabs, default) |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
112 |
# build the html structure |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
113 |
w = self.w |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
114 |
w(u'<div id="entity-tabs-%s">' % entity.eid) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
115 |
w(u'<ul>') |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
116 |
for tab in tabs: |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
117 |
w(u'<li>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
118 |
w(u'<a href="#as-%s">' % tab) |
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
119 |
w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name)) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
120 |
w(self.req._(tab)) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
121 |
w(u'</span>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
122 |
w(u'</a>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
123 |
w(u'</li>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
124 |
w(u'</ul>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
125 |
w(u'</div>') |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
126 |
for tab in tabs: |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
127 |
w(u'<div id="as-%s">' % tab) |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
128 |
self.lazyview(tab, eid=entity.eid) |
485
0f830732be19
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
235
diff
changeset
|
129 |
w(u'</div>') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
130 |
# call the set_tab() JS function *after* each tab is generated |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
131 |
# because the callback binding needs to be done before |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
132 |
self.req.html_headers.add_onload(u""" |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
133 |
jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s }); |
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
134 |
set_tab('%(vid)s', '%(cookiename)s'); |
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
135 |
""" % {'tabindex' : tabs.index(active_tab), |
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
136 |
'vid' : active_tab, |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
137 |
'eeid' : entity.eid, |
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
138 |
'cookiename' : self.cookie_name}) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
139 |
|
489 | 140 |
|
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
141 |
class EntityRelationView(EntityView): |
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
142 |
"""view displaying entity related stuff. |
489 | 143 |
Such a view _must_ provide the rtype, target and vid attributes : |
144 |
||
145 |
Example : |
|
146 |
||
147 |
class ProjectScreenshotsView(EntityRelationView): |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
148 |
'''display project's screenshots''' |
489 | 149 |
id = title = _('projectscreenshots') |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
150 |
__select__ = EntityRelationView.__select__ & implements('Project') |
489 | 151 |
rtype = 'screenshot' |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
152 |
role = 'subject' |
489 | 153 |
vid = 'gallery' |
154 |
||
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
155 |
in this example, entities related to project entity by the'screenshot' |
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
156 |
relation (where the project is subject of the relation) will be displayed |
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
157 |
using the 'gallery' view. |
489 | 158 |
""" |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
159 |
__select__ = EntityView.__select__ & partial_has_related_entities() |
489 | 160 |
vid = 'list' |
885
b101d2ae80b4
no need for both EntityRelatedTab / EntityRelatedView which are doing the same thing
sylvain.thenault@logilab.fr
parents:
838
diff
changeset
|
161 |
|
489 | 162 |
def cell_call(self, row, col): |
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
163 |
rset = self.entity(row, col).related(self.rtype, role(self)) |
489 | 164 |
self.w(u'<div class="mainInfo">') |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
165 |
if self.title: |
1014 | 166 |
self.w(tags.h1(self.req._(self.title))) |
489 | 167 |
self.wview(self.vid, rset, 'noresult') |
168 |
self.w(u'</div>') |