1 | package LATMOS::Accounts::Web::Controller::Request; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Web::Controller::Request - 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 :Path :Args(0) { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | |
---|
27 | } |
---|
28 | |
---|
29 | sub 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 | |
---|
95 | sub 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 | |
---|
104 | olivier |
---|
105 | |
---|
106 | =head1 LICENSE |
---|
107 | |
---|
108 | This library is free software. You can redistribute it and/or modify |
---|
109 | it under the same terms as Perl itself. |
---|
110 | |
---|
111 | =cut |
---|
112 | |
---|
113 | __PACKAGE__->meta->make_immutable; |
---|
114 | |
---|
115 | 1; |
---|