source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Request.pm @ 1661

Last change on this file since 1661 was 1107, checked in by nanardon, 12 years ago

Add filter to object list

  • Property svn:keywords set to Id Rev
File size: 2.5 KB
Line 
1package LATMOS::Accounts::Web::Controller::Request;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Request - 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 :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27}
28
29sub default :LocalPath {
30    my ( $self, $c, undef, $form, $obj ) = @_;
31
32    $obj ||= $c->req->param('obj');
33
34    my $accreq = $c->model('Accounts')->db->get_object('accreq', $form) or do {
35        $c->forward('/no_object');
36        return;
37    };
38   
39    my $otype = $accreq->get_attributes('oType');
40    $c->stash->{accreq} = $accreq;
41
42    if ($accreq->get_attributes('requireObject')) {
43        if (!$obj) {
44            $c->stash->{ofilter} = $c->model('AttrFilter', $otype);
45            $c->stash->{select_object} = 1;
46            return;
47        } else {
48            $c->stash->{object} = $c->model('Accounts')->db->get_object(
49                $otype, $obj
50            );
51        }
52    }
53
54    require LATMOS::Accounts::Bases::Sql::DataRequest;
55    $c->stash->{datarequest} =
56        LATMOS::Accounts::Bases::Sql::DataRequest->new($accreq);
57    $c->stash->{datarequest}->set_ptr_object($c->stash->{object})
58        if ($c->stash->{object});
59
60    $c->stash->{form} = $c->model(
61        'AttrForms',
62        '',
63        $c->stash->{datarequest},
64        $c->model('Accounts')->db
65    );
66
67    # Default apply date:
68    my @date = localtime( time + 3600 * 24 ); # eg: tomorrow
69    $c->stash->{default_apply_date} = sprintf(
70        '%02d/%02d/%d',
71        $date[3],
72        $date[4] + 1,
73        $date[5] + 1900
74    );
75
76    if ($c->req->param('send')) {
77        my %attrs;
78        foreach ($c->stash->{datarequest}->attributes) {
79            my $htmlname = $c->stash->{form}->attr_field_name($_);
80            my @vals = $c->req->param($htmlname);
81            $attrs{$_} = @vals > 1 ? \@vals : $vals[0];
82        }
83        if ($c->stash->{datarequest}->register(
84            { user => $c->user->{username},
85              apply => $c->req->param('apply') ||
86              $c->stash->{default_apply_date} },
87            %attrs,
88        )) {
89            $c->go('recorded');
90        }
91    }
92
93}
94
95sub recorded : Private {
96    my ($self, $c) = @_;
97
98    my %attrs = $c->stash->{datarequest}->get_values;
99    $c->stash->{values} = \%attrs;
100}
101
102=head1 AUTHOR
103
104olivier
105
106=head1 LICENSE
107
108This library is free software. You can redistribute it and/or modify
109it under the same terms as Perl itself.
110
111=cut
112
113__PACKAGE__->meta->make_immutable;
114
1151;
Note: See TracBrowser for help on using the repository browser.