Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 757b637e

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID 757b637ef2ef00493ee4a9e7c7103100be05c25f
  • Vorgänger 1342327c
  • Nachfolger 3c407887

FileUploader: Überarbeitet Es kann jeder Controller/action jetzt aufgerufen. Javascript in extra Datei
Shoppart: Änderungen die den Dateiupload betreffen

Unterschiede anzeigen:

SL/Controller/ShopPart.pm
8 8
use SL::Locale::String qw(t8);
9 9
use SL::DB::ShopPart;
10 10
use SL::DB::File;
11
use SL::Controller::FileUploader;
11 12
use SL::DB::Default;
12 13
use SL::Helper::Flash;
13 14
use MIME::Base64;
14 15

  
15 16
use Rose::Object::MakeMethods::Generic
16 17
(
17
  'scalar --get_set_init' => [ qw(shop_part js) ],
18
  'scalar --get_set_init' => [ qw(shop_part file) ],
18 19
);
19 20

  
20 21
__PACKAGE__->run_before('check_auth');
......
65 66

  
66 67
}
67 68

  
69
sub action_ajax_upload_file{
70
  my ($self, %params) = @_;
71

  
72
  my $attributes                  = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix";
73
  $attributes->{trans_id}         = $::form->{trans_id} || die "Missing ID";
74
  $attributes->{modul}            = $::form->{modul} || die "Missing Modul";
75
  $attributes->{filename}         = $::form->{FILENAME} || die "Missing Filename";
76
  $attributes->{title}            = $::form->{ $::form->{form_prefix} }->{title};
77
  $attributes->{description}      = $::form->{ $::form->{form_prefix} }->{description};
78

  
79
  my @errors;
80
  my @file_errors = SL::DB::File->new(%{ $attributes })->validate;
81
  push @errors,@file_errors if @file_errors;
82

  
83
  my @type_error = SL::Controller::FileUploader->validate_filetype($attributes->{filename},$::form->{aft});
84
  push @errors,@type_error if @type_error;
85

  
86
  return $self->js->error(@errors)->render($self) if @errors;
87

  
88
  $self->file->assign_attributes(%{ $attributes });
89
  $self->file->file_update_type_and_dimensions;
90
  $self->file->save;
91
  #TODO return
92
}
68 93
sub action_get_categories {
69 94
  my ($self) = @_;
70 95

  
......
185 210
  };
