Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 757b637e

Von Werner Hahn vor fast 9 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
use SL::Locale::String qw(t8);
use SL::DB::ShopPart;
use SL::DB::File;
use SL::Controller::FileUploader;
use SL::DB::Default;
use SL::Helper::Flash;
use MIME::Base64;
use Rose::Object::MakeMethods::Generic
(
'scalar --get_set_init' => [ qw(shop_part js) ],
'scalar --get_set_init' => [ qw(shop_part file) ],
);
__PACKAGE__->run_before('check_auth');
......
}
sub action_ajax_upload_file{
my ($self, %params) = @_;
my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix";
$attributes->{trans_id} = $::form->{trans_id} || die "Missing ID";
$attributes->{modul} = $::form->{modul} || die "Missing Modul";
$attributes->{filename} = $::form->{FILENAME} || die "Missing Filename";
$attributes->{title} = $::form->{ $::form->{form_prefix} }->{title};
$attributes->{description} = $::form->{ $::form->{form_prefix} }->{description};
my @errors;
my @file_errors = SL::DB::File->new(%{ $attributes })->validate;
push @errors,@file_errors if @file_errors;
my @type_error = SL::Controller::FileUploader->validate_filetype($attributes->{filename},$::form->{aft});
push @errors,@type_error if @type_error;
return $self->js->error(@errors)->render($self) if @errors;
$self->file->assign_attributes(%{ $attributes });
$self->file->file_update_type_and_dimensions;
$self->file->save;
#TODO return
}
sub action_get_categories {
my ($self) = @_;
......
};
}
sub init_file {
#my $price_rule = $::form->{price_rule}{id} ? SL::DB::PriceRule->new(id => $::form->{price_rule}{id})->load : SL::DB::PriceRule->new;
#return SL::DB::File->new();
my $file = $::form->{id} ? SL::DB::File->new(id => $::form->{id})->load : SL::DB::File->new;
return $file;
}
1;
=pod
SL/DB/File.pm
__PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id modul)]);
__PACKAGE__->before_save(\&file_update_thumbnail);
#__PACKAGE__->before_save(\&file_update_thumbnail);
sub validate {
my ( $self ) = @_;
......
=head1 NAME
SL::DB::File - Databaseclass for Fileuploader
SL::DB::File - Databaseclass for Fileuploader
=head1 SYNOPSIS
......
=head1 DESCRIPTION
# longer description.
# longer description.
=head1 INTERFACE
......
=head1 AUTHOR
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
=cut
SL/DB/Helper/ThumbnailCreator.pm
sub file_create_thumbnail {
my ($self) = @_;
$main::lxdebug->dump(0, 'WH: CreateThumb',\$self);
croak "No picture set yet" if !$self->file_content;
my $image = GD::Image->new($self->file_content);
......
=head1 NAME
SL::DB::Helper::ThumbnailCreator - DatabaseClass Helper for Fileuploads
SL::DB::Helper::ThumbnailCreator - DatabaseClass Helper for Fileuploads
=head1 SYNOPSIS
......
=head1 DESCRIPTION
# longer description..
=head1 AUTHOR
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
=cut
=head1 INTERFACE
=head1 DEPENDENCIES
=head1 SEE ALSO
# longer description..
=head1 AUTHOR
# most things here from the thumbnailcreator in requirementspec
Moritz Bunkus
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
=cut
SL/Helper/FileUploader.pm
package SL::Controller::Helper::FileUploader;
# Controller will not be used if things for FILES needed they can go in Helpers
use strict;
use parent qw(SL::Controller::Base);
use SL::DB::File;
use SL::Helper::Flash;
use SL::Locale::String;
use Rose::Object::MakeMethods::Generic
(
'scalar --get_set_init' => [ qw(file) ],
);
#
# actions
#
sub action_test_page{
my ($self) = @_;
$self->render('fileuploader/test_page');
}
sub action_upload_form{
my ($self) = @_;
$self->file(SL::DB::File->new);
$self->render('common/file_upload', {header => 0});
}
sub action_show_files {
my ($self) = @_;
my $images = SL::DB::Manager::File->get_all( query => [ trans_id => $::form->{id}, modul => $::form->{modul} ] );
}
# this can go in Helpers::Fileuploader
sub action_ajax_add_file{
my ($self) = @_;
$self->file(SL::DB::File->new);
$self->render('common/file_upload', { layout => 0}, DATA => $::form);
}
sub action_ajax_upload_file{
my ($self, %params) = @_;
my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing FormPrefix";
$attributes->{trans_id} = $::form->{id} || die "Missing ID";
$attributes->{modul} = $::form->{modul} || die "Missing Modul";
$attributes->{filename} = $::form->{FILENAME} || die "Missing Filename";
$attributes->{title} = $::form->{ $::form->{form_prefix} }->{title};
$attributes->{description} = $::form->{ $::form->{form_prefix} }->{description};
my @image_types = ("jpg","tif","png");
my @errors = $self->file(SL::DB::File->new(%{ $attributes }))->validate;
return $self->js->error(@errors)->render($self) if @errors;
$self->file->save;
# TODO js call
$self->render('fileuploader/test_page');
}
#
# helpers
#
sub init_file {
return SL::DB::File->new(id => $::form->{id})->load;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
SL::Controller::FileUploader - Controller to manage fileuploads
=head1 SYNOPSIS
use SL::Controller::FileUploader;
# synopsis.. =>
=head1 DESCRIPTION
# longer description...
=head1 INTERFACE
=head1 DEPENDENCIES
=head1 SEE ALSO
=head1 AUTHOR
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
=cut
bin/mozilla/ic.pl
};
};
$::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule kivi.shop_part);
$::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule kivi.shop_part kivi.FileUploader);
$::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $::form->{id} * 1 ]})});") if $::form->{id};
$form->header;
#print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
js/kivi.FileUploader.js
namespace('kivi.FileUploader', function(ns) {
//opens a popupdialog for fileupload
//controller_action is passed to the popup_dialog fileupload form and can/will be called from the form to deal with the uploaded file
ns.add_file = function(id,modul,controller_action,allowed_filetypes) {
kivi.popup_dialog({
url : 'controller.pl?action=FileUploader/ajax_add_file',
data: 'id=' + id + '&modul=' + modul + '&ca=' + controller_action + '&aft=' + allowed_filetypes,
dialog: { title: kivi.t8('File upload') }
} );
return true;
};
});
templates/webpages/common/file_upload.html
[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% USE Base64 %]
[% SET style="width: 500px" %]
[% SET id_base = "fileupload" %]
[% # L.dump(DATA) %]
[% L.dump(data) %]
<form method="post" id="fileupload_form" method="POST" enctype="multipart/form-data">
[% L.hidden_tag('form_prefix', id_base, id=id_base _ '_form_prefix') %]
[% L.hidden_tag('id', DATA.id, no_id=1) %]
[% L.hidden_tag('modul', DATA.modul) %]
[% L.hidden_tag('trans_id', data.id, no_id=1) %]
[% L.hidden_tag('modul', data.modul) %]
[% L.hidden_tag('aft', data.aft) %]
<h2>
[%- IF SELF.file.id %]
[%- LxERP.t8("Edit file properties ", SELF.file.number) %]
[%- ELSE %]
[%- LxERP.t8("Add file to webdav") %]
[%- LxERP.t8("Add file") %]
[%- END %]
</h2>
......
<p>
<!-- TODO action ändern in übergebene Variable, sodass jede xbelibiege Controller/Action aufgerufen werden kann -->
[%- L.ajax_submit_tag('controller.pl?action=FileUploader/ajax_upload_file', '#fileupload_form', LxERP.t8('Save'), no_id=1) %]
[%- L.ajax_submit_tag('controller.pl?action=' _ data.ca, '#fileupload_form', LxERP.t8('Save'), no_id=1) %]
<a href="#" onclick="$('#jqueryui_popup_dialog').dialog('close');">[%- LxERP.t8("Cancel") %]</a>
</p>
templates/webpages/shop_part/_list_images.html
<td>[% HTML.escape(img.title) %]</td>
<td>[% HTML.escape(img.description) %]</td>
<td>[% HTML.escape(img.filename) %]</td>
<td>[% HTML.escape(img.thumbnail_img_width) _ ' x ' _ HTML.escape(img.thumbnail_img_height) %]</td>
<td>[% HTML.escape(img.files_img_width) _ ' x ' _ HTML.escape(img.files_img_height) %]</td>
</tr>
[% END %]
</tbody>
......
[% L.sortable_element('#images_list tbody', url=SELF.url_for(action='reorder'), with='image_id') %]
<p>
[% L.button_tag("add_file(this.form.id.value,'shop_part')", 'Fileupload') %]
[% L.button_tag("kivi.FileUploader.add_file(this.form.id.value,'shop_part','ShopPart/ajax_upload_file','jpg|png|tif|gif')", 'Fileupload') %]
</p>
<!-- TODO javascript nach kivi.js id,modul,controller/action -->
<script type='text/javascript'>
<!--
function add_file(id,modul) {
//var id = this.$('#part').val();
kivi.popup_dialog({
url : 'controller.pl?action=FileUploader/ajax_add_file',
data: 'id=' + id + '&modul=' + modul,
dialog: { title: kivi.t8('File upload') }
} );
// var url = 'controller.pl?action=ShopPart/show_files?modul=shop_part&id=' + $('#id').val();
// $('#images_list').load(url);
//$('#jqueryui_popup_dialog').dialog('close');
return true;
}
-->
</script>

Auch abrufbar als: Unified diff