Backout "[web/navigation] use add_onload instead of inline javascript href"

This reverts changeset 170e1437948d, for at least two reasons: the PageNavigationSelect component was not updated for the new type of navigation links, and external cubes defining View.page_navigation_url exist in the wild and also got broken navigation links. This reopens #3501626 and closes #3677945.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset0f0199948f93
branchstable
phasepublic
hiddenno
parent revision#121c88b360d0 [test] those are rql tests, not cubicweb (and they break with rql 0.31.5). Remove them.
child revision#fe267b7336f3 [migration] always rebuild infered relation
files modified by this revision
web/component.py
web/views/navigation.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1395674958 -3600
# Mon Mar 24 16:29:18 2014 +0100
# Branch stable
# Node ID 0f0199948f938663c6a0132f116e49cff6a9e22a
# Parent 121c88b360d0d9bb3e764292506c9605c2dd7f47
Backout "[web/navigation] use add_onload instead of inline javascript href"

This reverts changeset 170e1437948d, for at least two reasons: the
PageNavigationSelect component was not updated for the new type of
navigation links, and external cubes defining View.page_navigation_url
exist in the wild and also got broken navigation links. This reopens
#3501626 and closes #3677945.

diff --git a/web/component.py b/web/component.py
@@ -106,23 +106,27 @@
1          if stop is not None:
2              params[self.stop_param] = stop
3          view = self.cw_extra_kwargs.get('view')
4          if view is not None and hasattr(view, 'page_navigation_url'):
5              url = view.page_navigation_url(self, path, params)
6 +        elif path in ('json', 'ajax'):
7 +            # 'ajax' is the new correct controller, but the old 'json'
8 +            # controller should still be supported
9 +            url = self.ajax_page_url(**params)
10          else:
11 -            url = self.ajax_page_url(**params)
12 +            url = self._cw.build_url(path, **params)
13          # XXX hack to avoid opening a new page containing the evaluation of the
14          # js expression on ajax call
15          if url.startswith('javascript:'):
16              url += '; $.noop();'
17          return url
18 
19      def ajax_page_url(self, **params):
20          divid = params.setdefault('divid', 'pageContent')
21 -        params['fname'] = 'view'
22          params['rql'] = self.cw_rset.printable_rql()
23 -        return self._cw.build_url('ajax', **params)
24 +        return js_href("$(%s).loadxhtml(AJAX_PREFIX_URL, %s, 'get', 'swap')" % (
25 +            json_dumps('#'+divid), js.ajaxFuncArgs('view', params)))
26 
27      def page_link(self, path, params, start, stop, content):
28          url = xml_escape(self.page_url(path, params, start, stop))
29          if start == self.starting_from:
30              return self.selected_page_link_templ % (url, content, content)
diff --git a/web/views/navigation.py b/web/views/navigation.py
@@ -53,11 +53,10 @@
31  from rql.nodes import VariableRef, Constant
32 
33  from logilab.mtconverter import xml_escape
34  from logilab.common.deprecation import deprecated
35 
36 -from cubicweb.utils import json_dumps
37  from cubicweb.predicates import paginated_rset, sorted_rset, adaptable
38  from cubicweb.uilib import cut
39  from cubicweb.view import EntityAdapter
40  from cubicweb.web.component import EmptyComponent, EntityCtxComponent, NavigationComponent
41 
@@ -279,17 +278,10 @@
42      if w is None:
43          w = view.w
44      nav = req.vreg['components'].select_or_none(
45          'navigation', req, rset=rset, page_size=page_size, view=view)
46      if nav:
47 -        domid = getattr(view, 'domid', 'pageContent')
48 -        view._cw.add_onload('''
49 -        jQuery('div.displayAllLink a, div.pagination a').click(function() {
50 -            cw.jqNode(%s).loadxhtml(this.href, null, 'get', 'swap');
51 -            return false;
52 -        });
53 -            ''' % json_dumps(domid))
54          if w is None:
55              w = view.w
56          if req.form.get('__force_display'):
57              # allow to come back to the paginated view
58              params = dict(req.form)