Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a2a746b0

Von Werner Hahn vor mehr als 8 Jahren hinzugefügt

  • ID a2a746b043002d86fc0cee77ac5f70508b007bde
  • Vorgänger f0e61977
  • Nachfolger 45ea86a9

Fileuploader: Löschen, bearbeiten Liste wird aktualisiert angezeigt

Unterschiede anzeigen:

SL/Controller/ShopPart.pm
69 69
sub action_ajax_upload_file{
70 70
  my ($self, %params) = @_;
71 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};
72
  my $attributes                   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
73
  $attributes->{filename} = ((($::form->{ATTACHMENTS} || {})->{ $::form->{form_prefix} } || {})->{file_content} || {})->{filename};
78 74

  
79 75
  my @errors;
80 76
  my @file_errors = SL::DB::File->new(%{ $attributes })->validate;
......
88 84
  $self->file->assign_attributes(%{ $attributes });
89 85
  $self->file->file_update_type_and_dimensions;
90 86
  $self->file->save;
91
  #TODO return
87

  
88
  $self->js
89
    ->dialog->close('#jqueryui_popup_dialog')
90
    ->run('kivi.shop_part.show_images',$self->file->trans_id)
91
    ->render();
92
}
93

  
94
sub action_ajax_update_file{
95
  my ($self, %params) = @_;
96

  
97
  my $attributes                   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
98

  
99
  if (!$attributes->{file_content}) {
100
    delete $attributes->{file_content};
101
  } else {
102
    $attributes->{filename} = ((($::form->{ATTACHMENTS} || {})->{ $::form->{form_prefix} } || {})->{file_content} || {})->{filename};
103
  }
104

  
105
  my @errors;
106
  $self->file->assign_attributes(%{ $attributes });
107
  my @file_errors = $self->file->validate if $attributes->{file_content};;
108
  push @errors,@file_errors if @file_errors;
109

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

  
113
  return $self->js->error(@errors)->render($self) if @errors;
114

  
115
  $self->file->file_update_type_and_dimensions if $attributes->{file_content};
116
  $self->file->save;
117

  
118
  $self->js
119
    ->dialog->close('#jqueryui_popup_dialog')
120
    ->run('kivi.shop_part.show_images',$self->file->trans_id)
121
    ->render();
92 122
}
123

  
124
sub action_ajax_delete_file {
125
  my ( $self ) = @_;
126
  $self->file->delete;
127

  
128
  $self->js
129
    ->run('kivi.shop_part.show_images',$self->file->trans_id)
130
    ->render();
131
}
132

  
93 133
sub action_get_categories {
94 134
  my ($self) = @_;
95 135

  
136

  
96 137
#  my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
97 138
#  die unless $shop_part;
98 139
  require SL::Shop;
SL/DB/Helper/ThumbnailCreator.pm
81 81
  my ($self) = @_;
82 82

  
83 83
  return () if !$self->file_content;
84
  return () if $self->file_content_type && $self->file_img_width && $self->file_img_height && !Rose::DB::Object::Util::get_column_value_modified($self, 'file_content');
84
  return () if $self->file_content_type && $self->files_img_width && $self->files_img_height && !Rose::DB::Object::Util::get_column_value_modified($self, 'file_content');
85 85

  
86 86
  my @errors = $self->file_probe_type;
87 87
  return @errors if @errors;
js/kivi.FileUploader.js
16 16
    return true;
17 17
  };
18 18

  
19
  ns.delete_file = function(id) {
20
    alert ("ID: "+id);
19
  ns.delete_file = function(id,controller_action) {
20
    $.post('controller.pl', { action: controller_action, id: id }, function(data) {
21
      kivi.eval_json_result(data);
22
    });
21 23
  };
22 24
});
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
[% SET id_base = "fileupload" %]
3
[% SET id_base_bak = "fileupload" %]
4
[% SET id_base = 'fileupload_' _ (SELF.file.id ? SELF.file.id : 'new') %]
4 5
[%  L.dump(data) %]
5 6
<form method="post" id="fileupload_form" method="POST" enctype="multipart/form-data">
6 7
 [% 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('trans_id',                       data.trans_id) %]
9
 [% L.hidden_tag('modul',                          data.modul) %]
