[page nav] json navigation (when coming from a facets restriction for instance) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 26 Aug 2009 11:14:47 +0200
branchstable
changeset 3013 6a40a9a72957
parent 3012 97696093ba54
child 3014 62ce5a139b52
[page nav] json navigation (when coming from a facets restriction for instance)
web/component.py
--- a/web/component.py	Wed Aug 26 11:13:42 2009 +0200
+++ b/web/component.py	Wed Aug 26 11:14:47 2009 +0200
@@ -8,6 +8,8 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
+from simplejson import dumps
+
 from logilab.common.deprecation import class_renamed
 from logilab.mtconverter import xml_escape
 
@@ -113,10 +115,21 @@
         if self.stop_param in params:
             del params[self.stop_param]
 
+    def page_url(self, path, params, start, stop):
+        params = merge_dicts(params, {self.start_param : start,
+                                      self.stop_param : stop,})
+        if path == 'json':
+            rql = params.pop('rql', self.rset.printable_rql())
+            # latest 'true' used for 'swap' mode
+            url = 'javascript: replacePageChunk(%s, %s, %s, %s, true)' % (
+                dumps(params.get('divid', 'paginated-content')),
+                dumps(rql), dumps(params.pop('vid', None)), dumps(params))
+        else:
+            url = self.build_url(path, **params)
+        return url
+
     def page_link(self, path, params, start, stop, content):
-        url = self.build_url(path, **merge_dicts(params, {self.start_param : start,
-                                                          self.stop_param : stop,}))
-        url = xml_escape(url)
+        url = xml_escape(self.page_url(path, params, start, stop))
         if start == self.starting_from:
             return self.selected_page_link_templ % (url, content, content)
         return self.page_link_templ % (url, content, content)