Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 860c8bbe

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 860c8bbe44b658a34a3129dc8b6b0a99a8d02cb0
  • Vorgänger 21e2dc57
  • Nachfolger 95f810ee

EmailJournal: Anhangsvorschau mit kopierbaren Text

Unterschiede anzeigen:

SL/Controller/EmailJournal.pm
back_to => $back_to);
}
sub action_show_attachment {
my ($self) = @_;
$::auth->assert('email_journal');
my $attachment_id = $::form->{attachment_id};
my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load;
return $self->send_file(
\$attachment->content,
name => $attachment->name,
type => $attachment->mime_type,
content_disposition => 'inline',
);
}
sub action_download_attachment {
my ($self) = @_;
......
->replaceWith('#attachment_preview',
SL::Presenter::EmailJournal::attachment_preview(
$attachment,
style => "width:655px;border:1px solid black;margin:9px"
style => "height:1800px"
)
)
->render();
SL/Presenter/EmailJournal.pm
use strict;
use SL::Presenter::EscapedText qw(escape is_escaped);
use SL::Presenter::Tag qw(link_tag img_tag html_tag);
use SL::Presenter::Tag qw(link_tag html_tag div_tag);
use SL::Locale::String qw(t8);
use SL::SessionFile::Random;
use SL::DB::EmailJournalAttachment;
......
my ($attachment_or_id, %params) = @_;
if (! $attachment_or_id) {
return is_escaped(html_tag('div', '', id => 'attachment_preview'));
}
my $attachment = ref $attachment_or_id ? $attachment_or_id
: SL::DB::EmailJournalAttachment->new(id => $attachment_or_id)->load;
# clean up mime_type
my $mime_type = $attachment->mime_type;
$mime_type =~ s/;.*//;
# parse to img tag
my $image_tags = '';
if ($mime_type =~ m{^image/}) {
my $image_content = $attachment->content;
my $img_base64 = "data:$mime_type;base64," . MIME::Base64::encode_base64($image_content);
my $image_tag = img_tag(
src => $img_base64,
alt => escape($attachment->name),
%params);
$image_tags .= $image_tag;
} elsif ($mime_type =~ m{^application/pdf}) {
my $pdf_content = $attachment->content;
my $session_file = SL::SessionFile::Random->new(mode => 'w');
$session_file->fh->print($pdf_content);
$session_file->fh->close;
my $image_size = 2048;
my $file_name = $session_file->file_name;
# files are created in session_files folder
my $command = 'pdftoppm -forcenum -scale-to '
. $image_size . ' -png' . ' '
. $file_name . ' ' . $file_name;
my $ans = system($command);
if ($ans != 0) {
return;
}
my @image_file_names = glob($file_name . '-*.png');
unlink($file_name);
my $image_count = scalar @image_file_names;
my $counter = 1;
foreach my $image_file_name (@image_file_names) {
my $image_file = SL::SessionFile->new($image_file_name, mode => 'r');
my $file_size = -s $image_file->file_name;
my $image_content;
read($image_file->fh, $image_content, $file_size);
my $img_base64 = 'data:image/png;base64,' . MIME::Base64::encode_base64($image_content);
my $name_ending = $image_count > 1 ? "-($counter/$image_count)" : '';
my $image_tag = img_tag(
src => $img_base64,
alt => escape($attachment->name) . $name_ending,
%params);
unlink($image_file->file_name);
$image_tags .= $image_tag;
}
return is_escaped(div_tag('', id => 'attachment_preview'));
}
my $attachment_id = ref $attachment_or_id ? $attachment_or_id->id
: $attachment_or_id;
my $attachment_preview = html_tag('div', $image_tags, id => 'attachment_preview');
require SL::Controller::EmailJournal;
my $src_url = SL::Controller::EmailJournal->new->url_for(
action => 'show_attachment',
attachment_id => $attachment_id
);
$params{style} .= "; display:flex; resize:both; overflow:hidden; padding-bottom:5px";
my $attachment_preview = div_tag(
html_tag('iframe', '', src => $src_url,
width => "100%", height => '100%',
"flex-grow" => '1',
),
id => 'attachment_preview',
%params
);
return is_escaped($attachment_preview);
}
templates/design40_webpages/email_journal/show.html
[% SET attachments = SELF.entry.attachments_sorted %]
<div class="input-panel" style="vertical-align:top;" id="wrapper-2">
<div class="wrapper input-panel" style="vertical-align:top;" id="wrapper-2">
[% IF attachments.size %]
<table id="email_journal_details" class="tbl-list">
......
[% L.select_tag('record_action',
# id has to start with customer_ or vendor_ for picker selection
[
[ LxERP.t8("Hard linking"), [
[ LxERP.t8("Linking"), [
{id => "link_sales_quotation", name => LxERP.t8("Link to sales quotation")},
{id => "link_sales_order_intake", name => LxERP.t8("Link to sales order intake")},
{id => "link_sales_order", name => LxERP.t8("Link to sales order")},
templates/design40_webpages/order/form.html
<div class="wrapper" id="email_attachment_wrapper">
[% P.email_journal.attachment_preview(
SELF.email_attachment_id,
style="border:1px solid black;margin:9px"
style="height: 1800px"
);
%]
</div><!-- /.wrapper -->
templates/design40_webpages/order/tabs/basic_data.html
BLOCK panel_1;
P.email_journal.attachment_preview(
SELF.email_attachment_id,
style="width:520px;border:1px solid black;margin:9px"
style="height:600px"
);
END;
INCLUDE 'common/toggle_panel.html'
templates/webpages/email_journal/show.html
[% L.select_tag('record_action',
# id has to start with customer_ or vendor_ for picker selection
[
[ LxERP.t8("Hard linking"), [
[ LxERP.t8("Linking"), [
{id => "link_sales_quotation", name => LxERP.t8("Link to sales quotation")},
{id => "link_sales_order_intake", name => LxERP.t8("Link to sales order intake")},
{id => "link_sales_order", name => LxERP.t8("Link to sales order")},
templates/webpages/order/form.html
<div class="tabwidget" id="order_tabs">
<ul>
<li><a href="#ui-tabs-basic-data">[% 'Basic Data' | $T8 %]</a></li>
[% IF SELF.email_attachment_id %]
<li><a href="#ui-tabs-email-attachment-preview">[% 'Email Attachment Preview' | $T8 %]</a></li>
[% END %]
[%- IF INSTANCE_CONF.get_webdav %]
<li><a href="#ui-tabs-webdav">[% 'WebDAV' | $T8 %]</a></li>
[%- END %]
......
cvars=SELF.order.custom_shipto.cvars_by_config
id_selector='#order_shipto_id' %]
</div>
[% IF SELF.email_attachment_id %]
<div id="ui-tabs-email-attachment-preview">
<div class="wrapper" id="email_attachment_wrapper">
[% P.email_journal.attachment_preview(
SELF.email_attachment_id,
style="height: 1800px"
);
%]
</div><!-- /.wrapper -->
</div><!-- /#ui-tabs-attachment-preview -->
[% END %]
</div>
</form>

Auch abrufbar als: Unified diff