126 itemvid = 'treeitemview' |
126 itemvid = 'treeitemview' |
127 subvid = 'oneline' |
127 subvid = 'oneline' |
128 cssclass = 'treeview widget' |
128 cssclass = 'treeview widget' |
129 title = _('tree view') |
129 title = _('tree view') |
130 |
130 |
131 def _init_params(self, subvid, treeid, initial_load, initial_thru_ajax, morekwargs): |
131 def _init_params(self, subvid, treeid, initial_load, morekwargs): |
132 form = self._cw.form |
132 form = self._cw.form |
133 if subvid is None: |
133 if subvid is None: |
134 subvid = form.pop('treesubvid', self.subvid) # consume it |
134 subvid = form.pop('treesubvid', self.subvid) # consume it |
135 if treeid is None: |
135 if treeid is None: |
136 treeid = form.pop('treeid', None) |
136 treeid = form.pop('treeid', None) |
137 if treeid is None: |
137 if treeid is None: |
138 treeid = 'throw_away' + make_uid('uid') |
138 treeid = 'throw_away' + make_uid('uid') |
139 if 'morekwargs' in self._cw.form: |
139 if 'morekwargs' in self._cw.form: |
140 ajaxargs = json.loads(form.pop('morekwargs')) |
140 ajaxargs = json.loads(form.pop('morekwargs')) |
141 # got unicode & python keywords must be strings |
141 # got unicode & python keywords must be strings |
142 morekwargs.update(dict((str(k), v) |
142 morekwargs.update(dict((str(k), v) |
143 for k, v in ajaxargs.items())) |
143 for k, v in ajaxargs.items())) |
144 toplevel_thru_ajax = form.pop('treeview_top', False) or initial_thru_ajax |
144 return subvid, treeid |
145 toplevel = toplevel_thru_ajax or (initial_load and not form.get('fname')) |
|
146 return subvid, treeid, toplevel_thru_ajax, toplevel |
|
147 |
145 |
148 def _init_headers(self, treeid): |
146 def _init_headers(self, treeid): |
149 self._cw.add_css(('jquery-treeview/jquery.treeview.css', 'cubicweb.treeview.css')) |
147 self._cw.add_css(('jquery-treeview/jquery.treeview.css', 'cubicweb.treeview.css')) |
150 self._cw.add_js(('cubicweb.ajax.js', 'cubicweb.widgets.js', 'jquery-treeview/jquery.treeview.js')) |
148 self._cw.add_js(('cubicweb.ajax.js', 'cubicweb.widgets.js', 'jquery-treeview/jquery.treeview.js')) |
151 self._cw.html_headers.add_onload(u""" |
149 self._cw.html_headers.add_onload(u""" |
152 jQuery("#tree-%s").treeview({toggle: toggleTree, prerendered: true});""" % treeid) |
150 jQuery("#tree-%s").treeview({toggle: toggleTree, prerendered: true});""" % treeid) |
153 |
151 |
154 def call(self, subvid=None, treeid=None, |
152 def call(self, subvid=None, treeid=None, |
155 initial_load=True, initial_thru_ajax=False, **morekwargs): |
153 initial_load=True, initial_thru_ajax=None, **morekwargs): |
156 subvid, treeid, toplevel_thru_ajax, toplevel = self._init_params( |
154 if initial_thru_ajax is not None: |
157 subvid, treeid, initial_load, initial_thru_ajax, morekwargs) |
155 msg = '[3.24] initial_thru_ajax argument is deprecated' |
|
156 warn(msg, DeprecationWarning, stacklevel=2) |
|
157 |
|
158 subvid, treeid = self._init_params(subvid, treeid, |
|
159 initial_load, morekwargs) |
158 ulid = ' ' |
160 ulid = ' ' |
159 if toplevel: |
161 self._init_headers(treeid) |
160 self._init_headers(treeid) |
162 ulid = ' id="tree-%s"' % treeid |
161 ulid = ' id="tree-%s"' % treeid |
|
162 self.w(u'<ul%s class="%s">' % (ulid, self.cssclass)) |
163 self.w(u'<ul%s class="%s">' % (ulid, self.cssclass)) |
163 # XXX force sorting on x.sortvalue() (which return dc_title by default) |
164 # XXX force sorting on x.sortvalue() (which return dc_title by default) |
164 # we need proper ITree & co specification to avoid this. |
165 # we need proper ITree & co specification to avoid this. |
165 # (pb when type ambiguity at the other side of the tree relation, |
166 # (pb when type ambiguity at the other side of the tree relation, |
166 # unability to provide generic implementation on eg Folder...) |
167 # unability to provide generic implementation on eg Folder...) |