From: Sven Schöling Date: Thu, 21 Jul 2011 14:04:17 +0000 (+0200) Subject: Paginating Sanity: X-Git-Tag: release-2.7.0beta1~135 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6c0aa04610dde7e6bdc69394da0f0c8133b10280;p=kivitendo-erp.git Paginating Sanity: Nur Seiten anzeigen die... - Erste oder letzte Seite sind - In der Nähe der aktuellen Seite (+-3) - 10,50,100,500,1000,5000 Seiten von der aktuellen entfernt sind --- diff --git a/SL/DB/Helper/Paginated.pm b/SL/DB/Helper/Paginated.pm index a5a07d067..df5a6e3d9 100644 --- a/SL/DB/Helper/Paginated.pm +++ b/SL/DB/Helper/Paginated.pm @@ -6,6 +6,8 @@ require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(paginate); +use List::MoreUtils qw(any); + sub paginate { my ($self, %params) = @_; my $page = $params{page} || 1; @@ -47,12 +49,21 @@ sub make_common_pages { my ($cur, $max) = @_; return [ map { - active => $_ != $cur, - page => $_, + active => $_ != $cur, + page => $_, + visible => }, 1 .. $max ]; } +sub calc_visibility { + my ($cur, $max, $this) = @_; + any { $_ } abs($cur - $this) < 5, + $cur <= 3, + $cur == $max, + any { ! abs ($cur - $this) % $_ } 10, 50, 100, 500, 1000, 5000; +} + 1; __END__ diff --git a/templates/webpages/common/paginate.html b/templates/webpages/common/paginate.html index 6611f774c..3724f8e8b 100644 --- a/templates/webpages/common/paginate.html +++ b/templates/webpages/common/paginate.html @@ -1,10 +1,8 @@ [%- IF pages.max > 1 %] -[%- IF pages.cur > 1 %]« [%- END %] +[%- IF pages.cur > 1 %]« [% ELSE %]« [% END %] [%- FOR p = pages.common %] - [%- IF p.active %][% p.page %] - [%- ELSE %][% p.page %] - [%- END %] - [%- ' ' UNLESS loop.last %] + [%- NEXT UNLESS p.visible %] + [%- IF p.active %][% p.page %] [% ELSE %][% p.page %] [%- END %] [%- END %] -[%- IF pages.cur < pages.max %] »[%- END %] +[%- IF pages.cur < pages.max %]»[% ELSE %]»[%- END %] [%- END %]