Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 93f51d62

Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt

  • ID 93f51d6216763896c85506cb815a9acbd653d4d5
  • Vorgänger 220746bf
  • Nachfolger 011c1238

Vermeidung von Package-Variablen

Unterschiede anzeigen:

SL/Controller/Helper/GetModels.pm
5 5
use Exporter qw(import);
6 6
our @EXPORT = qw(get_callback get_models);
7 7

  
8
my $current_action;
8
use constant PRIV => '__getmodelshelperpriv';
9

  
9 10
my %registered_handlers = ( callback => [], get_models => [] );
10 11

  
11 12
sub register_get_models_handlers {
......
15 16
  $only           = [ $only ] if !ref $only;
16 17
  my %hook_params = @{ $only } ? ( only => $only ) : ();
17 18

  
18
  $class->run_before(sub { $current_action = $_[1]; }, %hook_params);
19
  $class->run_before(sub { $_[0]->{PRIV()} = { current_action => $_[1] }; }, %hook_params);
19 20

  
20 21
  map { push @{ $registered_handlers{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %registered_handlers;
21 22
}
......
23 24
sub get_callback {
24 25
  my ($self, %override_params) = @_;
25 26

  
26
  my %default_params = _run_handlers($self, 'callback', action => $current_action);
27
  my %default_params = _run_handlers($self, 'callback', action => ($self->{PRIV()} || {})->{current_action});
27 28

  
28 29
  return $self->url_for(%default_params, %override_params);
29 30
}
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);
SL/Controller/Helper/Sorted.pm
5 5
use Exporter qw(import);
6 6
our @EXPORT = qw(make_sorted get_sort_spec get_current_sort_params _save_current_sort_params _get_models_handler_for_sorted _callback_handler_for_sorted);
7 7

  
8
my ($controller_sort_spec, $current_sort_by, $current_sort_dir);
8
use constant PRIV => '__sortedhelperpriv';
9

  
10
my $controller_sort_spec;
9 11

  
10 12
sub make_sorted {
11 13
  my ($class, %specs) = @_;
......
56 58
  my $sort_spec = $self->get_sort_spec;
57 59

  
58 60
  if (!$params{sort_by}) {
59
    $params{sort_by}  = $current_sort_by;
60
    $params{sort_dir} = $current_sort_dir;
61
    my $priv          = $self->{PRIV()} || {};
62
    $params{sort_by}  = $priv->{by};
63
    $params{sort_dir} = $priv->{dir};
61 64
  }
62 65

  
63 66
  my $by          = $params{sort_by} || $sort_spec->{DEFAULT_BY};
......
74 77
#
75 78

  
76 79
sub _save_current_sort_params {
77
  my ($self) = @_;
80
  my ($self)      = @_;
78 81

  
79
  my $sort_spec     = $self->get_sort_spec;
80
  $current_sort_by  =   $::form->{ $sort_spec->{FORM_PARAMS}->[0] };
81
  $current_sort_dir = !!$::form->{ $sort_spec->{FORM_PARAMS}->[1] } * 1;
82
  my $sort_spec   = $self->get_sort_spec;
83
  $self->{PRIV()} = {
84
    by            =>   $::form->{ $sort_spec->{FORM_PARAMS}->[0] },
85
    dir           => !!$::form->{ $sort_spec->{FORM_PARAMS}->[1] } * 1,
86
  };
82 87

  
83
  # $::lxdebug->message(0, "saving current sort params to $current_sort_by / $current_sort_dir");
88
  # $::lxdebug->message(0, "saving current sort params to " . $self->{PRIV()}->{by} . ' / ' . $self->{PRIV()}->{dir});
84 89
}
85 90

  
86 91
sub _callback_handler_for_sorted {
87 92
  my ($self, %params) = @_;
88 93

  
89
  if ($current_sort_by) {
94
  my $priv = $self->{PRIV()} || {};
95
  if ($priv->{by}) {
90 96
    my $sort_spec                             = $self->get_sort_spec;
91
    $params{ $sort_spec->{FORM_PARAMS}->[0] } = $current_sort_by;
92
    $params{ $sort_spec->{FORM_PARAMS}->[1] } = $current_sort_dir;
97
    $params{ $sort_spec->{FORM_PARAMS}->[0] } = $priv->{by};
98
    $params{ $sort_spec->{FORM_PARAMS}->[1] } = $priv->{dir};
93 99
  }
94 100

  
95 101
  # $::lxdebug->dump(0, "CB handler for sorted; params nach modif:", \%params);

Auch abrufbar als: Unified diff