source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Tools/LoadNew.pm @ 2301

Last change on this file since 2301 was 2301, checked in by nanardon, 5 years ago

Allow to pass name: in object definition

File size: 1.5 KB
Line 
1package LATMOS::Accounts::Web::Controller::Tools::LoadNew;
2use Moose;
3use namespace::autoclean;
4
5use LATMOS::Accounts::Utils;
6use File::Temp;
7
8BEGIN { extends 'Catalyst::Controller'; }
9
10=head1 NAME
11
12LATMOS::Accounts::Web::Controller::Tools::LoadNew - Catalyst Controller
13
14=head1 DESCRIPTION
15
16Catalyst Controller.
17
18=head1 METHODS
19
20=cut
21
22
23=head2 index
24
25=cut
26
27sub index :Path :Args(0) {
28    my ( $self, $c ) = @_;
29
30    if (my $upload = $c->req->upload('input')) {
31        my %attrs = LATMOS::Accounts::Utils::parse_obj_file($upload->fh);
32        my $otype = $c->req->param('otype');
33        $c->session->{ochelper} = {
34            contents => \%attrs,
35            name => { content => $attrs{name} },
36        };
37        $c->req->params->{step} = '1';
38        $c->go('/create/default', [ undef, $otype ]);
39    } elsif (my $content = $c->req->param('content')) {
40        my $tmp = File::Temp->new();
41        print $tmp $content;
42        $tmp->seek( 0, 0 );
43
44        my %attrs = LATMOS::Accounts::Utils::parse_obj_file($tmp);
45        $tmp = undef;
46        my $otype = $c->req->param('otype');
47        $c->session->{ochelper} = {
48            contents => \%attrs,
49            name => { content => $attrs{name} },
50        };
51        $c->req->params->{step} = '1';
52        $c->go('/create/default', [ undef, $otype ]);
53    }
54}
55
56
57
58=encoding utf8
59
60=head1 AUTHOR
61
62Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
63
64=head1 LICENSE
65
66This library is free software. You can redistribute it and/or modify
67it under the same terms as Perl itself.
68
69=cut
70
71__PACKAGE__->meta->make_immutable;
72
731;
Note: See TracBrowser for help on using the repository browser.