Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3c407887

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID 3c40788735ac0139e202480dad1972c051623105
  • Vorgänger 757b637e
  • Nachfolger f0e61977

FileUploader: Hatte FileUploader.pm nach Helper verschoben aber dann wieder zurück

Unterschiede anzeigen:

SL/Controller/FileUploader.pm
1
package SL::Controller::FileUploader;
2
# Controller will not be used if things for FILES needed they can go in Helpers
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

  
20
# this action can be thrown out, they where only for testing the testpage
21
sub action_test_page{
22
  my ($self) = @_;
23
  $self->render('fileuploader/test_page');
24
}
25

  
26
# this action renders the popup dialog to upload the file
27
sub action_ajax_add_file{
28
  my ($self) = @_;
29
  $self->file(SL::DB::File->new);
30
  $self->render('common/file_upload', { layout => 0}, data => $::form);
31
}
32

  
33

  
34
#
35
# helpers
36
#
37

  
38
sub validate_filetype {
39
  my ($self,$filename,$allowed_filetypes) = @_;
40

  
41
  my @errors;
42
  my($file,$filetype) = split /\./, $filename;
43
  my @file_types = split /\|/, $allowed_filetypes;
44

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

  
51
sub init_file {
52
  return SL::DB::File->new(id => $::form->{id})->load;
53
}
54

  
55
1;
56
__END__
57

  
58
=pod
59

  
60
=encoding utf8
61

  
62
=head1 NAME
63

  
64
  SL::Controller::FileUploader - Controller to manage fileuploads
65

  
66
=head1 SYNOPSIS
67

  
68
  use SL::Controller::FileUploader;
69

  
70
  # synopsis.. =>
71

  
72
=head1 DESCRIPTION
73

  
74
  just the action ajax_add_file is needed and its automaticly called by. The other ones are for the testpage templates/webpages/testpage.html
75
  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.
76
  [% L.button_tag("kivi.add_file(this.form.id.value,'shop_part', 'Part/do_something_with_file','jpg,png,gif,pdf')", 'Fileupload') %]
77

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

  
85

  
86
=head1 INTERFACE
87

  
88

  
89
=head1 DEPENDENCIES
90

  
91

  
92
=head1 SEE ALSO
93

  
94
=head1 AUTHOR
95

  
96
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
97

  
98
=cut

Auch abrufbar als: Unified diff