1 | package LATMOS::Accounts::Web::Controller::MassEdit; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'LATMOS::Accounts::Web::Controller'; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Web::Controller::MassEdit - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub index : Private { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | |
---|
27 | my $base = $c->stash->{db} = $c->model('Accounts')->db; |
---|
28 | |
---|
29 | if ($c->req->param('otype') && $c->req->param('otype') ne $c->session->{filter}{otype}) { |
---|
30 | $c->session->{filter} = undef; |
---|
31 | $c->stash->{filter}{otype} = $c->req->param('otype'); |
---|
32 | $c->session->{massedit}{attrcol} = undef; |
---|
33 | } else { |
---|
34 | $c->stash->{filter} = $c->session->{filter}; |
---|
35 | if ($c->req->params->{attrcol}) { |
---|
36 | $c->session->{massedit}{attrcol} = [ grep { $_ } $c->req->param('attrcol') ]; |
---|
37 | } else { |
---|
38 | $c->req->params->{attrcol} = $c->session->{massedit}{attrcol}; |
---|
39 | } |
---|
40 | } |
---|
41 | $c->stash->{ofilter} = $c->model('AttrFilter', $c->stash->{filter}{otype}); |
---|
42 | |
---|
43 | if (($c->req->param('_change') || '') eq 'all') { |
---|
44 | my %change; |
---|
45 | foreach ($c->req->param('attrcol')) { |
---|
46 | $change{$_} = $c->req->param($_) || undef; |
---|
47 | delete($c->req->params->{$_}); |
---|
48 | } |
---|
49 | foreach my $id ($c->req->param('objid')) { |
---|
50 | my $obj = $base->get_object($c->req->param('otype'), $id) or next; |
---|
51 | $obj->set_c_fields(%change); |
---|
52 | } |
---|
53 | $base->commit; |
---|
54 | } elsif (($c->req->param('_change') || '') eq 'perobj') { |
---|
55 | foreach my $id ($c->req->param('objid')) { |
---|
56 | my $obj = $base->get_object($c->req->param('otype'), $id) or next; |
---|
57 | my %change; |
---|
58 | foreach ($c->req->param('attrcol')) { |
---|
59 | $change{$_} = $c->req->param($id . '_' . $_) || undef; |
---|
60 | delete($c->req->params->{$id . '_' . $_}); |
---|
61 | } |
---|
62 | $obj->set_c_fields(%change); |
---|
63 | } |
---|
64 | $base->commit; |
---|
65 | } |
---|
66 | $c->session->{filter} = $c->stash->{filter}; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | =head1 AUTHOR |
---|
71 | |
---|
72 | Thauvin Olivier |
---|
73 | |
---|
74 | =head1 LICENSE |
---|
75 | |
---|
76 | This library is free software, you can redistribute it and/or modify |
---|
77 | it under the same terms as Perl itself. |
---|
78 | |
---|
79 | =cut |
---|
80 | |
---|
81 | 1; |
---|