30 if treeid is None: |
30 if treeid is None: |
31 treeid = self.req.form.pop('treeid', None) |
31 treeid = self.req.form.pop('treeid', None) |
32 if treeid is None: |
32 if treeid is None: |
33 self.warning('Tree state won\'t be properly restored after next reload') |
33 self.warning('Tree state won\'t be properly restored after next reload') |
34 treeid = make_uid('throw away uid') |
34 treeid = make_uid('throw away uid') |
35 self.w(u'<ul id="tree-%s" class="%s">' % (treeid, self.css_classes)) |
35 toplevel_thru_ajax = self.req.form.pop('treeview_top', False) |
|
36 toplevel = toplevel_thru_ajax or (initial_load and not self.req.form.get('fname')) |
|
37 ulid = ' ' |
|
38 if toplevel: |
|
39 ulid = ' id="tree-%s"' % treeid |
|
40 self.w(u'<ul%s class="%s">' % (ulid, self.css_classes)) |
36 for rowidx in xrange(len(self.rset)): |
41 for rowidx in xrange(len(self.rset)): |
37 self.wview(self.itemvid, self.rset, row=rowidx, col=0, |
42 self.wview(self.itemvid, self.rset, row=rowidx, col=0, |
38 vid=subvid, parentvid=self.id, treeid=treeid) |
43 vid=subvid, parentvid=self.id, treeid=treeid) |
39 self.w(u'</ul>') |
44 self.w(u'</ul>') |
40 if initial_load and not self.req.form.get('fname'): |
45 if toplevel: |
41 self.req.add_css('jquery.treeview.css') |
46 self.req.add_css('jquery.treeview.css') |
42 self.req.add_js(('cubicweb.ajax.js', 'cubicweb.widgets.js', 'jquery.treeview.js')) |
47 self.req.add_js(('cubicweb.ajax.js', 'cubicweb.widgets.js', 'jquery.treeview.js')) |
43 self.req.html_headers.add_onload(u""" |
48 self.req.html_headers.add_onload(u""" |
44 jQuery("#tree-%s").treeview({toggle: toggleTree, prerendered: true});""" % treeid) |
49 jQuery("#tree-%s").treeview({toggle: toggleTree, prerendered: true});""" % treeid, |
45 |
50 jsoncall=toplevel_thru_ajax) |
46 |
51 |
47 class FileTreeView(TreeView): |
52 class FileTreeView(TreeView): |
48 """specific version of the treeview to display file trees |
53 """specific version of the treeview to display file trees |
49 """ |
54 """ |
50 id = 'filetree' |
55 id = 'filetree' |
89 """specific treeitem view for entities which implement ITree |
94 """specific treeitem view for entities which implement ITree |
90 |
95 |
91 (each item should be expandable if it's not a tree leaf) |
96 (each item should be expandable if it's not a tree leaf) |
92 """ |
97 """ |
93 id = 'treeitemview' |
98 id = 'treeitemview' |
94 __select__ = EntityView.__select__ & implements(ITree) # XXX |
99 default_branch_state_is_open = False |
|
100 __select__ = EntityView.__select__ & implements(ITree) |
95 |
101 |
96 def open_state(self, eeid, treeid): |
102 def open_state(self, eeid, treeid): |
97 cookies = self.req.get_cookie() |
103 cookies = self.req.get_cookie() |
98 treestate = cookies.get(treecookiename(treeid)) |
104 treestate = cookies.get(treecookiename(treeid)) |
99 if treestate: |
105 if treestate: |
100 return str(eeid) in treestate.value.split(';') |
106 return str(eeid) in treestate.value.split(';') |
101 return False |
107 return self.default_branch_state_is_open |
102 |
108 |
103 def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview'): |
109 def cell_call(self, row, col, treeid, vid='oneline', parentvid='treeview'): |
104 w = self.w |
110 w = self.w |
105 entity = self.rset.get_entity(row, col) |
111 entity = self.rset.get_entity(row, col) |
106 liclasses = [] |
112 liclasses = [] |