web/component.py
changeset 6279 42079f752a9c
parent 6151 f910c60b84ff
parent 6265 27417b8b94ed
child 6333 e3994fcc21c3
equal deleted inserted replaced
6229:c4a70a5dd144 6279:42079f752a9c
    25 from logilab.common.deprecation import class_deprecated, class_renamed
    25 from logilab.common.deprecation import class_deprecated, class_renamed
    26 from logilab.mtconverter import xml_escape
    26 from logilab.mtconverter import xml_escape
    27 
    27 
    28 from cubicweb import Unauthorized, role, tags
    28 from cubicweb import Unauthorized, role, tags
    29 from cubicweb.uilib import js, domid
    29 from cubicweb.uilib import js, domid
       
    30 from cubicweb.utils import json_dumps
    30 from cubicweb.view import ReloadableMixIn, Component
    31 from cubicweb.view import ReloadableMixIn, Component
    31 from cubicweb.selectors import (no_cnx, paginated_rset, one_line_rset,
    32 from cubicweb.selectors import (no_cnx, paginated_rset, one_line_rset,
    32                                 non_final_entity, partial_relation_possible,
    33                                 non_final_entity, partial_relation_possible,
    33                                 partial_has_related_entities)
    34                                 partial_has_related_entities)
    34 from cubicweb.appobject import AppObject
    35 from cubicweb.appobject import AppObject
   104             params[self.stop_param] = stop
   105             params[self.stop_param] = stop
   105         view = self.cw_extra_kwargs.get('view')
   106         view = self.cw_extra_kwargs.get('view')
   106         if view is not None and hasattr(view, 'page_navigation_url'):
   107         if view is not None and hasattr(view, 'page_navigation_url'):
   107             url = view.page_navigation_url(self, path, params)
   108             url = view.page_navigation_url(self, path, params)
   108         elif path == 'json':
   109         elif path == 'json':
   109             rql = params.pop('rql', self.cw_rset.printable_rql())
   110             url = self.ajax_page_url(**params)
   110             # latest 'true' used for 'swap' mode
       
   111             url = 'javascript: %s' % (js.replacePageChunk(
       
   112                 params.get('divid', 'pageContent'), rql,
       
   113                 params.pop('vid', None), params))
       
   114         else:
   111         else:
   115             url = self._cw.build_url(path, **params)
   112             url = self._cw.build_url(path, **params)
   116         return url
   113         return url
   117 
   114 
       
   115     def ajax_page_url(self, **params):
       
   116         divid = params.setdefault('divid', 'pageContent')
       
   117         params['rql'] = self.cw_rset.printable_rql()
       
   118         return "javascript: $(%s).loadxhtml('json', %s, 'get', 'swap')" % (
       
   119             json_dumps('#'+divid), js.ajaxFuncArgs('view', params))
       
   120 
   118     def page_link(self, path, params, start, stop, content):
   121     def page_link(self, path, params, start, stop, content):
   119         url = xml_escape(self.page_url(path, params, start, stop))
   122         url = xml_escape(self.page_url(path, params, start, stop))
       
   123         # XXX hack to avoid opening a new page containing the evaluation of the
       
   124         # js expression on ajax call
       
   125         if url.startswith('javascript:'):
       
   126             url += '; noop();'
   120         if start == self.starting_from:
   127         if start == self.starting_from:
   121             return self.selected_page_link_templ % (url, content, content)
   128             return self.selected_page_link_templ % (url, content, content)
   122         return self.page_link_templ % (url, content, content)
   129         return self.page_link_templ % (url, content, content)
   123 
   130 
   124     def previous_link(self, path, params, content='<<', title=_('previous_results')):
   131     def previous_link(self, path, params, content='<<', title=_('previous_results')):