186 211
}
187 212

  
213
sub init_file {
214
   #my $price_rule = $::form->{price_rule}{id} ? SL::DB::PriceRule->new(id => $::form->{price_rule}{id})->load : SL::DB::PriceRule->new;
215
   #return SL::DB::File->new();
216
  my $file = $::form->{id} ? SL::DB::File->new(id => $::form->{id})->load : SL::DB::File->new;
217
  return $file;
218
}
188 219
1;
189 220

  
190 221
=pod
SL/DB/File.pm
15 15

  
16 16
__PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id modul)]);
17 17

  
18
__PACKAGE__->before_save(\&file_update_thumbnail);
18
#__PACKAGE__->before_save(\&file_update_thumbnail);
19 19

  
20 20
sub validate {
21 21
  my ( $self ) = @_;
......
40 40

  
41 41
=head1 NAME
42 42

  
43
SL::DB::File - Databaseclass for Fileuploader
43
  SL::DB::File - Databaseclass for Fileuploader
44 44

  
45 45
=head1 SYNOPSIS
46 46

  
......
50 50

  
51 51
=head1 DESCRIPTION
52 52

  
53
# longer description.
53
  # longer description.
54 54

  
55 55

  
56 56
=head1 INTERFACE
......
63 63

  
64 64
=head1 AUTHOR
65 65

  
66
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
66
  Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
67 67

  
68 68
=cut
SL/DB/Helper/ThumbnailCreator.pm
24 24

  
25 25
sub file_create_thumbnail {
26 26
  my ($self) = @_;
27
  $main::lxdebug->dump(0, 'WH: CreateThumb',\$self);
28

  
27 29
  croak "No picture set yet" if !$self->file_content;
28 30

  
29 31
  my $image            = GD::Image->new($self->file_content);
......
102 104

  
103 105
=head1 NAME
104 106

  
105
SL::DB::Helper::ThumbnailCreator - DatabaseClass Helper for Fileuploads
107
  SL::DB::Helper::ThumbnailCreator - DatabaseClass Helper for Fileuploads
106 108

  
107 109
=head1 SYNOPSIS
108 110

  
......
112 114

  
113 115
=head1 DESCRIPTION
114 116

  
115
# longer description..
116
=head1 AUTHOR
117

  
118
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
119

  
120
=cut
121 117

  
122 118

  
123 119
=head1 INTERFACE
124 120

  
125 121

  
122

  
126 123
=head1 DEPENDENCIES
127 124

  
128 125

  
126

  
129 127
=head1 SEE ALSO
130 128

  
129
  # longer description..
130

  
131
=head1 AUTHOR
132

  
133
  # most things here from the thumbnailcreator in requirementspec
134

  
135
  Moritz Bunkus
136

  
137
  Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
138

  
139
=cut
131 140

  
SL/Helper/FileUploader.pm
1
package SL::Controller::Helper::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
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
  my $images = SL::DB::Manager::File->get_all( query => [ trans_id => $::form->{id}, modul => $::form->{modul} ] );
33

  
34

  
35
}
36
# this can go in Helpers::Fileuploader
37
sub action_ajax_add_file{
38
  my ($self) = @_;
39
  $self->file(SL::DB::File->new);
40
  $self->render('common/file_upload', { layout => 0}, DATA => $::form);
41
}
42

  
43
sub action_ajax_upload_file{
44
  my ($self, %params) = @_;
45
  my $attributes                  = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix";
46
  $attributes->{trans_id}         = $::form->{id} || die "Missing ID";
47
  $attributes->{modul}            = $::form->{modul} || die "Missing Modul";
48
  $attributes->{filename}         = $::form->{FILENAME} || die "Missing Filename";
49
  $attributes->{title}            = $::form->{ $::form->{form_prefix} }->{title};
50
  $attributes->{description}      = $::form->{ $::form->{form_prefix} }->{description};
51
  my @image_types = ("jpg","tif","png");
52

  
53
  my @errors = $self->file(SL::DB::File->new(%{ $attributes }))->validate;
54
  return $self->js->error(@errors)->render($self) if @errors;
55

  
56
  $self->file->save;
57

  
58
  # TODO js call
59
  $self->render('fileuploader/test_page');
60
}
61

  
62
#
63
# helpers
64
#
65

  
66
sub init_file {
67
  return SL::DB::File->new(id => $::form->{id})->load;
68
}
69

  
70
1;
71
__END__
72

  
73
=pod
74

  
75
=encoding utf8
76

  
77
=head1 NAME
78

  
79
SL::Controller::FileUploader - Controller to manage fileuploads
80

  
81
=head1 SYNOPSIS
82

  
83
  use SL::Controller::FileUploader;
84

  
85
  # synopsis.. =>
86

  
87
=head1 DESCRIPTION
88

  
89
# longer description...
90

  
91

  
92
=head1 INTERFACE
93

  
94

  
95
=head1 DEPENDENCIES
96

  
97

  
98
=head1 SEE ALSO
99

  
100
=head1 AUTHOR
101

  
102
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
103

  
104
=cut
bin/mozilla/ic.pl
1660 1660
    };
1661 1661
  };
1662 1662

  
1663
  $::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule kivi.shop_part);
1663
  $::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule kivi.shop_part kivi.FileUploader);
1664 1664
  $::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $::form->{id} * 1 ]})});") if $::form->{id};
1665 1665
  $form->header;
1666 1666
  #print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
