]> git.decadent.org.uk Git - maypole.git/commitdiff
updated pager - now shows first last plus 10 pages
authorAaron Trevena <aaron.trevena@gmail.com>
Sat, 16 Jun 2007 17:57:59 +0000 (17:57 +0000)
committerAaron Trevena <aaron.trevena@gmail.com>
Sat, 16 Jun 2007 17:57:59 +0000 (17:57 +0000)
git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@571 48953598-375a-da11-a14b-00016c27c3ee

lib/Maypole/templates/factory/pager

index 78c89fd6aa93da92fef0f4d59738b37f52588db5..cd03a4fad1e75347695e9216813595bc2cbfe3fc 100644 (file)
@@ -7,42 +7,72 @@ and search views. It expects a C<pager> template argument which responds
 to the L<Data::Page> interface.
 
 #%]
+
+[% BLOCK pager_link; %]
 [%
-IF pager AND pager.first_page != pager.last_page;
+          SET label = page_num;
+            SET args = "?page=" _ page_num;
+           SET args = args _ "&order=" _ request.params.order IF request.params.order;
+           SET args = args _ "&amp;o2=desc" IF request.params.o2 == "desc";
+            FOR col = pager_columns;
+              IF request.params.$col;
+                SET args = args _ "&" _ col _ "=" _ request.params.$col;
+                SET action = "search";
+              END;
+            END;
+            link(classmetadata.table, action, args, label);
 %]
-<p class="pager">Pages: 
+[% END; %]
+
+
+[% IF pager %]
+<p class="pager">
+Page 
+[% IF pager.first_page == pager.last_page; %]
+1 of 1
+[% ELSE %]
+[% pager.current_page %] of [% pager.last_page %] &nbsp; | &nbsp;
 [%
     UNLESS pager_action;
        SET pager_action = request.action;
     END;
    
-    SET begin_page = pager.current_page - 10;
+   UNLESS pager_columns;
+        SET pager_columns = classmetadata.columns.list;
+   END;
+
+    SET end_page = pager.current_page + 5;
+    SET begin_page = pager.current_page - 5;
     IF begin_page < 1;
-        SET begin_page = pager.first_page;
+        SET begin_page = 1;
+       SET end_page = 10;
     END;
-    SET end_page = pager.current_page + 10;
+
     IF pager.last_page < end_page;
         SET end_page = pager.last_page;
+       IF (end_page - 10) > 1;
+         begin_page = end_page - 10;
+       END;
+    END;
+
+    IF begin_page > 1;
+           PROCESS pager_link page_num = 1, action = pager_action;
     END;
+
      FOREACH num = [begin_page .. end_page];
           IF num == pager.current_page;
             "<span class='current-page'>"; num; "</span>";
           ELSE;
-            SET label = num;
-            SET args = "?page=" _ num;
-           SET args = args _ "&order=" _ request.params.order
-             IF request.params.order;
-           SET args = args _ "&amp;o2=desc"
-             IF request.params.o2 == "desc";
-            FOR col = classmetadata.columns.list;
-              IF request.params.$col;
-                SET args = args _ "&" _ col _ "=" _ request.params.$col;
-                SET action = "search";
-              END;
-            END;
-            link(classmetadata.table, pager_action, args, label);
+           PROCESS pager_link page_num = num, action = pager_action;
           END;
      END;
+
+     IF end_page < pager.last_page;
+       PROCESS pager_link page_num = pager.last_page, action = pager_action;
+     END;
+
+END;
 %]
 </p>
 [% END %]
+