# HG changeset patch # User Adrien Di Mascio # Date 1225972902 -3600 # Node ID 64072193bd484ff4957dc789497d1b4e28b8a610 # Parent 8a607bdc11dc600f12abd55a3d0930eba0887d47 simple and naive implementation of 'bookmark this search' while using facets diff -r 8a607bdc11dc -r 64072193bd48 web/data/cubicweb.formfilter.js --- a/web/data/cubicweb.formfilter.js Thu Nov 06 13:01:08 2008 +0100 +++ b/web/data/cubicweb.formfilter.js Thu Nov 06 13:01:42 2008 +0100 @@ -46,6 +46,14 @@ var d = async_remote_exec('filter_build_rql', zipped[0], zipped[1]); d.addCallback(function(result) { var rql = result[0]; + var $bkLink = jQuery('#facetBkLink'); + if ($bkLink.length) { + var bkUrl = $bkLink.attr('cubicweb:target') + '&path=view?rql=' + rql; + if (vid) { + bkUrl += '&vid=' + vid; + } + $bkLink.attr('href', bkUrl); + } var toupdate = result[1]; var extraparams = vidargs; var displayactions = jQuery('#' + divid).attr('cubicweb:displayactions'); diff -r 8a607bdc11dc -r 64072193bd48 web/views/facets.py --- a/web/views/facets.py Thu Nov 06 13:01:08 2008 +0100 +++ b/web/views/facets.py Thu Nov 06 13:01:42 2008 +0100 @@ -52,12 +52,13 @@ return rset, vid, divid, paginate def call(self, view=None): - self.req.add_js( ('cubicweb.ajax.js', 'cubicweb.formfilter.js') ) + req = self.req + req.add_js( ('cubicweb.ajax.js', 'cubicweb.formfilter.js') ) rset, vid, divid, paginate = self._get_context(view) if rset.rowcount < 2: # XXX done by selectors, though maybe necessary when rset has been hijacked return if vid is None: - vid = self.req.form.get('vid') + vid = req.form.get('vid') rqlst = rset.syntax_tree() rqlst.save_state() try: @@ -71,14 +72,24 @@ if not widgets: return w = self.w + eschema = self.schema.eschema('Bookmark') + if eschema.has_perm(req, 'add'): + bk_path = 'view?rql=%s' % rset.printable_rql() + bk_title = req._('my custom search') + bk_add_url = self.build_url('add/Bookmark', path=bk_path, title=bk_title) + bk_base_url = self.build_url('add/Bookmark', title=bk_title) + w(u'
%s
' % ( + html_escape(bk_base_url), + html_escape(bk_add_url), + req._('bookmark this search'))) w(u'
' % ( divid, html_escape(dumps([divid, vid, paginate, self.facetargs()])))) w(u'
') hiddens = {'facets': ','.join(wdg.facet.id for wdg in widgets), 'baserql': baserql} for param in ('subvid', 'vtitle'): - if param in self.req.form: - hiddens[param] = self.req.form[param] + if param in req.form: + hiddens[param] = req.form[param] filter_hiddens(w, **hiddens) for wdg in widgets: wdg.render(w=self.w)