Revision 93f51d62
Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt
SL/Controller/Helper/Paginated.pm | ||
---|---|---|
5 | 5 |
use Exporter qw(import); |
6 | 6 |
our @EXPORT = qw(make_paginated get_paginate_spec get_current_paginate_params _save_current_paginate_params _get_models_handler_for_paginated _callback_handler_for_paginated); |
7 | 7 |
|
8 |
my ($controller_paginate_spec, $current_page, $current_per_page); |
|
8 |
use constant PRIV => '__paginatedhelper_priv'; |
|
9 |
|
|
10 |
my $controller_paginate_spec; |
|
9 | 11 |
|
10 | 12 |
sub make_paginated { |
11 | 13 |
my ($class, %specs) = @_; |
... | ... | |
43 | 45 |
|
44 | 46 |
my $spec = $self->get_paginate_spec; |
45 | 47 |
|
46 |
$params{page} = $current_page unless defined $params{page}; |
|
47 |
$params{per_page} = $current_per_page unless defined $params{per_page}; |
|
48 |
my $priv = $self->{PRIV()} || {}; |
|
49 |
$params{page} = $priv->{page} unless defined $params{page}; |
|
50 |
$params{per_page} = $priv->{per_page} unless defined $params{per_page}; |
|
48 | 51 |
|
49 | 52 |
my %paginate_params = ( |
50 | 53 |
page => ($params{page} * 1) || 1, |
... | ... | |
71 | 74 |
my ($self) = @_; |
72 | 75 |
|
73 | 76 |
my $paginate_spec = $self->get_paginate_spec; |
74 |
$current_page = $::form->{ $paginate_spec->{FORM_PARAMS}->[0] } || 1; |
|
75 |
$current_per_page = $::form->{ $paginate_spec->{FORM_PARAMS}->[1] } * 1; |
|
77 |
$self->{PRIV()} = { |
|
78 |
page => $::form->{ $paginate_spec->{FORM_PARAMS}->[0] } || 1, |
|
79 |
per_page => $::form->{ $paginate_spec->{FORM_PARAMS}->[1] } * 1, |
|
80 |
}; |
|
76 | 81 |
|
77 |
# $::lxdebug->message(0, "saving current paginate params to $current_page / $current_per_page");
|
|
82 |
# $::lxdebug->message(0, "saving current paginate params to " . $self->{PRIV()}->{page} . ' / ' . $self->{PRIV()}->{per_page});
|
|
78 | 83 |
} |
79 | 84 |
|
80 | 85 |
sub _callback_handler_for_paginated { |
81 | 86 |
my ($self, %params) = @_; |
87 |
my $priv = $self->{PRIV()} || {}; |
|
82 | 88 |
|
83 |
if ($current_page) {
|
|
89 |
if ($priv->{page}) {
|
|
84 | 90 |
my $paginate_spec = $self->get_paginate_spec; |
85 |
$params{ $paginate_spec->{FORM_PARAMS}->[0] } = $current_page;
|
|
86 |
$params{ $paginate_spec->{FORM_PARAMS}->[1] } = $current_per_page if $current_per_page;
|
|
91 |
$params{ $paginate_spec->{FORM_PARAMS}->[0] } = $priv->{page};
|
|
92 |
$params{ $paginate_spec->{FORM_PARAMS}->[1] } = $priv->{per_page} if $priv->{per_page};
|
|
87 | 93 |
} |
88 | 94 |
|
89 | 95 |
# $::lxdebug->dump(0, "CB handler for paginated; params nach modif:", \%params); |
Auch abrufbar als: Unified diff
Vermeidung von Package-Variablen