author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 19 Feb 2009 21:31:18 +0100 | |
branch | tls-sprint |
changeset 861 | 7985b5db2284 |
parent 836 | 2ca048a43240 |
child 939 | ad72e06320e2 |
permissions | -rw-r--r-- |
0 | 1 |
from logilab.mtconverter import html_escape |
2 |
||
3 |
from cubicweb.interfaces import ITree |
|
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
4 |
from cubicweb.selectors import implements |
836 | 5 |
from cubicweb.view import EntityView |
0 | 6 |
|
7 |
class TreeView(EntityView): |
|
8 |
id = '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
|
9 |
itemvid = 'treeitemview' |
443 | 10 |
css_classes = 'treeview widget' |
11 |
title = _('tree view') |
|
0 | 12 |
|
13 |
def call(self, subvid=None): |
|
14 |
if subvid is None and 'subvid' in self.req.form: |
|
15 |
subvid = self.req.form.pop('subvid') # consume it |
|
16 |
if subvid is None: |
|
17 |
subvid = 'oneline' |
|
18 |
self.req.add_css('jquery.treeview.css') |
|
19 |
self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js', 'cubicweb.widgets.js')) |
|
187
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
20 |
# XXX noautoload is a quick hack to avoid treeview to be rebuilt |
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
21 |
# after a json query and avoid double toggling bugs. |
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
22 |
# Need to find a way to do that cleanly. |
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
23 |
if 'noautoload' in self.req.form: |
443 | 24 |
self.w(u'<ul class="%s" cubicweb:wdgtype="TreeView">' % self.css_classes) |
187
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
25 |
else: |
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
26 |
self.w(u'<ul class="%s" cubicweb:loadtype="auto" cubicweb:wdgtype="TreeView">' |
443 | 27 |
% self.css_classes) |
0 | 28 |
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
|
29 |
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
|
30 |
vid=subvid, parentvid=self.id) |
0 | 31 |
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
|
32 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
33 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
34 |
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
|
35 |
"""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
|
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 |
id = 'filetree' |
443 | 38 |
css_classes = 'treeview widget filetree' |
39 |
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
|
40 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
41 |
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
|
42 |
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
|
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 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
45 |
|
443 | 46 |
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
|
47 |
"""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
|
48 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
49 |
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
|
50 |
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
|
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 |
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
|
53 |
|
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
if ITree.is_implemented_by(entity.__class__) and not entity.is_leaf(): |
464
75d242975792
[treeview] replace span elements by div for xhtml conformance
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
431
diff
changeset
|
57 |
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
|
58 |
else: |
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
59 |
# XXX define specific CSS classes according to mime types |
464
75d242975792
[treeview] replace span elements by div for xhtml conformance
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
431
diff
changeset
|
60 |
self.w(u'<div class="file">%s</div>' % entity.view('oneline')) |
0 | 61 |
|
62 |
||
63 |
class DefaultTreeViewItemView(EntityView): |
|
64 |
"""default treeitem view for entities which don't implement ITree |
|
65 |
""" |
|
66 |
id = 'treeitemview' |
|
67 |
||
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
68 |
def cell_call(self, row, col, vid='oneline', parentvid='treeview'): |
0 | 69 |
entity = self.entity(row, col) |
70 |
itemview = self.view(vid, self.rset, row=row, col=col) |
|
71 |
if row == len(self.rset) - 1: |
|
72 |
self.w(u'<li class="last">%s</li>' % itemview) |
|
73 |
else: |
|
472 | 74 |
self.w(u'<li>%s</li>' % itemview) |
0 | 75 |
|
76 |
||
77 |
class TreeViewItemView(EntityView): |
|
78 |
"""specific treeitem view for entities which implement ITree |
|
79 |
|
|
80 |
(each item should be exandable if it's not a tree leaf) |
|
81 |
""" |
|
82 |
id = 'treeitemview' |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
83 |
__select__ = implements(ITree) |
0 | 84 |
|
150
1190261a1f13
provide a specific version of treeview to display files and directories
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
85 |
def cell_call(self, row, col, vid='oneline', parentvid='treeview'): |
0 | 86 |
entity = self.entity(row, col) |
87 |
cssclasses = [] |
|
88 |
is_leaf = False |
|
89 |
if row == len(self.rset) - 1: |
|
90 |
is_leaf = True |
|
91 |
if not hasattr(entity, 'is_leaf') or entity.is_leaf(): |
|
92 |
if is_leaf : cssclasses.append('last') |
|
93 |
self.w(u'<li class="%s">' % u' '.join(cssclasses)) |
|
94 |
else: |
|
95 |
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
|
96 |
url = html_escape(self.build_url('json', rql=rql, vid=parentvid, |
0 | 97 |
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
|
98 |
subvid=vid, |
cae87ca76f02
quick hack to fix treeview double toggling bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
150
diff
changeset
|
99 |
noautoload=True)) |
0 | 100 |
cssclasses.append('expandable') |
101 |
divclasses = ['hitarea expandable-hitarea'] |
|
102 |
if is_leaf : |
|
103 |
cssclasses.append('lastExpandable') |
|
104 |
divclasses.append('lastExpandable-hitarea') |
|
105 |
self.w(u'<li cubicweb:loadurl="%s" class="%s">' % (url, u' '.join(cssclasses))) |
|
106 |
self.w(u'<div class="%s"> </div>' % u' '.join(divclasses)) |
|
107 |
||
108 |
# add empty <ul> because jquery's treeview plugin checks for |
|
109 |
# sublists presence |
|
110 |
self.w(u'<ul class="placeholder"><li>place holder</li></ul>') |
|
111 |
self.wview(vid, self.rset, row=row, col=col) |
|
112 |
self.w(u'</li>') |
|
113 |