source: LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/MassEdit.pm @ 244

Last change on this file since 244 was 244, checked in by nanardon, 15 years ago

fix hardcoded value

File size: 2.1 KB
Line 
1package LATMOS::Accounts::Web::Controller::MassEdit;
2
3use strict;
4use warnings;
5use base 'LATMOS::Accounts::Web::Controller';
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::MassEdit - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub 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
72Thauvin Olivier
73
74=head1 LICENSE
75
76This library is free software, you can redistribute it and/or modify
77it under the same terms as Perl itself.
78
79=cut
80
811;
Note: See TracBrowser for help on using the repository browser.