use Carp;
use List::Util qw(max);
+use Scalar::Util qw(blessed);
use SL::Common;
use SL::MoreCommon;
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} . "/" : '';
+
+ for my $bar ($::request->layout->get('actionbar')) {
+ $bar->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) = @_;
$::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,
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 });
}
my @columns = $params{report}->get_visible_columns('HTML');
for my $obj (@{ $params{objects} || [] }) {
- my %data = map {
- my $def = $column_defs->{$_};
- $_ => {
- raw_data => $def->{raw_data} ? $def->{raw_data}->($obj) : '',
- data => $def->{sub} ? $def->{sub}->($obj)
- : $obj->can($_) ? $obj->$_
- : $obj->{$_},
- link => $def->{obj_link} ? $def->{obj_link}->($obj) : '',
- },
- } @columns;
+ my %data;
+
+ if (blessed($obj) && $obj->isa('SL::Controller::Helper::ReportGenerator::ControlRow::Base')) {
+ $obj->set_data($params{report});
+ next;
+
+ } else {
+ %data = map {
+ my $def = $column_defs->{$_};
+ my $tmp;
+ $tmp->{raw_data} = $def->{raw_data} ? $def->{raw_data}->($obj) : '';
+ $tmp->{data} = $def->{sub} ? $def->{sub}->($obj)
+ : $obj->can($_) ? $obj->$_
+ : $obj->{$_};
+ $tmp->{link} = $def->{obj_link} ? $def->{obj_link}->($obj) : '';
+ $_ => $tmp;
+ } @columns;
+ }
$params{data_callback}->(\%data) if $params{data_callback};
$params{report}->add_data(\%data);
}
+ my %options = %{ $params{options} || {} };
+ $options{action_bar} //= $params{action_bar} // 1;
+
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(action_bar => 0, %options);
$self->render(\$html , { layout => 0, process => 0 });
}
}
Mandatory. An array reference of RDBO models to output.
+An element of the array can also be an instance of a control row, i.e.
+an instance of a class derived from
+C<SL::Controller::Helper::ReportGenerator::ControlRow::Base>.
+See also:
+
+L<SL::Controller::Helper::ReportGenerator::ControlRow>
+L<SL::Controller::Helper::ReportGenerator::ControlRow::*>
+
=item C<data_callback>
Optional. A callback handler (code reference) that gets called for
An optional hash reference that's passed verbatim to the function
L<SL::ReportGenerator/generate_with_headers>.
+=item C<action_bar>
+
+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-E<gt>layout-E<gt>get('actionbar')>.
+
=back
=back