From: Moritz Bunkus
Date: Fri, 11 Nov 2016 10:46:09 +0000 (+0100)
Subject: ActionBar: Unterstützung in ReportGenerator
X-Git-Tag: release-3.5.4~1354
X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=40e0911a4ec0bbae2036839e0d9a954ea5c76d07;p=kivitendo-erp.git
ActionBar: Unterstützung in ReportGenerator
---
diff --git a/SL/Controller/Helper/ReportGenerator.pm b/SL/Controller/Helper/ReportGenerator.pm
index e84f9ca2c..20ab8c3b4 100644
--- a/SL/Controller/Helper/ReportGenerator.pm
+++ b/SL/Controller/Helper/ReportGenerator.pm
@@ -16,6 +16,24 @@ our @EXPORT = qw(
report_generator_list_objects
);
+sub _setup_action_bar {
+ my ($self, $type) = @_;
+
+ my $key = $::form->{CONTROLLER_DISPATCH} ? 'action' : 'report_generator_form.report_generator_dispatch_to';
+ my $value = $::form->{CONTROLLER_DISPATCH} ? $::form->{CONTROLLER_DISPATCH} . "/" : '';
+
+ $::request->layout->get('actionbar')->add(
+ action => [
+ $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
+ submit => [ '#report_generator_form', { $key => "${value}report_generator_export_as_${type}" } ],
+ ],
+ action => [
+ $::locale->text('Back'),
+ submit => [ '#report_generator_form', { $key => "${value}report_generator_back" } ],
+ ],
+ );
+}
+
sub action_report_generator_export_as_pdf {
my ($self) = @_;
@@ -42,6 +60,9 @@ sub action_report_generator_export_as_pdf {
$::form->{copies} = max $::myconfig{copies} * 1, 1;
$::form->{title} = $::locale->text('PDF export -- options');
+
+ _setup_action_bar($self, 'pdf'); # Sub not exported, therefore don't call via object.
+
$::form->header;
print $::form->parse_html_template('report_generator/pdf_export_options', {
'HIDDEN' => \@form_values,
@@ -61,6 +82,9 @@ sub action_report_generator_export_as_csv {
my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
$::form->{title} = $::locale->text('CSV export -- options');
+
+ _setup_action_bar($self, 'csv'); # Sub not exported, therefore don't call via object.
+
$::form->header;
print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
}
@@ -116,10 +140,13 @@ sub report_generator_list_objects {
$params{report}->add_data(\%data);
}
+ my %options = %{ $params{options} || {} };
+ $options{action_bar} //= $params{action_bar};
+
if ($params{layout}) {
- return $params{report}->generate_with_headers(%{ $params{options} || {}});
+ return $params{report}->generate_with_headers(%options);
} else {
- my $html = $params{report}->generate_html_content(%{ $params{options} || {}});
+ my $html = $params{report}->generate_html_content(%options);
$self->render(\$html , { layout => 0, process => 0 });
}
}
@@ -235,6 +262,15 @@ L.
An optional hash reference that's passed verbatim to the function
L.
+=item C
+
+If the buttons for exporting PDF and/or CSV variants are included in
+the action bar. Otherwise they're rendered at the bottom of the page.
+
+The value can be either a specific action bar instance or simply 1 in
+which case the default action bar is used:
+C<$::request-Elayout-Eget('actionbar')>.
+
=back
=back
diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm
index 0a61195c9..36a81f35b 100644
--- a/SL/ReportGenerator.pm
+++ b/SL/ReportGenerator.pm
@@ -2,6 +2,7 @@ package SL::ReportGenerator;
use Data::Dumper;
use List::Util qw(max);
+use Scalar::Util qw(blessed);
use Text::CSV_XS;
#use PDF::API2; # these two eat up to .75s on startup. only load them if we actually need them
#use PDF::Table;
@@ -232,12 +233,13 @@ sub generate_with_headers {
}
if ($format eq 'html') {
+ my $content = $self->generate_html_content(%params);
my $title = $form->{title};
$form->{title} = $self->{title} if ($self->{title});
$form->header(no_layout => $params{no_layout});
$form->{title} = $title;
- print $self->generate_html_content();
+ print $content;
} elsif ($format eq 'csv') {
# FIXME: don't do mini http in here
@@ -275,7 +277,7 @@ sub html_format {
}
sub prepare_html_content {
- my $self = shift;
+ my ($self, %params) = @_;
my ($column, $name, @column_headers);
@@ -407,14 +409,47 @@ sub prepare_html_content {
'DATA_PRESENT' => $self->{data_present},
'CONTROLLER_DISPATCH' => $opts->{controller_class},
'TABLE_CLASS' => $opts->{table_class},
+ 'SKIP_BUTTONS' => !!$params{action_bar},
};
return $variables;
}
+sub setup_action_bar {
+ my ($self, $action_bar, $variables) = @_;
+
+ my @actions;
+ foreach my $type (qw(pdf csv)) {
+ next unless $variables->{"ALLOW_" . uc($type) . "_EXPORT"};
+
+ my $key = $variables->{CONTROLLER_DISPATCH} ? 'action' : 'report_generator_dispatch_to';
+ my $value = "report_generator_export_as_${type}";
+ $value = $variables->{CONTROLLER_DISPATCH} . "/${value}" if $variables->{CONTROLLER_DISPATCH};
+
+ push @actions, action => [
+ $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
+ submit => [ '#report_generator_form', { $key => $value } ],
+ ];
+ }
+
+ if (scalar(@actions) > 1) {
+ @actions = (
+ combobox => [
+ action => [ $::locale->text('Export') ],
+ @actions,
+ ],
+ );
+ }
+
+ $action_bar = ($::request->layout->get('actionbar'))[0] unless blessed($action_bar);
+ $action_bar->add(@actions) if @actions;
+}
+
sub generate_html_content {
- my $self = shift;
- my $variables = $self->prepare_html_content();
+ my ($self, %params) = @_;
+ my $variables = $self->prepare_html_content(%params);
+
+ $self->setup_action_bar($params{action_bar}, $variables) if $params{action_bar};
my $stuff = $self->{form}->parse_html_template($self->{options}->{html_template}, $variables);
return $stuff;
@@ -661,7 +696,7 @@ sub generate_pdf_content {
my $content = $pdf->stringify();
$main::lxdebug->message(LXDebug->DEBUG2(),"addattachments ?? =".$form->{report_generator_addattachments}." GL=".$form->{GL});
- if ( $form->{report_generator_addattachments} eq 'yes' && $form->{GL}) {
+ if ($form->{report_generator_addattachments} && $form->{GL}) {
$content = $self->append_gl_pdf_attachments($form,$content);
}
diff --git a/bin/mozilla/reportgenerator.pl b/bin/mozilla/reportgenerator.pl
index 2304e492d..5ba261f28 100644
--- a/bin/mozilla/reportgenerator.pl
+++ b/bin/mozilla/reportgenerator.pl
@@ -34,6 +34,28 @@ sub report_generator_set_default_sort {
}
+sub report_generator_setup_action_bar {
+ my ($type, %params) = @_;
+
+ $::request->layout->get('actionbar')->add(
+ combobox => [
+ action => [
+ $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
+ submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_export_as_${type}" } ],
+ ],
+ action => [
+ $::locale->text('PDF export with attachments'),
+ submit => [ '#report_generator_form', { report_generator_dispatch_to => "report_generator_export_as_pdf", report_generator_addattachments => 1 } ],
+ only_if => $params{allow_attachments},
+ ],
+ ],
+ action => [
+ $::locale->text('Back'),
+ submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_back" } ],
+ ],
+ );
+}
+
sub report_generator_export_as_pdf {
$main::lxdebug->enter_sub();
@@ -64,15 +86,15 @@ sub report_generator_export_as_pdf {
$form->{copies} = max $myconfig{copies} * 1, 1;
my $allow_font_selection = 1;
- my $allow_attachments = 0;
eval { require PDF::API2; };
$allow_font_selection = 0 if ($@);
- $allow_attachments = 1 if $form->{report_generator_hidden_l_attachments};
$form->{title} = $locale->text('PDF export -- options');
+
+ report_generator_setup_action_bar('pdf', allow_attachments => !!$form->{report_generator_hidden_l_attachments});
+
$form->header();
print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN' => \@form_values,
- 'ALLOW_ATTACHMENTS' => $allow_attachments,
'ALLOW_FONT_SELECTION' => $allow_font_selection, });
$main::lxdebug->leave_sub();
@@ -93,6 +115,9 @@ sub report_generator_export_as_csv {
my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
$form->{title} = $locale->text('CSV export -- options');
+
+ report_generator_setup_action_bar('csv');
+
$form->header();
print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
diff --git a/locale/de/all b/locale/de/all
index 30e63fc0c..f0785c86a 100755
--- a/locale/de/all
+++ b/locale/de/all
@@ -482,6 +482,7 @@ $self->{texts} = {
'CN' => 'Kd-Nr.',
'CR' => 'H',
'CSS style for pictures' => 'CSS Style für Bilder',
+ 'CSV export' => 'CSV-Export',
'CSV export -- options' => 'CSV-Export -- Optionen',
'CSV import: ar transactions' => 'CSV Import: Debitorenbuchungen',
'CSV import: bank transactions' => 'CSV Import: Bankbewegungen',
@@ -2030,7 +2031,9 @@ $self->{texts} = {
'PAYMENT POSTED' => 'Rechnung gebucht',
'PDF' => 'PDF',
'PDF (OpenDocument/OASIS)' => 'PDF (OpenDocument/OASIS)',
+ 'PDF export' => 'PDF-Export',
'PDF export -- options' => 'PDF-Export -- Optionen',
+ 'PDF export with attachments' => 'Als PDF mit Anhängen exportieren',
'PLZ Grosskunden' => 'PLZ Grosskunden',
'POSTED' => 'Gebucht',
'POSTED AS NEW' => 'Als neu gebucht',
diff --git a/templates/webpages/report_generator/csv_export_options.html b/templates/webpages/report_generator/csv_export_options.html
index 45a1fcea5..085715155 100644
--- a/templates/webpages/report_generator/csv_export_options.html
+++ b/templates/webpages/report_generator/csv_export_options.html
@@ -3,7 +3,7 @@
[% HTML.escape(title) %]
-
@@ -96,27 +100,32 @@
[% END %]
[% IF SHOW_EXPORT_BUTTONS %]
-
diff --git a/templates/webpages/report_generator/pdf_export_options.html b/templates/webpages/report_generator/pdf_export_options.html
index 5b2f68f3f..86594b5df 100644
--- a/templates/webpages/report_generator/pdf_export_options.html
+++ b/templates/webpages/report_generator/pdf_export_options.html
@@ -6,7 +6,7 @@
[% HTML.escape(title) %]
-