author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 18 Mar 2010 14:06:53 +0100 | |
branch | stable |
changeset 4941 | ec27aea9632b |
parent 4727 | 946a9db5405d |
child 5151 | 2f70fa8b6854 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3929
diff
changeset
|
4 |
:copyright: 2008-2010 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 |
|
4602
fe5aad04f08b
proper deprecation of TabedPrimaryView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4601
diff
changeset
|
11 |
from logilab.common.deprecation import class_renamed |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2264
diff
changeset
|
12 |
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
|
13 |
|
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
14 |
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
|
15 |
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
|
16 |
from cubicweb.view import EntityView |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
17 |
from cubicweb import tags, uilib |
1997
554eb4dd533d
[views] get tabs to work with startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
18 |
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
|
19 |
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
|
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 |
class LazyViewMixin(object): |
510
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
22 |
"""provides two convenience methods for the tab machinery |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
23 |
can also be used to lazy-load arbitrary views |
6b92504d77c1
[tabs] improve pylint note :)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
504
diff
changeset
|
24 |
""" |
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
|
25 |
|
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
26 |
def _prepare_bindings(self, vid, reloadable): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
27 |
self._cw.add_onload(u""" |
559
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
28 |
jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
29 |
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
|
30 |
});""" % {'event': 'load_%s' % vid, 'vid': vid, |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
31 |
'reloadable' : str(reloadable).lower()}) |
7cfd3d11edc8
[tabs] prepare for reloadability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
547
diff
changeset
|
32 |
|
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
"""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
|
36 |
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
|
37 |
""" |
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 |
w = w or self.w |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
39 |
self._cw.add_js('cubicweb.lazy.js') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
40 |
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
|
41 |
if rql: |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
42 |
urlparams['rql'] = rql |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
43 |
elif eid: |
1135 | 44 |
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
|
45 |
elif rset: |
90705536b7c8
[tabs] from rev 917 - got lost in a merge
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
46 |
urlparams['rql'] = rset.printable_rql() |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
47 |
w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
3589 | 48 |
tabid or vid, xml_escape(self._cw.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
|
49 |
if show_spinbox: |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
50 |
w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>' |
4727
946a9db5405d
tabs/lazy views: provide a link for the no js user agents (lynx, blinds, google) #693670
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4602
diff
changeset
|
51 |
% (tabid or vid, self._cw._('(loading ...)'))) |
946a9db5405d
tabs/lazy views: provide a link for the no js user agents (lynx, blinds, google) #693670
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4602
diff
changeset
|
52 |
w(u'<noscript><p><a class="style: hidden" id="seo-%s" href="%s">%s</a></p></noscript>' |
946a9db5405d
tabs/lazy views: provide a link for the no js user agents (lynx, blinds, google) #693670
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4602
diff
changeset
|
53 |
% (tabid or vid, xml_escape(self._cw.build_url(**urlparams)), xml_escape('%s (%s)') % |
946a9db5405d
tabs/lazy views: provide a link for the no js user agents (lynx, blinds, google) #693670
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4602
diff
changeset
|
54 |
(tabid or vid, self._cw._('follow this link if javascript is deactivated')))) |
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 |
w(u'</div>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
56 |
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
|
57 |
|
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 |
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
|
59 |
"""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
|
60 |
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
|
61 |
""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
62 |
self._cw.add_js('cubicweb.lazy.js') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
63 |
self._cw.add_onload("trigger_load('%s');" % vid) |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
64 |
|
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
|
65 |
|
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
|
66 |
class TabsMixin(LazyViewMixin): |
1079
452cb76fe07a
backport typo fix
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1000
diff
changeset
|
67 |
"""a tab mixin |
452cb76fe07a
backport typo fix
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1000
diff
changeset
|
68 |
""" |
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
|
69 |
|
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
70 |
@property |
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
71 |
def cookie_name(self): |
4085
002ba2a3bb13
api update again
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
72 |
return str('%s_active_tab' % self._cw.vreg.config.appid) |
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
73 |
|
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
74 |
def active_tab(self, default): |
3589 | 75 |
if 'tab' in self._cw.form: |
76 |
return self._cw.form['tab'] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
77 |
cookies = self._cw.get_cookie() |
606
40c7c2cf0797
[tabs] reuse the new set_cookie controller method
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
559
diff
changeset
|
78 |
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
|
79 |
activetab = cookies.get(cookiename) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
80 |
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
|
81 |
cookies[cookiename] = default |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
82 |
self._cw.set_cookie(cookies, cookiename) |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
83 |
return default |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
84 |
return activetab.value |
214
aaf2957bf69e
tabview is used to call each view for each tab
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
diff
changeset
|
85 |
|
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
86 |
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
|
87 |
selected_tabs = [] |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
88 |
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
|
89 |
active_tab = default_tab |
3589 | 90 |
viewsvreg = self._cw.vreg['views'] |
490
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
91 |
for tab in tabs: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
92 |
try: |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
93 |
tabid, tabkwargs = tab |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
94 |
tabkwargs = tabkwargs.copy() |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
95 |
except ValueError: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
96 |
tabid, tabkwargs = tab, {} |
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3645
diff
changeset
|
97 |
tabkwargs.setdefault('rset', self.cw_rset) |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
98 |
vid = tabkwargs.get('vid', tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
99 |
try: |
3589 | 100 |
viewsvreg.select(vid, self._cw, **tabkwargs) |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
101 |
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
|
102 |
except NoSelectableObject: |
b84d64db2350
[tabs] prune tab set _before_ computing & setting 'active' tab
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
489
diff
changeset
|
103 |
continue |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
104 |
if tabid == may_be_active_tab: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
105 |
active_tab = tabid |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
106 |
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
|
107 |
|
1997
554eb4dd533d
[views] get tabs to work with startup views
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
108 |
def render_tabs(self, tabs, default, entity=None): |
2264 | 109 |
# delegate to the default tab if there is more than one entity |
110 |
# in the result set (tabs are pretty useless there) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
111 |
if entity and len(self.cw_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
|
112 |
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
|
113 |
return |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
114 |
self._cw.add_css('ui.tabs.css') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
115 |
self._cw.add_js(('ui.core.js', 'ui.tabs.js', |
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
510
diff
changeset
|
116 |
'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
|
117 |
# 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
|
118 |
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
|
119 |
# build the html structure |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
120 |
w = self.w |
2386
b246d5cee44e
[tabs] backport entity-less support for tabs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2383
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
w(u'<ul>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
124 |
active_tab_idx = None |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
125 |
for i, (tabid, tabkwargs) in enumerate(tabs): |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
126 |
w(u'<li>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
127 |
w(u'<a href="#%s">' % tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
128 |
w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tabid, self.cookie_name)) |
3589 | 129 |
w(tabkwargs.pop('label', self._cw._(tabid))) |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
130 |
w(u'</span>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
131 |
w(u'</a>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
132 |
w(u'</li>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
133 |
if tabid == active_tab: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
134 |
active_tab_idx = i |
235
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
135 |
w(u'</ul>') |
b43362d92a1d
rename to tabs.py
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
220
diff
changeset
|
136 |
w(u'</div>') |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
137 |
for tabid, tabkwargs in tabs: |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
138 |
w(u'<div id="%s">' % tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
139 |
tabkwargs.setdefault('tabid', tabid) |
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
140 |
tabkwargs.setdefault('vid', tabid) |
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3645
diff
changeset
|
141 |
tabkwargs.setdefault('rset', self.cw_rset) |
3569
89a60802711b
[tabs] refactor to more tab control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3209
diff
changeset
|
142 |
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
|
143 |
w(u'</div>') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
542
diff
changeset
|
144 |
# 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
|
145 |
# 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
|
146 |
# XXX make work history: true |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
147 |
self._cw.add_onload(u""" |
2674
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
""" % {'tabindex' : active_tab_idx, |
2674
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
151 |
'vid' : active_tab, |
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
152 |
'eeid' : (entity and entity.eid or uid), |
ff6114c2c416
merge (after jquery.tools backout)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
diff
changeset
|
153 |
'cookiename' : self.cookie_name}) |
489 | 154 |
|
3026
17644247f0ff
fix emacs syntaxic colorization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2675
diff
changeset
|
155 |
|
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
156 |
class EntityRelationView(EntityView): |
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
157 |
"""view displaying entity related stuff. |
489 | 158 |
Such a view _must_ provide the rtype, target and vid attributes : |
159 |
||
160 |
Example : |
|
161 |
||
162 |
class ProjectScreenshotsView(EntityRelationView): |
|
542
46d4ff5aa917
use lgc.decorators.monkeypatch in tabs.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
163 |
'''display project's screenshots''' |
3408
c92170fca813
[api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
164 |
__regid__ = title = _('projectscreenshots') |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
165 |
__select__ = EntityRelationView.__select__ & implements('Project') |
489 | 166 |
rtype = 'screenshot' |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
167 |
role = 'subject' |
489 | 168 |
vid = 'gallery' |
169 |
||
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
|
170 |
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
|
171 |
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
|
172 |
using the 'gallery' view. |
489 | 173 |
""" |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
174 |
__select__ = EntityView.__select__ & partial_has_related_entities() |
489 | 175 |
vid = 'list' |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1498
diff
changeset
|
176 |
|
489 | 177 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
178 |
rset = self.cw_rset.get_entity(row, col).related(self.rtype, role(self)) |
489 | 179 |
self.w(u'<div class="mainInfo">') |
982
ba5257deec7d
rename EntityRelatedTab into EntityRelationView, some fixes
sylvain.thenault@logilab.fr
parents:
981
diff
changeset
|
180 |
if self.title: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
181 |
self.w(tags.h1(self._cw._(self.title))) |
489 | 182 |
self.wview(self.vid, rset, 'noresult') |
183 |
self.w(u'</div>') |
|
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
184 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
185 |
|
3929
9f314411cd04
[web] rename TabedPrimary to TabbedPrimary with backward compat
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3849
diff
changeset
|
186 |
class TabbedPrimaryView(TabsMixin, primary.PrimaryView): |
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
187 |
__abstract__ = True # don't register |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
188 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
189 |
tabs = ['main_tab'] |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
190 |
default_tab = 'main_tab' |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
191 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
192 |
def cell_call(self, row, col): |
4237
87d9431243ad
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4085
diff
changeset
|
193 |
entity = self.cw_rset.complete_entity(row, col) |
4601
0f65c40b56b5
missing call to toolbox in tabbed primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
194 |
self.render_entity_toolbox(entity) |
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
195 |
self.render_entity_title(entity) |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
196 |
self.render_tabs(self.tabs, self.default_tab, entity) |
4602
fe5aad04f08b
proper deprecation of TabedPrimaryView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4601
diff
changeset
|
197 |
|
fe5aad04f08b
proper deprecation of TabedPrimaryView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4601
diff
changeset
|
198 |
TabedPrimaryView = class_renamed('TabedPrimaryView', TabbedPrimaryView) |
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
199 |
|
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
200 |
class PrimaryTab(primary.PrimaryView): |
3645
7272b793d7c9
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3589
diff
changeset
|
201 |
__regid__ = '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
|
202 |
title = None |
3570
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 is_primary(self): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
205 |
return True |
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_title(self, entity): |
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
208 |
pass |
3845
596044fb7bc5
introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3844
diff
changeset
|
209 |
def render_entity_toolbox(self, entity): |
3570
c31de6ea6984
[tabs] some convenience classes for tabbed views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3569
diff
changeset
|
210 |
pass |