root/veekun/trunk/templates/common.tt

Revision 345, 2.4 kB (checked in by eevee, 14 months ago)

Apparently Template::Plugin::Math is gone from the latest releases, so I've taken out the few times I used it.

Line 
1[% PAGE_RADIUS = 2 %]
2[% MACRO pagelink(page, pagesize, action, params) BLOCK %]
3[%     IF page == 1 %]
4[%         params.delete('skip') %]
5[%     ELSE %]
6[%         params.skip = (page - 1) * pagesize %]
7[%     END %]
8[%     c.uri_for(action, params).replace('&', ';') # fuck ampersands %]
9[% END %]
10
11
12[% MACRO pagelist(skip, pagesize, total, action, params) BLOCK %]
13[%     IF skip OR pagesize < total %]
14<div class="pagelist">
15<div class="label">Pages:</div>
16[%         ellipsesed = 0 %]
17[%         pagect = total / pagesize + 0.999999999999 %]
18[%         pagect = int(pagect) %]
19[%         curpage = skip / pagesize + 1 %]
20[%         IF curpage > 1 %]
21<a href="[% pagelink(1, pagesize, action, params) %]" class="endcap">First</a>
22<a href="[% tmp = curpage - 0.000001; tmp = int(tmp); pagelink(tmp, pagesize, action, params) %]" class="endcap">Prev</a>
23[%         ELSE %]
24<span class="endcap">First</span>
25<span class="endcap">Prev</span>
26[%         END %]
27[%         FOREACH i IN [ 1 .. pagect ] %]
28[%#             IF i <= PAGE_RADIUS OR i > pagect - PAGE_RADIUS OR (i >= curpage - PAGE_RADIUS AND i <= curpage + PAGE_RADIUS) %]
29[%             IF i == curpage OR
30                  (i < curpage AND (curpage <=          PAGE_RADIUS * 2 + 2 OR i <= PAGE_RADIUS           OR i >= curpage - PAGE_RADIUS)) OR
31                  (i > curpage AND (curpage >= pagect - PAGE_RADIUS * 2 - 1 OR i <= curpage + PAGE_RADIUS OR i >  pagect  - PAGE_RADIUS)) %]
32[%                 ellipsesed = 0 %]
33[%                 IF i == curpage %]
34<span>[% i %]</span>
35[%                 ELSE %]
36[%                     IF i > curpage AND i - 1 < curpage %]<span>*</span>[% END %]
37<a href="[% pagelink(i, pagesize, action, params) %]">[% i %]</a>
38[%                 END %]
39[%             ELSE %]
40[%                 IF NOT ellipsesed %]
41<span class="endcap">...</span>
42[%                     ellipsesed = 1 %]
43[%                 ELSE %]
44[%                 END %]
45[%             END %]
46[%         END %]
47[%         IF curpage > pagect %]<span>*</span>[% END %]
48[%         IF curpage < pagect %]
49<a href="[% tmp = curpage + 1.000001; tmp = int(tmp); pagelink(tmp, pagesize, action, params) %]" class="endcap">Next</a>
50<a href="[% pagelink(pagect, pagesize, action, params) %]" class="endcap">Last</a>
51[%         ELSE %]
52<span class="endcap">Next</span>
53<span class="endcap">Last</span>
54[%         END %]
55</div>
56[%         IF skip; params.skip = skip; ELSE; params.delete('skip'); END %]
57[%     END %]
58[% END %]
Note: See TracBrowser for help on using the browser.