author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 09 Oct 2009 15:10:17 +0200 | |
branch | stable |
changeset 3625 | f03b55a18c43 |
parent 3576 | a9ed6f7cf2c2 |
child 3589 | a5432f99f2d9 |
child 3779 | bb44b3a522fe |
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 |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
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 |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
235
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 |
|
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
9 |
__docformat__ = "restructuredtext en" |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
10 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2264
diff
changeset
|
11 |
from logilab.mtconverter import xml_escape |
214
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 |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
14 |
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
|
15 |
from cubicweb.view import EntityView |
1135 | 16 |
from cubicweb.common import tags, uilib |
1997
554eb4dd533d
[views] get tabs to work with startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
17 |
from cubicweb.utils import make_uid |
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
18 |
from cubicweb.web.views import primary |
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
|
19 |
|
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 |
class LazyViewMixin(object): |
510
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
21 |
"""provides two convenience methods for the tab machinery |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
22 |
can also be used to lazy-load arbitrary views |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
23 |
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
|
24 |
lazyload a view that in turns does the same |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
25 |
""" |
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
|
26 |
|
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
27 |
def _prepare_bindings(self, vid, reloadable): |
2258
79bc598c6411
when request is a json request, bind on 'ajax-loaded' instead of document.ready()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1997
diff
changeset
|
28 |
self.req.add_onload(u""" |
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
29 |
jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
30 |
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
|
31 |
});""" % {'event': 'load_%s' % vid, 'vid': vid, |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
32 |
'reloadable' : str(reloadable).lower()}) |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
33 |
|
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
34 |
def lazyview(self, vid, rql=None, eid=None, rset=None, tabid=None, |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
35 |
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
|
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') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
41 |
urlparams = {'vid' : vid, 'fname' : 'view'} |
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">' % ( |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
49 |
tabid or vid, xml_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"/>' |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
52 |
% (tabid or 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>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
54 |
self._prepare_bindings(tabid or 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') |
2258
79bc598c6411
when request is a json request, bind on 'ajax-loaded' instead of document.ready()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1997
diff
changeset
|
61 |
self.req.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 |
|
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
72 |
def active_tab(self, default): |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
73 |
if 'tab' in self.req.form: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
74 |
return self.req.form['tab'] |
1000
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
activetab = cookies.get(cookiename) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
78 |
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
|
79 |
cookies[cookiename] = default |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
80 |
self.req.set_cookie(cookies, cookiename) |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
81 |
return default |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
82 |
return activetab.value |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
83 |
|
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
84 |
def prune_tabs(self, tabs, default_tab): |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
85 |
selected_tabs = [] |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
86 |
may_be_active_tab = self.active_tab(default_tab) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
87 |
active_tab = default_tab |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
88 |
viewsvreg = self.vreg['views'] |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
89 |
for tab in tabs: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
90 |
try: |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
91 |
tabid, tabkwargs = tab |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
92 |
tabkwargs = tabkwargs.copy() |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
93 |
except ValueError: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
94 |
tabid, tabkwargs = tab, {} |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
95 |
tabkwargs.setdefault('rset', self.rset) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
96 |
vid = tabkwargs.get('vid', tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
97 |
try: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
98 |
viewsvreg.select(vid, self.req, **tabkwargs) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
99 |
selected_tabs.append((tabid, tabkwargs)) |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
100 |
except NoSelectableObject: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
101 |
continue |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
102 |
if tabid == may_be_active_tab: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
103 |
active_tab = tabid |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
104 |
return selected_tabs, active_tab |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
105 |
|
1997
554eb4dd533d
[views] get tabs to work with startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
106 |
def render_tabs(self, tabs, default, entity=None): |
2264 | 107 |
# delegate to the default tab if there is more than one entity |
108 |
# in the result set (tabs are pretty useless there) |
|
1997
554eb4dd533d
[views] get tabs to work with startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
109 |
if entity and len(self.rset) > 1: |
1379
6c6dbc0df829
MUST NOT consider req.form['rql'] in a view, use len(rset) > 1 to detect if we can apply tabs or not
sylvain.thenault@logilab.fr
parents:
1112
diff
changeset
|
110 |
entity.view(default, w=self.w) |
6c6dbc0df829
MUST NOT consider req.form['rql'] in a view, use len(rset) > 1 to detect if we can apply tabs or not
sylvain.thenault@logilab.fr
parents:
1112
diff
changeset
|
111 |
return |
2673
9e639925ca2f
Backed out changeset 3e1d2ab5f8c0 (restore ui.tabs.js instead of jquery tools)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2123
diff
changeset
|
112 |
self.req.add_css('ui.tabs.css') |
9e639925ca2f
Backed out changeset 3e1d2ab5f8c0 (restore ui.tabs.js instead of jquery tools)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2123
diff
changeset
|
113 |
self.req.add_js(('ui.core.js', 'ui.tabs.js', |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
114 |
'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
|
115 |
# prune tabs : not all are to be shown |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
116 |
tabs, active_tab = self.prune_tabs(tabs, default) |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
117 |
# build the html structure |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
118 |
w = self.w |
2386
b246d5cee44e
[tabs] backport entity-less support for tabs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2383
diff
changeset
|
119 |
uid = entity and entity.eid or make_uid('tab') |
b246d5cee44e
[tabs] backport entity-less support for tabs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2383
diff
changeset
|
120 |
w(u'<div id="entity-tabs-%s">' % uid) |
2673
9e639925ca2f
Backed out changeset 3e1d2ab5f8c0 (restore ui.tabs.js instead of jquery tools)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2123
diff
changeset
|
121 |
w(u'<ul>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
122 |
active_tab_idx = None |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
123 |
for i, (tabid, tabkwargs) in enumerate(tabs): |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
124 |
w(u'<li>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
125 |
w(u'<a href="#%s">' % tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
126 |
w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tabid, self.cookie_name)) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
127 |
w(tabkwargs.pop('label', self.req._(tabid))) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
128 |
w(u'</span>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
129 |
w(u'</a>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
130 |
w(u'</li>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
131 |
if tabid == active_tab: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
132 |
active_tab_idx = i |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
133 |
w(u'</ul>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
134 |
w(u'</div>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
135 |
for tabid, tabkwargs in tabs: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
136 |
w(u'<div id="%s">' % tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
137 |
tabkwargs.setdefault('tabid', tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
138 |
tabkwargs.setdefault('vid', tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
139 |
tabkwargs.setdefault('rset', self.rset) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
140 |
self.lazyview(**tabkwargs) |
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
|
141 |
w(u'</div>') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
142 |
# 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
|
143 |
# because the callback binding needs to be done before |
2383
96780c1e0c53
shrink a bit the tabs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
144 |
# XXX make work history: true |
3026
17644247f0ff
fix emacs syntaxic colorization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2675
diff
changeset
|
145 |
self.req.add_onload(u""" |
2674
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
146 |
jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s }); |
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
147 |
set_tab('%(vid)s', '%(cookiename)s'); |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
148 |
""" % {'tabindex' : active_tab_idx, |
2674
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
149 |
'vid' : active_tab, |
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
150 |
'eeid' : (entity and entity.eid or uid), |
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
151 |
'cookiename' : self.cookie_name}) |
489 | 152 |
|
3026
17644247f0ff
fix emacs syntaxic colorization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2675
diff
changeset
|
153 |
|
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
154 |
class EntityRelationView(EntityView): |
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
155 |
"""view displaying entity related stuff. |
489 | 156 |
Such a view _must_ provide the rtype, target and vid attributes : |
157 |
||
158 |
Example : |
|
159 |
||
160 |
class ProjectScreenshotsView(EntityRelationView): |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
161 |
'''display project's screenshots''' |
489 | 162 |
id = title = _('projectscreenshots') |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
163 |
__select__ = EntityRelationView.__select__ & implements('Project') |
489 | 164 |
rtype = 'screenshot' |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
165 |
role = 'subject' |
489 | 166 |
vid = 'gallery' |
167 |
||
3209
c2c8f88a4520
allow user to give ?tab=tabname and be set to the right tab (part of #345399)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3026
diff
changeset
|
168 |
in this example, entities related to project entity by the 'screenshot' |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
169 |
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
|
170 |
using the 'gallery' view. |
489 | 171 |
""" |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
172 |
__select__ = EntityView.__select__ & partial_has_related_entities() |
489 | 173 |
vid = 'list' |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1498
diff
changeset
|
174 |
|
489 | 175 |
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
|
176 |
rset = self.entity(row, col).related(self.rtype, role(self)) |
489 | 177 |
self.w(u'<div class="mainInfo">') |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
178 |
if self.title: |
1014 | 179 |
self.w(tags.h1(self.req._(self.title))) |
489 | 180 |
self.wview(self.vid, rset, 'noresult') |
181 |
self.w(u'</div>') |
|
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
182 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
183 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
184 |
class TabedPrimaryView(TabsMixin, primary.PrimaryView): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
185 |
__abstract__ = True # don't register |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
186 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
187 |
tabs = ['main_tab'] |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
188 |
default_tab = 'main_tab' |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
189 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
190 |
def cell_call(self, row, col): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
191 |
entity = self.complete_entity(row, col) |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
192 |
self.render_entity_title(entity) |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
193 |
self.render_entity_metadata(entity) |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
194 |
self.render_tabs(self.tabs, self.default_tab, entity) |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
195 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
196 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
197 |
class PrimaryTab(primary.PrimaryView): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
198 |
id = 'main_tab' |
3576
a9ed6f7cf2c2
set title to None so it doesn't appears in possible views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3570
diff
changeset
|
199 |
title = None |
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
200 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
201 |
def is_primary(self): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
202 |
return True |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
203 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
204 |
def render_entity_title(self, entity): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
205 |
pass |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
206 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
207 |
def render_entity_metadata(self, entity): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
208 |
pass |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
209 |