From: Moritz Bunkus Date: Fri, 23 Nov 2012 11:15:39 +0000 (+0100) Subject: Refactoring: In Rückgabewert vom Paginated-DB-Helfer 'cur' in 'page' umbenennen X-Git-Tag: release-3.0.0beta2~6 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5b22ebf0e0e3cf62364dfb46a7f2de28f90289da;p=kivitendo-erp.git Refactoring: In Rückgabewert vom Paginated-DB-Helfer 'cur' in 'page' umbenennen Dient Konsistenz der Eingangs- und Ausgangsparameter. Dadurch entfällt auch das Hin- und Herbenennen im Paginated-Controller-Helfer/im L-Plugin. --- diff --git a/SL/Controller/Helper/Paginated.pm b/SL/Controller/Helper/Paginated.pm index 1683aada0..15997b8e9 100644 --- a/SL/Controller/Helper/Paginated.pm +++ b/SL/Controller/Helper/Paginated.pm @@ -61,16 +61,10 @@ sub get_current_paginate_params { : $spec->{PAGINATE_ARGS} ? do { my $sub = $spec->{PAGINATE_ARGS}; %{ $self->$sub() } } : (); my $calculated_params = "SL::DB::Manager::$spec->{MODEL}"->paginate(%paginate_params, args => \%paginate_args); - %paginate_params = ( - page => min($paginate_params{page}, $calculated_params->{max}), - per_page => $paginate_params{per_page}, - num_pages => $calculated_params->{max}, - common_pages => $calculated_params->{common}, - ); - # $::lxdebug->dump(0, "get_current_paginate_params: ", \%paginate_params); + # $::lxdebug->dump(0, "get_current_paginate_params: ", $calculated_params); - return %paginate_params; + return %{ $calculated_params }; } sub disable_pagination { diff --git a/SL/DB/Helper/Paginated.pm b/SL/DB/Helper/Paginated.pm index a0ad02cb8..27daffedd 100644 --- a/SL/DB/Helper/Paginated.pm +++ b/SL/DB/Helper/Paginated.pm @@ -17,12 +17,12 @@ sub paginate { $ret->{per_page} = per_page($self, %params); $ret->{max} = ceil($self->get_all_count(%args), $ret->{per_page}) || 1; - $ret->{cur} = $page < 1 ? 1 + $ret->{page} = $page < 1 ? 1 : $page > $ret->{max} ? $ret->{max} : $page; - $ret->{common} = make_common_pages($ret->{cur}, $ret->{max}); + $ret->{common} = make_common_pages($ret->{page}, $ret->{max}); - $params{args}{page} = $ret->{cur}; + $params{args}{page} = $ret->{page}; $params{args}{per_page} = $ret->{per_page}; delete $params{args}{limit}; delete $params{args}{offset}; diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 95d225441..c590082cf 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -689,11 +689,7 @@ sub paginate_controls { my %paginate_params = $controller->get_current_paginate_params; my %template_params = ( - pages => { - cur => $paginate_params{page}, - max => $paginate_params{num_pages}, - common => $paginate_params{common_pages}, - }, + pages => \%paginate_params, url_maker => sub { my %url_params = _hashify(@_); $url_params{ $paginate_spec->{FORM_PARAMS}->[0] } = delete $url_params{page}; diff --git a/templates/webpages/common/paginate.html b/templates/webpages/common/paginate.html index 089972947..c833904b8 100644 --- a/templates/webpages/common/paginate.html +++ b/templates/webpages/common/paginate.html @@ -8,11 +8,11 @@ [%- END %] [%- IF pages.max > 1 %]
-[%- IF pages.cur > 1 %]« [% 'prev' | $T8 %] [% ELSE %]« [% END %] +[%- IF pages.page > 1 %]« [% 'prev' | $T8 %] [% ELSE %]« [% END %] [%- FOR p = pages.common %] [%- NEXT UNLESS p.visible %] [%- IF p.active %][% p.page %] [% ELSE %][% p.page %] [%- END %] [%- END %] -[%- IF pages.cur < pages.max %][% 'next' | $T8 %] »[% ELSE %]»[%- END %] +[%- IF pages.page < pages.max %][% 'next' | $T8 %] »[% ELSE %]»[%- END %]
[%- END %]