34 |
34 |
35 class PageNavigation(NavigationComponent): |
35 class PageNavigation(NavigationComponent): |
36 |
36 |
37 def call(self): |
37 def call(self): |
38 """displays a resultset by page""" |
38 """displays a resultset by page""" |
39 w = self.w |
39 params = dict(self._cw.form) |
40 req = self._cw |
40 self.clean_params(params) |
|
41 basepath = self._cw.relative_path(includeparams=False) |
|
42 self.w(u'<div class="pagination">') |
|
43 self.w(u'%s ' % self.previous_link(basepath, params)) |
|
44 self.w(u'[ %s ]' % |
|
45 u' | '.join(self.iter_page_links(basepath, params))) |
|
46 self.w(u' %s' % self.next_link(basepath, params)) |
|
47 self.w(u'</div>') |
|
48 |
|
49 def index_display(self, start, stop): |
|
50 return u'%s - %s' % (start+1, stop+1) |
|
51 |
|
52 def iter_page_links(self, basepath, params): |
41 rset = self.cw_rset |
53 rset = self.cw_rset |
42 page_size = self.page_size |
54 page_size = self.page_size |
43 start = 0 |
55 start = 0 |
44 blocklist = [] |
|
45 params = dict(req.form) |
|
46 self.clean_params(params) |
|
47 basepath = req.relative_path(includeparams=False) |
|
48 while start < rset.rowcount: |
56 while start < rset.rowcount: |
49 stop = min(start + page_size - 1, rset.rowcount - 1) |
57 stop = min(start + page_size - 1, rset.rowcount - 1) |
50 blocklist.append(self.page_link(basepath, params, start, stop, |
58 yield self.page_link(basepath, params, start, stop, |
51 self.index_display(start, stop))) |
59 self.index_display(start, stop)) |
52 start = stop + 1 |
60 start = stop + 1 |
|
61 |
|
62 |
|
63 class PageNavigationSelect(PageNavigation): |
|
64 """displays a resultset by page as PageNavigationSelect but in a <select>, |
|
65 better when there are a lot of results. |
|
66 """ |
|
67 __select__ = paginated_rset(4) |
|
68 |
|
69 page_link_templ = u'<option value="%s" title="%s">%s</option>' |
|
70 selected_page_link_templ = u'<option value="%s" selected="selected" title="%s">%s</option>' |
|
71 def call(self): |
|
72 params = dict(self._cw.form) |
|
73 self.clean_params(params) |
|
74 basepath = self._cw.relative_path(includeparams=False) |
|
75 w = self.w |
53 w(u'<div class="pagination">') |
76 w(u'<div class="pagination">') |
54 w(u'%s ' % self.previous_link(basepath, params)) |
77 w(u'%s ' % self.previous_link(basepath, params)) |
55 w(u'[ %s ]' % u' | '.join(blocklist)) |
78 w(u'<select onchange="javascript: document.location=this.options[this.selectedIndex].value">') |
|
79 for option in self.iter_page_links(basepath, params): |
|
80 w(option) |
|
81 w(u'</select>') |
56 w(u' %s' % self.next_link(basepath, params)) |
82 w(u' %s' % self.next_link(basepath, params)) |
57 w(u'</div>') |
83 w(u'</div>') |
58 |
|
59 def index_display(self, start, stop): |
|
60 return u'%s - %s' % (start+1, stop+1) |
|
61 |
84 |
62 |
85 |
63 class SortedNavigation(NavigationComponent): |
86 class SortedNavigation(NavigationComponent): |
64 """sorted navigation apply if navigation is needed (according to page size) |
87 """sorted navigation apply if navigation is needed (according to page size) |
65 and if the result set is sorted |
88 and if the result set is sorted |