Revision bd727c21
Von Tamino Steinert vor 11 Monaten hinzugefügt
SL/Controller/EmailJournal.pm | ||
---|---|---|
87 | 87 |
back_to => $back_to); |
88 | 88 |
} |
89 | 89 |
|
90 |
sub action_show_attachment { |
|
91 |
my ($self) = @_; |
|
92 |
|
|
93 |
$::auth->assert('email_journal'); |
|
94 |
|
|
95 |
my $attachment_id = $::form->{attachment_id}; |
|
96 |
my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load; |
|
97 |
|
|
98 |
return $self->send_file( |
|
99 |
\$attachment->content, |
|
100 |
name => $attachment->name, |
|
101 |
type => $attachment->mime_type, |
|
102 |
content_disposition => 'inline', |
|
103 |
); |
|
104 |
} |
|
105 |
|
|
90 | 106 |
sub action_download_attachment { |
91 | 107 |
my ($self) = @_; |
92 | 108 |
|
... | ... | |
164 | 180 |
->replaceWith('#attachment_preview', |
165 | 181 |
SL::Presenter::EmailJournal::attachment_preview( |
166 | 182 |
$attachment, |
167 |
style => "width:655px;border:1px solid black;margin:9px"
|
|
183 |
style => "height:1800px"
|
|
168 | 184 |
) |
169 | 185 |
) |
170 | 186 |
->render(); |
SL/Presenter/EmailJournal.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
|
5 | 5 |
use SL::Presenter::EscapedText qw(escape is_escaped); |
6 |
use SL::Presenter::Tag qw(link_tag img_tag html_tag);
|
|
6 |
use SL::Presenter::Tag qw(link_tag html_tag div_tag);
|
|
7 | 7 |
use SL::Locale::String qw(t8); |
8 | 8 |
use SL::SessionFile::Random; |
9 | 9 |
use SL::DB::EmailJournalAttachment; |
... | ... | |
50 | 50 |
my ($attachment_or_id, %params) = @_; |
51 | 51 |
|
52 | 52 |
if (! $attachment_or_id) { |
53 |
return is_escaped(html_tag('div', '', id => 'attachment_preview')); |
|
54 |
} |
|
55 |
my $attachment = ref $attachment_or_id ? $attachment_or_id |
|
56 |
: SL::DB::EmailJournalAttachment->new(id => $attachment_or_id)->load; |
|
57 |
|
|
58 |
# clean up mime_type |
|
59 |
my $mime_type = $attachment->mime_type; |
|
60 |
$mime_type =~ s/;.*//; |
|
61 |
|
|
62 |
# parse to img tag |
|
63 |
my $image_tags = ''; |
|
64 |
if ($mime_type =~ m{^image/}) { |
|
65 |
my $image_content = $attachment->content; |
|
66 |
my $img_base64 = "data:$mime_type;base64," . MIME::Base64::encode_base64($image_content); |
|
67 |
my $image_tag = img_tag( |
|
68 |
src => $img_base64, |
|
69 |
alt => escape($attachment->name), |
|
70 |
%params); |
|
71 |
$image_tags .= $image_tag; |
|
72 |
} elsif ($mime_type =~ m{^application/pdf}) { |
|
73 |
my $pdf_content = $attachment->content; |
|
74 |
my $session_file = SL::SessionFile::Random->new(mode => 'w'); |
|
75 |
$session_file->fh->print($pdf_content); |
|
76 |
$session_file->fh->close; |
|
77 |
my $image_size = 2048; |
|
78 |
|
|
79 |
my $file_name = $session_file->file_name; |
|
80 |
|
|
81 |
# files are created in session_files folder |
|
82 |
my $command = 'pdftoppm -forcenum -scale-to ' |
|
83 |
. $image_size . ' -png' . ' ' |
|
84 |
. $file_name . ' ' . $file_name; |
|
85 |
my $ans = system($command); |
|
86 |
if ($ans != 0) { |
|
87 |
return; |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
my @image_file_names = glob($file_name . '-*.png'); |
|
92 |
unlink($file_name); |
|
93 |
|
|
94 |
my $image_count = scalar @image_file_names; |
|
95 |
my $counter = 1; |
|
96 |
foreach my $image_file_name (@image_file_names) { |
|
97 |
my $image_file = SL::SessionFile->new($image_file_name, mode => 'r'); |
|
98 |
my $file_size = -s $image_file->file_name; |
|
99 |
my $image_content; |
|
100 |
read($image_file->fh, $image_content, $file_size); |
|
101 |
my $img_base64 = 'data:image/png;base64,' . MIME::Base64::encode_base64($image_content); |
|
102 |
my $name_ending = $image_count > 1 ? "-($counter/$image_count)" : ''; |
|
103 |
my $image_tag = img_tag( |
|
104 |
src => $img_base64, |
|
105 |
alt => escape($attachment->name) . $name_ending, |
|
106 |
%params); |
|
107 |
unlink($image_file->file_name); |
|
108 |
$image_tags .= $image_tag; |
|
109 |
} |
|
53 |
return is_escaped(div_tag('', id => 'attachment_preview')); |
|
110 | 54 |
} |
55 |
my $attachment_id = ref $attachment_or_id ? $attachment_or_id->id |
|
56 |
: $attachment_or_id; |
|
111 | 57 |
|
112 |
my $attachment_preview = html_tag('div', $image_tags, id => 'attachment_preview'); |
|
58 |
require SL::Controller::EmailJournal; |
|
59 |
my $src_url = SL::Controller::EmailJournal->new->url_for( |
|
60 |
action => 'show_attachment', |
|
61 |
attachment_id => $attachment_id |
|
62 |
); |
|
113 | 63 |
|
64 |
$params{style} .= "; display:flex; resize:both; overflow:hidden; padding-bottom:5px"; |
|
65 |
my $attachment_preview = div_tag( |
|
66 |
html_tag('iframe', '', src => $src_url, |
|
67 |
width => "100%", height => '100%', |
|
68 |
"flex-grow" => '1', |
|
69 |
), |
|
70 |
id => 'attachment_preview', |
|
71 |
%params |
|
72 |
); |
|
114 | 73 |
return is_escaped($attachment_preview); |
115 | 74 |
} |
116 | 75 |
|
templates/design40_webpages/email_journal/show.html | ||
---|---|---|
75 | 75 |
|
76 | 76 |
[% SET attachments = SELF.entry.attachments_sorted %] |
77 | 77 |
|
78 |
<div class="input-panel" style="vertical-align:top;" id="wrapper-2"> |
|
78 |
<div class="wrapper input-panel" style="vertical-align:top;" id="wrapper-2">
|
|
79 | 79 |
|
80 | 80 |
[% IF attachments.size %] |
81 | 81 |
<table id="email_journal_details" class="tbl-list"> |
... | ... | |
120 | 120 |
[% L.select_tag('record_action', |
121 | 121 |
# id has to start with customer_ or vendor_ for picker selection |
122 | 122 |
[ |
123 |
[ LxERP.t8("Hard linking"), [
|
|
123 |
[ LxERP.t8("Linking"), [
|
|
124 | 124 |
{id => "link_sales_quotation", name => LxERP.t8("Link to sales quotation")}, |
125 | 125 |
{id => "link_sales_order_intake", name => LxERP.t8("Link to sales order intake")}, |
126 | 126 |
{id => "link_sales_order", name => LxERP.t8("Link to sales order")}, |
templates/design40_webpages/order/form.html | ||
---|---|---|
75 | 75 |
<div class="wrapper" id="email_attachment_wrapper"> |
76 | 76 |
[% P.email_journal.attachment_preview( |
77 | 77 |
SELF.email_attachment_id, |
78 |
style="border:1px solid black;margin:9px"
|
|
78 |
style="height: 1800px"
|
|
79 | 79 |
); |
80 | 80 |
%] |
81 | 81 |
</div><!-- /.wrapper --> |
templates/design40_webpages/order/tabs/basic_data.html | ||
---|---|---|
15 | 15 |
BLOCK panel_1; |
16 | 16 |
P.email_journal.attachment_preview( |
17 | 17 |
SELF.email_attachment_id, |
18 |
style="width:520px;border:1px solid black;margin:9px"
|
|
18 |
style="height:600px"
|
|
19 | 19 |
); |
20 | 20 |
END; |
21 | 21 |
INCLUDE 'common/toggle_panel.html' |
templates/webpages/email_journal/show.html | ||
---|---|---|
100 | 100 |
[% L.select_tag('record_action', |
101 | 101 |
# id has to start with customer_ or vendor_ for picker selection |
102 | 102 |
[ |
103 |
[ LxERP.t8("Hard linking"), [
|
|
103 |
[ LxERP.t8("Linking"), [
|
|
104 | 104 |
{id => "link_sales_quotation", name => LxERP.t8("Link to sales quotation")}, |
105 | 105 |
{id => "link_sales_order_intake", name => LxERP.t8("Link to sales order intake")}, |
106 | 106 |
{id => "link_sales_order", name => LxERP.t8("Link to sales order")}, |
templates/webpages/order/form.html | ||
---|---|---|
34 | 34 |
<div class="tabwidget" id="order_tabs"> |
35 | 35 |
<ul> |
36 | 36 |
<li><a href="#ui-tabs-basic-data">[% 'Basic Data' | $T8 %]</a></li> |
37 |
[% IF SELF.email_attachment_id %] |
|
38 |
<li><a href="#ui-tabs-email-attachment-preview">[% 'Email Attachment Preview' | $T8 %]</a></li> |
|
39 |
[% END %] |
|
37 | 40 |
[%- IF INSTANCE_CONF.get_webdav %] |
38 | 41 |
<li><a href="#ui-tabs-webdav">[% 'WebDAV' | $T8 %]</a></li> |
39 | 42 |
[%- END %] |
... | ... | |
66 | 69 |
cvars=SELF.order.custom_shipto.cvars_by_config |
67 | 70 |
id_selector='#order_shipto_id' %] |
68 | 71 |
</div> |
72 |
[% IF SELF.email_attachment_id %] |
|
73 |
<div id="ui-tabs-email-attachment-preview"> |
|
74 |
<div class="wrapper" id="email_attachment_wrapper"> |
|
75 |
[% P.email_journal.attachment_preview( |
|
76 |
SELF.email_attachment_id, |
|
77 |
style="height: 1800px" |
|
78 |
); |
|
79 |
%] |
|
80 |
</div><!-- /.wrapper --> |
|
81 |
</div><!-- /#ui-tabs-attachment-preview --> |
|
82 |
[% END %] |
|
69 | 83 |
|
70 | 84 |
</div> |
71 | 85 |
</form> |
Auch abrufbar als: Unified diff
EmailJournal: Anhangsvorschau mit kopierbaren Text