]> git.decadent.org.uk Git - maypole.git/blob - lib/Maypole/templates/factory/pager
updated pager - now shows first last plus 10 pages
[maypole.git] / lib / Maypole / templates / factory / pager
1 [%#
2
3 =head1 pager
4
5 This controls the pager display at the bottom (by default) of the list
6 and search views. It expects a C<pager> template argument which responds
7 to the L<Data::Page> interface.
8
9 #%]
10
11 [% BLOCK pager_link; %]
12 [%
13           SET label = page_num;
14             SET args = "?page=" _ page_num;
15             SET args = args _ "&order=" _ request.params.order IF request.params.order;
16             SET args = args _ "&amp;o2=desc" IF request.params.o2 == "desc";
17             FOR col = pager_columns;
18               IF request.params.$col;
19                 SET args = args _ "&" _ col _ "=" _ request.params.$col;
20                 SET action = "search";
21               END;
22             END;
23             link(classmetadata.table, action, args, label);
24 %]
25 [% END; %]
26
27
28 [% IF pager %]
29 <p class="pager">
30 Page 
31 [% IF pager.first_page == pager.last_page; %]
32 1 of 1
33 [% ELSE %]
34 [% pager.current_page %] of [% pager.last_page %] &nbsp; | &nbsp;
35 [%
36     UNLESS pager_action;
37         SET pager_action = request.action;
38     END;
39    
40    UNLESS pager_columns;
41         SET pager_columns = classmetadata.columns.list;
42    END;
43
44     SET end_page = pager.current_page + 5;
45     SET begin_page = pager.current_page - 5;
46     IF begin_page < 1;
47         SET begin_page = 1;
48         SET end_page = 10;
49     END;
50
51     IF pager.last_page < end_page;
52         SET end_page = pager.last_page;
53         IF (end_page - 10) > 1;
54           begin_page = end_page - 10;
55         END;
56     END;
57
58     IF begin_page > 1;
59             PROCESS pager_link page_num = 1, action = pager_action;
60     END;
61
62      FOREACH num = [begin_page .. end_page];
63           IF num == pager.current_page;
64             "<span class='current-page'>"; num; "</span>";
65           ELSE;
66             PROCESS pager_link page_num = num, action = pager_action;
67           END;
68      END;
69
70      IF end_page < pager.last_page;
71        PROCESS pager_link page_num = pager.last_page, action = pager_action;
72      END;
73
74 END;
75 %]
76 </p>
77 [% END %]
78