author | Laure Bourgois <Laure.Bourgois@logilab.fr> |
Mon, 23 Feb 2009 16:25:59 +0100 | |
changeset 926 | 6d3d693c0ad5 |
parent 923 | 7c184924d492 |
child 985 | 6a25c58a1c23 |
child 999 | 999198995a53 |
permissions | -rw-r--r-- |
0 | 1 |
from logilab.mtconverter import html_escape |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
2 |
|
0 | 3 |
from cubicweb.interfaces import ITree |
431 | 4 |
from cubicweb.common.selectors import implement_interface, yes |
0 | 5 |
from cubicweb.common.view import EntityView |
6 |
||
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
7 |
from cubicweb.web.views.baseviews import OneLineView |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
8 |
|
0 | 9 |
class TreeView(EntityView): |
10 |
id = 'treeview' |
|
11 |
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
|
12 |
itemvid = 'treeitemview' |
443 | 13 |
css_classes = 'treeview widget' |
14 |
title = _('tree view') |
|
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
15 |
|
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
16 |
def call(self, subvid=None): |
0 | 17 |
if subvid is None and 'subvid' in self.req.form: |
18 |
subvid = self.req.form.pop('subvid') # consume it |
|
19 |
if subvid is None: |
|
20 |
subvid = 'oneline' |
|
21 |
self.req.add_css('jquery.treeview.css') |
|
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
22 |
self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js', 'cubicweb.widgets.js')) |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
23 |
# XXX noautoload is a quick hack to avoid treeview to be rebuilt |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
24 |
# after a json query and avoid double toggling bugs. |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
25 |
# Need to find a way to do that cleanly. |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
26 |
if 'noautoload' in self.req.form: |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
27 |
self.w(u'<ul class="%s" cubicweb:wdgtype="TreeView">' % self.css_classes) |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
28 |
else: |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
29 |
self.w(u'<ul class="%s" cubicweb:loadtype="auto" cubicweb:wdgtype="TreeView">' |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
30 |
% self.css_classes) |
0 | 31 |
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
|
32 |
self.wview(self.itemvid, self.rset, row=rowidx, col=0, |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
33 |
vid=subvid, parentvid=self.id) |
0 | 34 |
self.w(u'</ul>') |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
35 |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
36 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
37 |
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
|
38 |
"""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
|
39 |
""" |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
40 |
id = 'filetree' |
443 | 41 |
css_classes = 'treeview widget filetree' |
42 |
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
|
43 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
44 |
def call(self, subvid=None): |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
45 |
super(FileTreeView, self).call(subvid='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
|
46 |
|
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
47 |
|
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
48 |
|
443 | 49 |
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
|
50 |
"""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
|
51 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
""" |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
55 |
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
|
56 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
if ITree.is_implemented_by(entity.__class__) and not entity.is_leaf(): |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
60 |
self.w(u'<div class="folder">%s</div>' % 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
|
61 |
else: |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
62 |
# XXX define specific CSS classes according to mime types |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
63 |
self.w(u'<div class="file">%s</div>' % entity.view('oneline')) |
0 | 64 |
|
65 |
||
66 |
class DefaultTreeViewItemView(EntityView): |
|
67 |
"""default treeitem view for entities which don't implement ITree |
|
68 |
""" |
|
69 |
id = 'treeitemview' |
|
70 |
accepts = ('Any',) |
|
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
71 |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
72 |
def cell_call(self, row, col, vid='oneline', parentvid='treeview'): |
0 | 73 |
entity = self.entity(row, col) |
74 |
itemview = self.view(vid, self.rset, row=row, col=col) |
|
75 |
if row == len(self.rset) - 1: |
|
76 |
self.w(u'<li class="last">%s</li>' % itemview) |
|
77 |
else: |
|
472 | 78 |
self.w(u'<li>%s</li>' % itemview) |
0 | 79 |
|
80 |
||
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
81 |
class TreeViewItemView(EntityView): |
0 | 82 |
"""specific treeitem view for entities which implement ITree |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
83 |
|
0 | 84 |
(each item should be exandable if it's not a tree leaf) |
85 |
""" |
|
86 |
id = 'treeitemview' |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
187
diff
changeset
|
87 |
# XXX append yes to make sure we get an higher score than |
0 | 88 |
# the default treeitem view |
431 | 89 |
__selectors__ = (implement_interface, yes) |
0 | 90 |
accepts_interfaces = (ITree,) |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
91 |
|
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 |
def cell_call(self, row, col, vid='oneline', parentvid='treeview'): |
0 | 93 |
entity = self.entity(row, col) |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
94 |
cssclasses = [] |
0 | 95 |
is_leaf = False |
96 |
if row == len(self.rset) - 1: |
|
97 |
is_leaf = True |
|
98 |
if not hasattr(entity, 'is_leaf') or entity.is_leaf(): |
|
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
99 |
if is_leaf : cssclasses.append('last') |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
100 |
self.w(u'<li class="%s">' % u' '.join(cssclasses)) |
0 | 101 |
else: |
102 |
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
|
103 |
url = html_escape(self.build_url('json', rql=rql, vid=parentvid, |
0 | 104 |
pageid=self.req.pageid, |
187
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
105 |
subvid=vid, |
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
106 |
noautoload=True)) |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
107 |
cssclasses.append('expandable') |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
108 |
divclasses = ['hitarea expandable-hitarea'] |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
109 |
if is_leaf : |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
110 |
cssclasses.append('lastExpandable') |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
111 |
divclasses.append('lastExpandable-hitarea') |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
112 |
self.w(u'<li cubicweb:loadurl="%s" class="%s">' % (url, u' '.join(cssclasses))) |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
113 |
self.w(u'<div class="%s"> </div>' % u' '.join(divclasses)) |
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
114 |
|
0 | 115 |
# add empty <ul> because jquery's treeview plugin checks for |
116 |
# sublists presence |
|
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
117 |
self.w(u'<ul class="placeholder"><li>place holder</li></ul>') |
0 | 118 |
self.wview(vid, self.rset, row=row, col=col) |
923
7c184924d492
unwanted merge : Backed out changeset 4328bcbd748e
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
918
diff
changeset
|
119 |
self.w(u'</li>') |
918
19862a0e55a5
[treeview] (inprogress) minimally working state-remembering treeview
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
916
diff
changeset
|
120 |