Revision 8081e39b
Von Werner Hahn vor mehr als 8 Jahren hinzugefügt
SL/Controller/FileUploader.pm | ||
---|---|---|
1 |
package SL::Controller::FileUploader; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use parent qw(SL::Controller::Base); |
|
5 |
|
|
6 |
use SL::DB::File; |
|
7 |
|
|
8 |
use SL::Helper::Flash; |
|
9 |
use SL::Locale::String; |
|
10 |
|
|
11 |
use Rose::Object::MakeMethods::Generic |
|
12 |
( |
|
13 |
'scalar --get_set_init' => [ qw(file) ], |
|
14 |
); |
|
15 |
|
|
16 |
# |
|
17 |
# actions |
|
18 |
# |
|
19 |
sub action_test_page{ |
|
20 |
my ($self) = @_; |
|
21 |
$self->render('fileuploader/test_page'); |
|
22 |
} |
|
23 |
|
|
24 |
sub action_upload_form{ |
|
25 |
my ($self) = @_; |
|
26 |
$self->file(SL::DB::File->new); |
|
27 |
$self->render('common/file_upload', {header => 0}); |
|
28 |
} |
|
29 |
|
|
30 |
sub action_show_files { |
|
31 |
my ($self) = @_; |
|
32 |
|
|
33 |
|
|
34 |
} |
|
35 |
|
|
36 |
sub action_ajax_add_file{ |
|
37 |
my ($self) = @_; |
|
38 |
$self->file(SL::DB::File->new); |
|
39 |
$self->render('common/file_upload', { layout => 0}, DATA => $::form); |
|
40 |
} |
|
41 |
|
|
42 |
sub action_ajax_upload_file{ |
|
43 |
my ($self, %params) = @_; |
|
44 |
my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix"; |
|
45 |
$attributes->{trans_id} = $::form->{id} || die "Missing ID"; |
|
46 |
$attributes->{modul} = $::form->{modul} || die "Missing Modul"; |
|
47 |
$attributes->{filename} = $::form->{FILENAME} || die "Missing Filename"; |
|
48 |
$attributes->{title} = $::form->{ $::form->{form_prefix} }->{title}; |
|
49 |
$attributes->{description} = $::form->{ $::form->{form_prefix} }->{description}; |
|
50 |
my @image_types = ("jpg","tif","png"); |
|
51 |
|
|
52 |
my @errors = $self->file(SL::DB::File->new(%{ $attributes }))->validate; |
|
53 |
return $self->js->error(@errors)->render($self) if @errors; |
|
54 |
|
|
55 |
$self->file->save; |
|
56 |
|
|
57 |
# TODO js call |
|
58 |
$self->render('fileuploader/test_page'); |
|
59 |
} |
|
60 |
|
|
61 |
# |
|
62 |
# helpers |
|
63 |
# |
|
64 |
|
|
65 |
sub init_file { |
|
66 |
return SL::DB::File->new(id => $::form->{id})->load; |
|
67 |
} |
|
68 |
|
|
69 |
1; |
|
70 |
__END__ |
|
71 |
|
|
72 |
=pod |
|
73 |
|
|
74 |
=encoding utf8 |
|
75 |
|
|
76 |
=head1 NAME |
|
77 |
|
|
78 |
SL::Controller::FileUploader - Controller to manage fileuploads |
|
79 |
|
|
80 |
=head1 SYNOPSIS |
|
81 |
|
|
82 |
use SL::Controller::FileUploader; |
|
83 |
|
|
84 |
# synopsis.. => |
|
85 |
|
|
86 |
=head1 DESCRIPTION |
|
87 |
|
|
88 |
# longer description... |
|
89 |
|
|
90 |
|
|
91 |
=head1 INTERFACE |
|
92 |
|
|
93 |
|
|
94 |
=head1 DEPENDENCIES |
|
95 |
|
|
96 |
|
|
97 |
=head1 SEE ALSO |
|
98 |
|
|
99 |
=head1 AUTHOR |
|
100 |
|
|
101 |
Werner Hahn E<lt>wh@futureworldsearch.netE<gt> |
|
102 |
|
|
103 |
=cut |
Auch abrufbar als: Unified diff
Fileuploader: cherry-pick