From 6b22268c1277884455b820d2d8b50dab62af66f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 9 Oct 2019 11:06:19 +0200 Subject: [PATCH] Auftrags-Controller: PDF-Download per ajax-send_file --- SL/Controller/Order.pm | 39 +++++++++------------------------------ js/kivi.Order.js | 8 -------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 771b1606d..9b4f42f6d 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -242,11 +242,8 @@ sub action_save_as_new { # print the order # # This is called if "print" is pressed in the print dialog. -# If PDF creation was requested and succeeded, the pdf is stored in a session -# file and the filename is stored as session value with an unique key. A -# javascript function with this key is then called. This function calls the -# download action below (action_download_pdf), which offers the file for -# download. +# If PDF creation was requested and succeeded, the pdf is offered for download +# via send_file (which uses ajax in this case). sub action_print { my ($self) = @_; @@ -298,16 +295,13 @@ sub action_print { if ($media eq 'screen') { # screen/download - my $sfile = SL::SessionFile::Random->new(mode => "w"); - $sfile->fh->print($pdf); - $sfile->fh->close; - - my $key = join('_', Time::HiRes::gettimeofday(), int rand 1000000000000); - $::auth->set_session_value("Order::print-${key}" => $sfile->file_name); - - $self->js - ->run('kivi.Order.download_pdf', $pdf_filename, $key) - ->flash('info', t8('The PDF has been created')); + $self->js->flash('info', t8('The PDF has been created')); + $self->send_file( + \$pdf, + type => SL::MIME->mime_type_from_ext($pdf_filename), + name => $pdf_filename, + js_no_render => 1, + ); } elsif ($media eq 'printer') { # printer @@ -354,21 +348,6 @@ sub action_print { $self->js->render; } -# offer pdf for download -# -# It needs to get the key for the session value to get the pdf file. -sub action_download_pdf { - my ($self) = @_; - - my $key = $::form->{key}; - my $tmp_filename = $::auth->get_session_value("Order::print-${key}"); - return $self->send_file( - $tmp_filename, - type => SL::MIME->mime_type_from_ext($::form->{pdf_filename}), - name => $::form->{pdf_filename}, - ); -} - # open the email dialog sub action_show_email_dialog { my ($self) = @_; diff --git a/js/kivi.Order.js b/js/kivi.Order.js index 3421f9ff6..e77b63e15 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -87,14 +87,6 @@ namespace('kivi.Order', function(ns) { $.post("controller.pl", data, kivi.eval_json_result); }; - ns.download_pdf = function(pdf_filename, key) { - var data = [{ name: 'action', value: 'Order/download_pdf' }, - { name: 'type', value: $('#type').val() }, - { name: 'pdf_filename', value: pdf_filename }, - { name: 'key', value: key }]; - $.download("controller.pl", data); - }; - ns.email = function(warn_on_duplicates) { if (warn_on_duplicates && !ns.check_duplicate_parts(kivi.t8("Do you really want to send by mail?"))) return; if (!ns.check_cv()) return; -- 2.20.1