From: Sven Schöling Date: Wed, 14 Dec 2011 15:19:15 +0000 (+0100) Subject: SL::Controller::Base wrapper für ReportGenerator X-Git-Tag: release-2.7.0beta1~128 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1320854c647c77be5befbc2c07332df92afdf4ea;p=kivitendo-erp.git SL::Controller::Base wrapper für ReportGenerator --- diff --git a/SL/Controller/Helper/ReportGenerator.pm b/SL/Controller/Helper/ReportGenerator.pm new file mode 100644 index 000000000..345537529 --- /dev/null +++ b/SL/Controller/Helper/ReportGenerator.pm @@ -0,0 +1,101 @@ +#===================================================================== +# LX-Office ERP +# Copyright (C) 2004 +# Based on SQL-Ledger Version 2.1.9 +# Web http://www.lx-office.org +###################################################################### +# +# Mixin for controllers to use ReportGenerator things +# +###################################################################### + +use strict; + +use List::Util qw(max); + +use SL::Form; +use SL::Common; +use SL::MoreCommon; +use SL::ReportGenerator; + +use Exporter 'import'; +our @EXPORT = qw( + action_report_generator_export_as_pdf action_report_generator_export_as_csv + action_report_generator_back report_generator_do +); + +sub action_report_generator_export_as_pdf { + my ($self) = @_; + if ($::form->{report_generator_pdf_options_set}) { + my $saved_form = save_form(); + + $self->report_generator_do('PDF'); + + if ($::form->{report_generator_printed}) { + restore_form($saved_form); + $::form->{MESSAGE} = $::locale->text('The list has been printed.'); + $self->report_generator_do('HTML'); + } + + return; + } + + my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form }); + + $::form->get_lists('printers' => 'ALL_PRINTERS'); + map { $_->{selected} = $::myconfig{default_printer_id} == $_->{id} } @{ $::form->{ALL_PRINTERS} }; + + $::form->{copies} = max $::myconfig{copies} * 1, 1; + $::form->{title} = $::locale->text('PDF export -- options'); + $::form->header; + print $::form->parse_html_template('report_generator/pdf_export_options', { + 'HIDDEN' => \@form_values, + 'ALLOW_FONT_SELECTION' => SL::ReportGenerator->check_for_pdf_api, }); +} + +sub action_report_generator_export_as_csv { + my ($self) = @_; + if ($::form->{report_generator_csv_options_set}) { + $self->report_generator_do('CSV'); + return; + } + + my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form }); + + $::form->{title} = $::locale->text('CSV export -- options'); + $::form->header; + print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values }); +} + +sub action_report_generator_back { + $_[0]->report_generator_do('HTML'); +} + +sub report_generator_set_default_sort { + my ($default_sortorder, $default_sortdir) = @_; + + $::form->{sort} ||= $default_sortorder; + $::form->{sortdir} = $default_sortdir unless (defined $::form->{sortdir}); + $::form->{sortdir} = $::form->{sortdir} ? 1 : 0; +} + +sub report_generator_do { + my ($self, $format) = @_; + + my $nextsub = $::form->{report_generator_nextsub}; + if (!$nextsub) { + $::form->error($::locale->text('report_generator_nextsub is not defined.')); + } + + foreach my $key (split m/ +/, $::form->{report_generator_variable_list}) { + $::form->{$key} = $::form->{"report_generator_hidden_${key}"}; + } + + $::form->{report_generator_output_format} = $format; + + delete @{$::form}{map { "report_generator_$_" } qw(nextsub variable_list)}; + + $self->_run_action($nextsub); +} + +1; diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 6b9990180..f81435e71 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -23,6 +23,7 @@ sub new { $self->{options} = { 'std_column_visibility' => 0, 'output_format' => 'HTML', + 'controller_class ' => '', 'allow_pdf_export' => 1, 'allow_csv_export' => 1, 'html_template' => 'report_generator/html_report', @@ -389,6 +390,7 @@ sub prepare_html_content { 'EXPORT_VARIABLE_LIST' => join(' ', @{ $self->{export}->{variable_list} }), 'EXPORT_NEXTSUB' => $self->{export}->{nextsub}, 'DATA_PRESENT' => $self->{data_present}, + 'CONTROLLER_DISPATCH' => $opts->{controller_class}, }; return $variables; @@ -768,6 +770,10 @@ sub _generate_csv_content { } } +sub check_for_pdf_api { + return eval { require PDF::API2; 1; } ? 1 : 0; +} + 1; __END__ @@ -921,6 +927,12 @@ Used to determine if a button for CSV export should be displayed. Default is yes The template to be used for HTML reports. Default is 'report_generator/html_report'. +=item controller_class + +If this is used from a C based controller class, pass the +class name here and make sure C is +used in the controller. That way the exports stay functional. + =back =head2 PDF Options diff --git a/templates/webpages/report_generator/csv_export_options.html b/templates/webpages/report_generator/csv_export_options.html index 0af556014..996adfc0d 100644 --- a/templates/webpages/report_generator/csv_export_options.html +++ b/templates/webpages/report_generator/csv_export_options.html @@ -1,16 +1,6 @@ [%- USE T8 %] [% USE HTML %] - -
[% HTML.escape(title) %]
@@ -21,7 +11,6 @@ - @@ -77,10 +66,27 @@
+[%- IF CONTROLLER_DISPATCH %] +

+ + + + +

+[%- ELSE %]

+

+ +[%- END %] +
diff --git a/templates/webpages/report_generator/html_report.html b/templates/webpages/report_generator/html_report.html index 32c2bd5d8..8b2d25330 100644 --- a/templates/webpages/report_generator/html_report.html +++ b/templates/webpages/report_generator/html_report.html @@ -1,16 +1,6 @@ [%- USE T8 %] [% USE HTML %] - -