author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 05 Feb 2010 08:11:32 +0100 | |
changeset 4460 | 5c22869079b9 |
parent 4459 | f628abfb3a6c |
child 4552 | 79f461d7ec37 |
permissions | -rw-r--r-- |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
1 |
"""Set of tree-building widgets, based on jQuery treeview plugin |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
2 |
|
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3932
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
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:
1844
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
7 |
""" |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
9 |
|
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
10 |
import simplejson as json |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
11 |
|
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
12 |
from logilab.common.decorators import monkeypatch |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2216
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
1828
e9e8beb06f01
[treeview] really fix #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1826
diff
changeset
|
14 |
from cubicweb.utils import make_uid |
0 | 15 |
from cubicweb.interfaces import ITree |
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
939
diff
changeset
|
16 |
from cubicweb.selectors import implements |
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
939
diff
changeset
|
17 |
from cubicweb.view import EntityView |
0 | 18 |
|
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
19 |
def treecookiename(treeid): |
2391
59a2def75e93
[treeview] nicer cookie name
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
20 |
return str('%s-treestate' % treeid) |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
21 |
|
0 | 22 |
class TreeView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
23 |
__regid__ = 'treeview' |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
24 |
itemvid = 'treeitemview' |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
25 |
subvid = 'oneline' |
443 | 26 |
css_classes = 'treeview widget' |
27 |
title = _('tree view') |
|
916
968f00dd9a24
[treeview] (in progress) use less magic, having something that now allows prepopulating a part of the tree
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
472
diff
changeset
|
28 |
|
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
29 |
def _init_params(self, subvid, treeid, initial_load, initial_thru_ajax, morekwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
30 |
form = self._cw.form |
0 | 31 |
if subvid is None: |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
32 |
subvid = form.pop('treesubvid', self.subvid) # consume it |
1828
e9e8beb06f01
[treeview] really fix #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1826
diff
changeset
|
33 |
if treeid is None: |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
34 |
treeid = form.pop('treeid', None) |
1828
e9e8beb06f01
[treeview] really fix #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1826
diff
changeset
|
35 |
if treeid is None: |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
36 |
treeid = 'throw_away' + make_uid('uid') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
37 |
if 'morekwargs' in self._cw.form: |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
38 |
ajaxargs = json.loads(form.pop('morekwargs')) |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
39 |
# got unicode & python keywords must be strings |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
40 |
morekwargs.update(dict((str(k), v) |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
41 |
for k, v in ajaxargs.iteritems())) |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
42 |
toplevel_thru_ajax = form.pop('treeview_top', False) or initial_thru_ajax |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
43 |
toplevel = toplevel_thru_ajax or (initial_load and not form.get('fname')) |
3299
cb543d6bd0e6
make it easier to subclass
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3222
diff
changeset
|
44 |
return subvid, treeid, toplevel_thru_ajax, toplevel |
cb543d6bd0e6
make it easier to subclass
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3222
diff
changeset
|
45 |
|
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
46 |
def _init_headers(self, treeid, toplevel_thru_ajax): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
47 |
self._cw.add_css('jquery.treeview.css') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
48 |
self._cw.add_js(('cubicweb.ajax.js', 'cubicweb.widgets.js', 'jquery.treeview.js')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
49 |
self._cw.html_headers.add_onload(u""" |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
50 |
jQuery("#tree-%s").treeview({toggle: toggleTree, prerendered: true});""" % treeid, |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
51 |
jsoncall=toplevel_thru_ajax) |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
52 |
|
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
53 |
def call(self, subvid=None, treeid=None, |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
54 |
initial_load=True, initial_thru_ajax=False, **morekwargs): |
3299
cb543d6bd0e6
make it easier to subclass
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3222
diff
changeset
|
55 |
subvid, treeid, toplevel_thru_ajax, toplevel = self._init_params( |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
56 |
subvid, treeid, initial_load, initial_thru_ajax, morekwargs) |
3298
caef98aa4a98
backport from 3.5
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2391
diff
changeset
|
57 |
ulid = ' ' |
caef98aa4a98
backport from 3.5
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2391
diff
changeset
|
58 |
if toplevel: |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
59 |
self._init_headers(treeid, toplevel_thru_ajax) |
3298
caef98aa4a98
backport from 3.5
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2391
diff
changeset
|
60 |
ulid = ' id="tree-%s"' % treeid |
caef98aa4a98
backport from 3.5
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2391
diff
changeset
|
61 |
self.w(u'<ul%s class="%s">' % (ulid, self.css_classes)) |
4436 | 62 |
for i, entity in enumerate(sorted(self.cw_rset.entities(), |
63 |
key=lambda x: x.dc_title())): |
|
64 |
if i+1 < len(self.cw_rset): |
|
4407
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
65 |
morekwargs['is_last'] = False |
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
66 |
else: |
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
67 |
morekwargs['is_last'] = True |
4436 | 68 |
entity.view(self.itemvid, vid=subvid, parentvid=self.__regid__, |
4407
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
69 |
treeid=treeid, w=self.w, **morekwargs) |
0 | 70 |
self.w(u'</ul>') |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
71 |
|
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
72 |
def cell_call(self, *args, **allargs): |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
73 |
""" does not makes much sense until you have to invoke |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
74 |
somentity.view('treeview') """ |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
75 |
allargs.pop('row') |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
76 |
allargs.pop('col') |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
77 |
self.call(*args, **allargs) |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
78 |
|
4407
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
79 |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
80 |
class FileTreeView(TreeView): |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
81 |
"""specific version of the treeview to display file trees |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
82 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
83 |
__regid__ = 'filetree' |
443 | 84 |
css_classes = 'treeview widget filetree' |
85 |
title = _('file tree view') |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
86 |
|
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
87 |
def call(self, subvid=None, treeid=None, initial_load=True, **kwargs): |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
88 |
super(FileTreeView, self).call(treeid=treeid, subvid='filetree-oneline', |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
89 |
initial_load=initial_load, **kwargs) |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
90 |
|
443 | 91 |
class FileItemInnerView(EntityView): |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
92 |
"""inner view used by the TreeItemView instead of oneline view |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
93 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
94 |
This view adds an enclosing <span> with some specific CSS classes |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
95 |
around the oneline view. This is needed by the jquery treeview plugin. |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
96 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
97 |
__regid__ = 'filetree-oneline' |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
98 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
99 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
100 |
entity = self.cw_rset.get_entity(row, col) |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
101 |
if ITree.is_implemented_by(entity.__class__) and not entity.is_leaf(): |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
102 |
self.w(u'<div class="folder">%s</div>\n' % entity.view('oneline')) |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
103 |
else: |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
104 |
# XXX define specific CSS classes according to mime types |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
105 |
self.w(u'<div class="file">%s</div>\n' % entity.view('oneline')) |
0 | 106 |
|
107 |
||
108 |
class DefaultTreeViewItemView(EntityView): |
|
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
939
diff
changeset
|
109 |
"""default treeitem view for entities which don't implement ITree""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
110 |
__regid__ = 'treeitemview' |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1133
diff
changeset
|
111 |
|
4411
d0bde029f625
should take arbitrary arguments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4407
diff
changeset
|
112 |
def cell_call(self, row, col, vid='oneline', treeid=None, **morekwargs): |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
113 |
assert treeid is not None |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
114 |
entity = self.cw_rset.get_entity(row, col) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
115 |
itemview = self._cw.view(vid, self.cw_rset, row=row, col=col) |
4455
6af31772765f
[views/treeview] fix non-ITree nodes last element computation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4411
diff
changeset
|
116 |
last_class = morekwargs['is_last'] and ' class="last"' or '' |
6af31772765f
[views/treeview] fix non-ITree nodes last element computation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4411
diff
changeset
|
117 |
self.w(u'<li%s>%s</li>' % (last_class, itemview)) |
0 | 118 |
|
119 |
||
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
120 |
class TreeViewItemView(EntityView): |
0 | 121 |
"""specific treeitem view for entities which implement ITree |
916
968f00dd9a24
[treeview] (in progress) use less magic, having something that now allows prepopulating a part of the tree
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
472
diff
changeset
|
122 |
|
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
939
diff
changeset
|
123 |
(each item should be expandable if it's not a tree leaf) |
0 | 124 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
125 |
__regid__ = 'treeitemview' |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
126 |
__select__ = implements(ITree) |
3298
caef98aa4a98
backport from 3.5
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2391
diff
changeset
|
127 |
default_branch_state_is_open = False |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1133
diff
changeset
|
128 |
|
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
129 |
def open_state(self, eeid, treeid): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
130 |
cookies = self._cw.get_cookie() |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
131 |
treestate = cookies.get(treecookiename(treeid)) |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
132 |
if treestate: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
133 |
return str(eeid) in treestate.value.split(';') |
3298
caef98aa4a98
backport from 3.5
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2391
diff
changeset
|
134 |
return self.default_branch_state_is_open |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
135 |
|
4407
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
136 |
def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview', |
e4f921a68703
[treeview] ensure items are ordered according to their dc_title, we can't rely on an ordered rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
137 |
is_last=False, **morekwargs): |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
138 |
w = self.w |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
139 |
entity = self.cw_rset.get_entity(row, col) |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
140 |
liclasses = [] |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
141 |
is_open = self.open_state(entity.eid, treeid) |
2216
b44b06520ddc
[treeview] fix condition
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1977
diff
changeset
|
142 |
is_leaf = not hasattr(entity, 'is_leaf') or entity.is_leaf() |
b44b06520ddc
[treeview] fix condition
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1977
diff
changeset
|
143 |
if is_leaf: |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
144 |
if is_last: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
145 |
liclasses.append('last') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
146 |
w(u'<li class="%s">' % u' '.join(liclasses)) |
0 | 147 |
else: |
148 |
rql = entity.children_rql() % {'x': entity.eid} |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
149 |
url = xml_escape(self._cw.build_url('json', rql=rql, vid=parentvid, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
150 |
pageid=self._cw.pageid, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
151 |
treeid=treeid, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
152 |
fname='view', |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
153 |
treesubvid=vid, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
154 |
morekwargs=json.dumps(morekwargs))) |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
155 |
divclasses = ['hitarea'] |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
156 |
if is_open: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
157 |
liclasses.append('collapsable') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
158 |
divclasses.append('collapsable-hitarea') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
159 |
else: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
160 |
liclasses.append('expandable') |
1828
e9e8beb06f01
[treeview] really fix #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1826
diff
changeset
|
161 |
divclasses.append('expandable-hitarea') |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
162 |
if is_last: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
163 |
if is_open: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
164 |
liclasses.append('lastCollapsable') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
165 |
divclasses.append('lastCollapsable-hitarea') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
166 |
else: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
167 |
liclasses.append('lastExpandable') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
168 |
divclasses.append('lastExpandable-hitarea') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
169 |
if is_open: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
170 |
w(u'<li class="%s">' % u' '.join(liclasses)) |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
171 |
else: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
172 |
w(u'<li cubicweb:loadurl="%s" class="%s">' % (url, u' '.join(liclasses))) |
3320
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
173 |
if treeid.startswith('throw_away'): |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
174 |
divtail = '' |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
175 |
else: |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
176 |
divtail = """ onclick="asyncRemoteExec('node_clicked', '%s', '%s')" """ %\ |
0dc8b2d46a53
more in the way of subclassability & args passing all the way down
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3311
diff
changeset
|
177 |
(treeid, entity.eid) |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
178 |
w(u'<div class="%s"%s></div>' % (u' '.join(divclasses), divtail)) |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
179 |
|
0 | 180 |
# add empty <ul> because jquery's treeview plugin checks for |
181 |
# sublists presence |
|
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
182 |
if not is_open: |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
183 |
w(u'<ul class="placeholder"><li>place holder</li></ul>') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
184 |
# the local node info |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
185 |
self.wview(vid, self.cw_rset, row=row, col=col, **morekwargs) |
2216
b44b06520ddc
[treeview] fix condition
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1977
diff
changeset
|
186 |
if is_open and not is_leaf: # => rql is defined |
3888
6f145783409d
use ITree api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3596
diff
changeset
|
187 |
self.wview(parentvid, entity.children(entities=False), subvid=vid, |
6f145783409d
use ITree api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3596
diff
changeset
|
188 |
treeid=treeid, initial_load=False, **morekwargs) |
1826
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
189 |
w(u'</li>') |
afc563537d8f
[treeview] restore functionnality lost in some previous merge #343232
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1802
diff
changeset
|
190 |