8
 [% L.hidden_tag(id_base _ '.id',                             SELF.file.id, no_id=1) %]
9
 [% L.hidden_tag(id_base _ '.trans_id',                       SELF.file.trans_id) %]
10
 [% L.hidden_tag(id_base _ '.modul',                          SELF.file.modul) %]
10 11
 [% L.hidden_tag('aft',                            data.aft) %]
11 12

  
12 13
 <h2>
13 14
  [%- IF SELF.file.id %]
14
   [%- LxERP.t8("Edit file properties ", SELF.file.number) %]
15
   [%- LxERP.t8("Edit file properties ", SELF.file.position) %]
15 16
  [%- ELSE %]
16 17
   [%- LxERP.t8("Add file") %]
17 18
  [%- END %]
......
20 21
 <table>
21 22
[% IF SELF.file.id %]
22 23
  <tr>
23
   <th align="right">[%- LxERP.t8("Number") %]:</th>
24
   <td>[% HTML.escape(SELF.file.number) %]</td>
24
   <th align="right">[%- LxERP.t8("Position") %]:</th>
25
   <td>[% HTML.escape(SELF.file.position) %]</td>
25 26
  </tr>
26 27
[% END %]
27 28

  
......
38 39
[% IF SELF.file.file_content %]
39 40
  <tr>
40 41
   <th align="right">[%- LxERP.t8("File name") %]:</th>
41
   <td>[% HTML.escape(SELF.file.file_file_name) %]</td>
42
   <td>[% HTML.escape(SELF.file.filename) %][% L.hidden_tag(id_base _ '.filename', SELF.file.filename) %][% L.hidden_tag('id',                             SELF.file.id, no_id=1) %]</td>
42 43
  </tr>
43 44

  
44 45
  <tr>
......
48 49

  
49 50
  <tr>
50 51
   <th align="right">[%- LxERP.t8("Dimensions") %]:</th>
51
   <td>[% HTML.escape(SELF.file.file_width) %]x[% HTML.escape(SELF.file.file_height) %]</td>
52
   <td>[% HTML.escape(SELF.file.files_img_width) %]x[% HTML.escape(SELF.file.files_img_height) %]</td>
52 53
  </tr>
53 54

  
54 55
  <tr>
55 56
   <th align="right">[%- LxERP.t8("Uploaded at") %]:</th>
56
   <td>[% HTML.escape(SELF.file.file_mtime.to_kivitendo(precision='second')) %]</td>
57
   <td>[% HTML.escape(SELF.file.files_mtime.to_kivitendo(precision='second')) %]</td>
57 58
  </tr>
58 59
[% END %]
59 60

  
templates/webpages/shop_part/_list_images.html
1 1
[%- USE HTML %][%- USE L -%][%- USE P -%][%- USE LxERP -%]
2 2
[%- USE T8 %][% USE Base64 %]
3 3
[%- USE Dumper %]
4
[% Dumper.dump(FORM) %]
4
[% # Dumper.dump(FORM) %]
5 5
<table width="100%" id="images_list">
6 6
  <thead>
7 7
    <tr class="listheading">
......
23 23
      <td>[% HTML.escape(img.description) %]</td>
24 24
      <td>[% HTML.escape(img.filename) %]</td>
25 25
      <td>[% HTML.escape(img.files_img_width) _  ' x ' _ HTML.escape(img.files_img_height) %]</td>
26
      <td>[% L.button_tag("kivi.FileUploader.delete_file(" _ img.id _ ")", LxERP.t8('Delete')) %] [% L.button_tag("kivi.FileUploader.add_file(" _ img.id _ "," _ FORM.id _ ",'shop_part','ShopPart/ajax_upload_file','jpg|png|tif|gif')", LxERP.t8('Edit')) %] </td>
26
      <td>[% L.button_tag("kivi.FileUploader.delete_file(" _ img.id _ ", 'ShopPart/ajax_delete_file')", LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %] [% L.button_tag("kivi.FileUploader.add_file(" _ img.id _ "," _ FORM.id _ ",'shop_part','ShopPart/ajax_update_file','jpg|png|tif|gif')", LxERP.t8('Edit')) %] </td>
27 27
    </tr>
28 28
   [%  END %]
29 29
  </tbody>

Auch abrufbar als: Unified diff