Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 38dbb246

Von Werner Hahn vor mehr als 7 Jahren hinzugefügt

  • ID 38dbb246deb2757ae2c1ca7561a27300c11dbfd1
  • Vorgänger 1050369d
  • Nachfolger d364b3e9

Shopmodul: Nicht benötigte Datei gelöscht

Unterschiede anzeigen:

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_ajax_add_file{
25
  my ($self) = @_;
26
  $self->file( $::form->{id} ? SL::DB::File->new(id => $::form->{id})->load : SL::DB::File->new );
27
  $self->render('common/file_upload', { layout => 0}, data => $::form);
28
}
29

  
30

  
31
#
32
# helpers
33
#
34

  
35
sub validate_filetype {
36
  my ($self,$filename,$allowed_filetypes) = @_;
37

  
38
  my @errors;
39
  my($file,$filetype) = split /\./, $filename;
40
  my @file_types = split /\|/, $allowed_filetypes;
41

  
42
  if (!grep {$_ eq $filetype} @file_types) {
43
      push @errors, t8("Filetype not allowed");
44
  }
45
  return @errors
46
}
47

  
48
sub init_file {
49
  return SL::DB::File->new(id => $::form->{id})->load;
50
}
51

  
52
1;
53
__END__
54

  
55
=pod
56

  
57
=encoding utf8
58

  
59
=head1 NAME
60

  
61
SL::Controller::FileUploader - Controller to manage fileuploads
62

  
63
=head1 SYNOPSIS
64

  
65
  use SL::Controller::FileUploader;
66

  
67
  # synopsis.. =>
68

  
69
=head1 DESCRIPTION
70

  
71
 just the action ajax_add_file is needed and its automaticly called by. The other ones are for the testpage templates/webpages/testpage.html
72
 kivi.add.file(id[shop_part_id,part_id, cv_id, project_id,...],modul[part,shop_part,project,IC,...],controller_action[ShopPart/do_something_file],allowed_filestypes) in your template.
73
 [% L.button_tag("kivi.add_file(this.form.id.value,'shop_part', 'Part/do_something_with_file','jpg,png,gif,pdf')", 'Fileupload') %]
74

  
75
 The called Controller/Action deals with the uploaded file in wich you can do whatever you want with the file.
76
 like
77
 - Store it in the Database SL::DB::File
78
 - Store it in Webdav
79
 - Store it in Webdav and DB (be careful: files wich deleted in the filesystem will not be deleted in the database automaticly)
80
 - do something very fancy with the file
81

  
82

  
83
=head1 INTERFACE
84

  
85

  
86
=head1 DEPENDENCIES
87

  
88

  
89
=head1 SEE ALSO
90

  
91
=head1 AUTHOR
92

  
93
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
94

  
95
=cut

Auch abrufbar als: Unified diff