author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 30 Jan 2009 16:57:20 +0100 | |
changeset 543 | c0f2b6378f70 |
parent 542 | 46d4ff5aa917 |
child 544 | 890e8d016d12 |
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 |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
10 |
from logilab.common.decorators import monkeypatch |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
11 |
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
|
12 |
|
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
13 |
from cubicweb import NoSelectableObject, role |
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 |
489 | 15 |
from cubicweb.common.selectors import has_related_entities |
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
16 |
from cubicweb.common.utils import HTMLHead |
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
17 |
from cubicweb.common.uilib import rql_for_eid |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
18 |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
19 |
from cubicweb.web.views.basecontrollers import JSonController |
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
|
20 |
|
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
|
21 |
# the prepend hack only work for 1-level lazy views |
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
|
22 |
# a whole lot different thing must be done otherwise |
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
23 |
@monkeypatch(HTMLHead) |
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 |
def prepend_post_inline_script(self, content): |
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
|
25 |
self.post_inlined_scripts.insert(0, content) |
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
26 |
|
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
|
27 |
|
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
|
28 |
class LazyViewMixin(object): |
510
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
29 |
"""provides two convenience methods for the tab machinery |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
30 |
can also be used to lazy-load arbitrary views |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
31 |
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
|
32 |
lazyload a view that in turns does the same |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
33 |
""" |
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 |
|
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 |
def lazyview(self, vid, eid=None, show_spinbox=True, w=None): |
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 |
"""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
|
37 |
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
|
38 |
""" |
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') |
494
c47229797d0d
python 2.4 compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
490
diff
changeset
|
41 |
eid = eid or '' |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
42 |
# w(u'<div id="lazy-%s" cubicweb:loadurl="%s-%s">' % (vid, vid, eid)) |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
43 |
w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
44 |
vid, html_escape(self.build_url('json', rql=rql_for_eid(eid), vid=vid, |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
45 |
mode='html')))) |
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
|
46 |
if show_spinbox: |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
47 |
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
|
48 |
% (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
|
49 |
w(u'</div>') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
50 |
self.req.html_headers.add_onload(u""" |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
51 |
jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
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
|
52 |
load_now('#lazy-%(vid)s', '#%(vid)s-hole'); |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
53 |
});""" % {'event': 'load_%s' % vid, 'vid': vid}) |
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
|
54 |
|
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 |
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
|
56 |
"""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
|
57 |
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
|
58 |
""" |
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 |
self.req.add_js('.lazy.js') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
60 |
self.req.html_headers.add_onload("trigger_load('%s');})" % vid) |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
61 |
|
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
|
62 |
|
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 |
class TabsMixin(LazyViewMixin): |
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 |
|
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
|
65 |
def active_tab(self, tabs, default): |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
66 |
cookie = self.req.get_cookie() |
504
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
67 |
cookiename = '%s_active_tab' % self.config.appid |
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
68 |
activetab = cookie.get(cookiename) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
69 |
if activetab is None: |
504
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
70 |
cookie[cookiename] = default |
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
71 |
self.req.set_cookie(cookie, 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
|
72 |
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
|
73 |
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
|
74 |
tab = activetab.value |
494
c47229797d0d
python 2.4 compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
490
diff
changeset
|
75 |
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
|
76 |
|
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
77 |
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
|
78 |
selected_tabs = [] |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
79 |
for tab in tabs: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
80 |
try: |
510
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
81 |
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
|
82 |
selected_tabs.append(tab) |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
83 |
except NoSelectableObject: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
84 |
continue |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
85 |
return selected_tabs |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
86 |
|
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
|
87 |
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
|
88 |
self.req.add_css('ui.tabs.css') |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
89 |
self.req.add_js(('ui.core.js', 'ui.tabs.js', |
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
90 |
'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
91 |
# 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
|
92 |
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
|
93 |
# 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
|
94 |
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
|
95 |
# build the html structure |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
96 |
w = self.w |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
97 |
w(u'<div id="entity-tabs">') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
98 |
w(u'<ul>') |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
99 |
for tab in tabs: |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
100 |
w(u'<li>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
101 |
w(u'<a href="#as-%s">' % tab) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
102 |
w(u'<span onclick="set_tab(\'%s\')">' % tab) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
103 |
w(self.req._(tab)) |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
104 |
w(u'</span>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
105 |
w(u'</a>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
106 |
w(u'</li>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
107 |
w(u'</ul>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
108 |
w(u'</div>') |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
109 |
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
|
110 |
w(u'<div id="as-%s">' % tab) |
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 |
self.lazyview(tab, entity.eid) |
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
|
112 |
w(u'</div>') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
113 |
# 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
|
114 |
# 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
|
115 |
self.req.html_headers.add_onload(u""" |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
116 |
jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
117 |
set_tab('%(vid)s'); |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
118 |
""" % {'tabindex' : tabs.index(active_tab), |
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
119 |
'vid' : active_tab}) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
120 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
121 |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
122 |
@monkeypatch(JSonController) |
498 | 123 |
def js_remember_active_tab(self, tabname): |
124 |
cookie = self.req.get_cookie() |
|
504
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
125 |
cookiename = '%s_active_tab' % self.config.appid |
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
126 |
cookie[cookiename] = tabname |
459e50669d96
[tabs] cookie name par cube instance will reduce cookie collisions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
498
diff
changeset
|
127 |
self.req.set_cookie(cookie, cookiename) |
489 | 128 |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
129 |
@monkeypatch(JSonController) |
498 | 130 |
def js_lazily(self, vid_eid): |
131 |
vid, eid = vid_eid.split('-') |
|
132 |
rset = eid and self.req.eid_rset(eid) or None |
|
133 |
view = self.vreg.select_view(vid, self.req, rset) |
|
134 |
return self._set_content_type(view, view.dispatch()) |
|
489 | 135 |
|
498 | 136 |
|
137 |
class EntityRelatedTab(EntityView): |
|
489 | 138 |
"""A view you should inherit from leftmost, |
139 |
to wrap another actual view displaying entity related stuff. |
|
140 |
Such a view _must_ provide the rtype, target and vid attributes : |
|
141 |
||
142 |
Example : |
|
143 |
||
144 |
class ProjectScreenshotsView(EntityRelationView): |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
145 |
'''display project's screenshots''' |
489 | 146 |
id = title = _('projectscreenshots') |
147 |
accepts = ('Project',) |
|
148 |
rtype = 'screenshot' |
|
149 |
target = 'object' |
|
150 |
vid = 'gallery' |
|
151 |
__selectors__ = EntityRelationView.__selectors__ + (one_line_rset,) |
|
152 |
||
153 |
||
154 |
This is the view we want to have in a tab, only if there is something to show. |
|
155 |
Then, just define as below, and declare this being the tab content : |
|
156 |
||
157 |
class ProjectScreenshotTab(DataDependantTab, ProjectScreenshotsView): |
|
158 |
id = 'screenshots_tab' |
|
159 |
""" |
|
160 |
__selectors__ = EntityView.__selectors__ + (has_related_entities,) |
|
161 |
vid = 'list' |
|
162 |
||
163 |
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
|
164 |
rset = self.entity(row, col).related(self.rtype, role(self)) |
489 | 165 |
self.w(u'<div class="mainInfo">') |
166 |
self.wview(self.vid, rset, 'noresult') |
|
167 |
self.w(u'</div>') |