author | sylvain.thenault@logilab.fr |
Thu, 14 May 2009 12:49:44 +0200 | |
branch | 1fbeb11a27a3 |
changeset 1811 | 2ef282c7f2a8 |
parent 1001 | 7d0fccdb8125 |
child 1006 | 92a0601b2523 |
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 |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
6 |
""" |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
7 |
__docformat__ = "restructuredtext en" |
0 | 8 |
from logilab.mtconverter import html_escape |
9 |
from cubicweb.interfaces import ITree |
|
431 | 10 |
from cubicweb.common.selectors import implement_interface, yes |
1001
7d0fccdb8125
[treeview] uuid is not available in the stdlib before python 2.5
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
11 |
from cubicweb.common.utils import make_uid |
0 | 12 |
from cubicweb.common.view import EntityView |
13 |
||
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
14 |
def treecookiename(treeid): |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
15 |
return str('treestate-%s' % treeid) |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
16 |
|
0 | 17 |
class TreeView(EntityView): |
18 |
id = 'treeview' |
|
19 |
accepts = ('Any',) |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
20 |
itemvid = 'treeitemview' |
443 | 21 |
css_classes = 'treeview widget' |
22 |
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
|
23 |
|
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
24 |
def call(self, subvid=None, treeid=None, initial_load=True): |
0 | 25 |
if subvid is None: |
998
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
26 |
if 'subvid' in self.req.form: |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
27 |
subvid = self.req.form.pop('subvid') # consume it |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
28 |
else: |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
29 |
subvid = 'oneline' |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
30 |
if treeid is None: |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
31 |
if 'treeid' in self.req.form: |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
32 |
treeid = self.req.form.pop('treeid') |
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
33 |
else: |
1001
7d0fccdb8125
[treeview] uuid is not available in the stdlib before python 2.5
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
999
diff
changeset
|
34 |
treeid = make_uid('throw away uid') |
998
9c6ce9d6384f
[treeview] if the client is not interested in maintaining the tree state across page reloads, we must provide a treeid
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
931
diff
changeset
|
35 |
self.warning('Tree state won\'t be properly restored after next reload') |
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
36 |
if initial_load: |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
37 |
self.req.add_css('jquery.treeview.css') |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
38 |
self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js')) |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
39 |
self.req.html_headers.add_onload(u""" |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
40 |
jQuery("#tree-%s").treeview({toggle: toggleTree, |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
41 |
prerendered: true});""" % treeid) |
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
|
42 |
self.w(u'<ul id="tree-%s" class="%s">' % (treeid, self.css_classes)) |
0 | 43 |
for rowidx in xrange(len(self.rset)): |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
44 |
self.wview(self.itemvid, self.rset, row=rowidx, col=0, |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
45 |
vid=subvid, parentvid=self.id, treeid=treeid) |
0 | 46 |
self.w(u'</ul>') |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
47 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
48 |
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
|
49 |
"""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
|
50 |
""" |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
51 |
id = 'filetree' |
443 | 52 |
css_classes = 'treeview widget filetree' |
53 |
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
|
54 |
|
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
55 |
def call(self, subvid=None, treeid=None, initial_load=True): |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
56 |
super(FileTreeView, self).call(treeid=treeid, subvid='filetree-oneline', initial_load=initial_load) |
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
57 |
|
443 | 58 |
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
|
59 |
"""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
|
60 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
""" |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
64 |
id = 'filetree-oneline' |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
65 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
66 |
def cell_call(self, row, col): |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
67 |
entity = self.entity(row, col) |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
68 |
if ITree.is_implemented_by(entity.__class__) and not entity.is_leaf(): |
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
|
69 |
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
|
70 |
else: |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
71 |
# XXX define specific CSS classes according to mime types |
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
|
72 |
self.w(u'<div class="file">%s</div>\n' % entity.view('oneline')) |
0 | 73 |
|
74 |
||
75 |
class DefaultTreeViewItemView(EntityView): |
|
76 |
"""default treeitem view for entities which don't implement ITree |
|
77 |
""" |
|
78 |
id = 'treeitemview' |
|
79 |
accepts = ('Any',) |
|
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
|
80 |
|
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
81 |
def cell_call(self, row, col, vid='oneline', parentvid='treeview', treeid=None): |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
82 |
assert treeid is not None |
0 | 83 |
entity = self.entity(row, col) |
84 |
itemview = self.view(vid, self.rset, row=row, col=col) |
|
85 |
if row == len(self.rset) - 1: |
|
86 |
self.w(u'<li class="last">%s</li>' % itemview) |
|
87 |
else: |
|
472 | 88 |
self.w(u'<li>%s</li>' % itemview) |
0 | 89 |
|
90 |
||
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
91 |
class TreeViewItemView(EntityView): |
0 | 92 |
"""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
|
93 |
|
0 | 94 |
(each item should be exandable if it's not a tree leaf) |
95 |
""" |
|
96 |
id = 'treeitemview' |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
187
diff
changeset
|
97 |
# XXX append yes to make sure we get an higher score than |
0 | 98 |
# the default treeitem view |
431 | 99 |
__selectors__ = (implement_interface, yes) |
0 | 100 |
accepts_interfaces = (ITree,) |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
101 |
|
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
102 |
def open_state(self, eeid, treeid): |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
103 |
cookies = self.req.get_cookie() |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
104 |
treestate = cookies.get(treecookiename(treeid)) |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
105 |
if treestate: |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
106 |
return str(eeid) in treestate.value.split(';') |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
107 |
return False |
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
|
108 |
|
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
109 |
def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview'): |
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
|
110 |
w = self.w |
0 | 111 |
entity = self.entity(row, col) |
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
|
112 |
liclasses = [] |
0 | 113 |
is_leaf = False |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
114 |
is_last = row == len(self.rset) - 1 |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
115 |
is_open = self.open_state(entity.eid, treeid) |
0 | 116 |
if not hasattr(entity, 'is_leaf') or entity.is_leaf(): |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
117 |
if is_last: |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
118 |
liclasses.append('last') |
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
|
119 |
w(u'<li class="%s">' % u' '.join(liclasses)) |
0 | 120 |
else: |
121 |
rql = entity.children_rql() % {'x': entity.eid} |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
122 |
url = html_escape(self.build_url('json', rql=rql, vid=parentvid, |
0 | 123 |
pageid=self.req.pageid, |
929
80de412e6ed7
[treeview] treeid is passed along: we can manage as many trees as we want
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
928
diff
changeset
|
124 |
treeid=treeid, |
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
125 |
subvid=vid)) |
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
126 |
divclasses = ['hitarea'] |
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
|
127 |
if is_open: |
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
|
128 |
liclasses.append('collapsable') |
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
129 |
divclasses.append('collapsable-hitarea') |
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
|
130 |
else: |
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
|
131 |
liclasses.append('expandable') |
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
132 |
divclasses.append('closed-hitarea expandable-hitarea') |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
133 |
if is_last: |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
134 |
if is_open: |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
135 |
liclasses.append('lastCollapsable') |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
136 |
divclasses.append('lastCollapsable-hitarea') |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
137 |
else: |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
138 |
liclasses.append('lastExpandable') |
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
|
139 |
divclasses.append('lastExpandable-hitarea') |
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
|
140 |
if is_open: |
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
|
141 |
w(u'<li class="%s">' % u' '.join(liclasses)) |
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
|
142 |
else: |
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
|
143 |
w(u'<li cubicweb:loadurl="%s" class="%s">' % (url, u' '.join(liclasses))) |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
144 |
if is_leaf: |
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
145 |
divtail = '' |
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
146 |
else: |
929
80de412e6ed7
[treeview] treeid is passed along: we can manage as many trees as we want
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
928
diff
changeset
|
147 |
divtail = ''' onclick="async_remote_exec('node_clicked', '%s', '%s')"''' % \ |
80de412e6ed7
[treeview] treeid is passed along: we can manage as many trees as we want
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
928
diff
changeset
|
148 |
(treeid, entity.eid) |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
149 |
w(u'<div class="%s"%s></div>' % (u' '.join(divclasses), divtail)) |
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
|
150 |
|
0 | 151 |
# add empty <ul> because jquery's treeview plugin checks for |
152 |
# sublists presence |
|
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
|
153 |
if not is_open: |
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
|
154 |
w(u'<ul class="placeholder"><li>place holder</li></ul>') |
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
|
155 |
# the local node info |
0 | 156 |
self.wview(vid, self.rset, row=row, col=col) |
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
|
157 |
if is_open: # recurse if needed |
931
7b701df4dbef
[treeview] don't readd stuff to the header, poslish css classes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
930
diff
changeset
|
158 |
self.wview(parentvid, self.req.execute(rql), treeid=treeid, initial_load=False) |
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
|
159 |
w(u'</li>') |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
160 |
|
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
161 |
from logilab.common.decorators import monkeypatch |
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
162 |
from cubicweb.web.views.basecontrollers import JSonController |
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
163 |
|
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
164 |
@monkeypatch(JSonController) |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
165 |
def js_node_clicked(self, treeid, nodeeid): |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
166 |
"""add/remove eid in treestate cookie""" |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
167 |
cookies = self.req.get_cookie() |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
168 |
statename = treecookiename(treeid) |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
169 |
treestate = cookies.get(statename) |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
170 |
if treestate is None: |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
171 |
cookies[statename] = nodeeid |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
172 |
self.req.set_cookie(cookies, statename) |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
173 |
else: |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
174 |
marked = set(filter(None, treestate.value.split(';'))) |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
175 |
if nodeeid in marked: |
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
176 |
marked.remove(nodeeid) |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
177 |
else: |
930
bab7f79fa26b
[treeview] rename, manage lastCollapsable
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
929
diff
changeset
|
178 |
marked.add(nodeeid) |
928
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
179 |
cookies[statename] = ';'.join(marked) |
57614f333dc6
[treeview] (in progress) treeid has to be produced from outside
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
180 |
self.req.set_cookie(cookies, statename) |