js/kivi.FileUploader.js
1
namespace('kivi.FileUploader', function(ns) {
2
  //opens a popupdialog for fileupload
3
  //controller_action is passed to the popup_dialog fileupload form and can/will be called from the form to deal with the uploaded file
4
  ns.add_file = function(id,modul,controller_action,allowed_filetypes) {
5
    kivi.popup_dialog({
6
        url :           'controller.pl?action=FileUploader/ajax_add_file',
7
        data:           'id=' + id + '&modul=' + modul + '&ca=' + controller_action + '&aft=' + allowed_filetypes,
8
        dialog:         { title: kivi.t8('File upload') }
9
    } );
10
    return true;
11
  };
12
});
templates/webpages/common/file_upload.html
1 1
[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% USE Base64 %]
2 2
[% SET style="width: 500px" %]
3 3
[% SET id_base = "fileupload" %]
4
[% # L.dump(DATA) %]
4
[%  L.dump(data) %]
5 5
<form method="post" id="fileupload_form" method="POST" enctype="multipart/form-data">
6 6
 [% L.hidden_tag('form_prefix',                    id_base,         id=id_base _ '_form_prefix') %]
7
 [% L.hidden_tag('id',                             DATA.id, no_id=1) %]
8
 [% L.hidden_tag('modul',                          DATA.modul) %]
7
 [% L.hidden_tag('trans_id',                       data.id, no_id=1) %]
8
 [% L.hidden_tag('modul',                          data.modul) %]
9
 [% L.hidden_tag('aft',                            data.aft) %]
9 10

  
10 11
 <h2>
11 12
  [%- IF SELF.file.id %]
12 13
   [%- LxERP.t8("Edit file properties ", SELF.file.number) %]
13 14
  [%- ELSE %]
14
   [%- LxERP.t8("Add file to webdav") %]
15
   [%- LxERP.t8("Add file") %]
15 16
  [%- END %]
16 17
 </h2>
17 18

  
......
63 64

  
64 65
 <p>
65 66
 <!-- TODO action ändern in übergebene Variable, sodass jede xbelibiege Controller/Action aufgerufen werden kann -->
66
  [%- L.ajax_submit_tag('controller.pl?action=FileUploader/ajax_upload_file', '#fileupload_form', LxERP.t8('Save'), no_id=1) %]
67
  [%- L.ajax_submit_tag('controller.pl?action=' _ data.ca, '#fileupload_form', LxERP.t8('Save'), no_id=1) %]
67 68
  <a href="#" onclick="$('#jqueryui_popup_dialog').dialog('close');">[%- LxERP.t8("Cancel") %]</a>
68 69
 </p>
69 70

  
templates/webpages/shop_part/_list_images.html
20 20
      <td>[%  HTML.escape(img.title) %]</td>
21 21
      <td>[%  HTML.escape(img.description) %]</td>
22 22
      <td>[%  HTML.escape(img.filename) %]</td>
23
      <td>[%  HTML.escape(img.thumbnail_img_width) _  ' x ' _ HTML.escape(img.thumbnail_img_height) %]</td>
23
      <td>[%  HTML.escape(img.files_img_width) _  ' x ' _ HTML.escape(img.files_img_height) %]</td>
24 24
    </tr>
25 25
   [%  END %]
26 26
  </tbody>
......
28 28

  
29 29
[% L.sortable_element('#images_list tbody', url=SELF.url_for(action='reorder'), with='image_id') %]
30 30
<p>
31
[% L.button_tag("add_file(this.form.id.value,'shop_part')", 'Fileupload') %]
31
[% L.button_tag("kivi.FileUploader.add_file(this.form.id.value,'shop_part','ShopPart/ajax_upload_file','jpg|png|tif|gif')", 'Fileupload') %]
32 32
</p>
33

  
34

  
35

  
36
<!-- TODO javascript nach kivi.js id,modul,controller/action -->
37
<script type='text/javascript'>
38
<!--
39
function add_file(id,modul) {
40
  //var id = this.$('#part').val();
41
  kivi.popup_dialog({
42
        url :           'controller.pl?action=FileUploader/ajax_add_file',
43
        data:           'id=' + id + '&modul=' + modul,
44
        dialog:         { title: kivi.t8('File upload') }
45
  } );
46
   // var url = 'controller.pl?action=ShopPart/show_files?modul=shop_part&id=' + $('#id').val();
47
   // $('#images_list').load(url);
48
    //$('#jqueryui_popup_dialog').dialog('close');
49
  return true;
50
}
51
-->
52
</script>

Auch abrufbar als: Unified diff