Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 40e0911a

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 40e0911a4ec0bbae2036839e0d9a954ea5c76d07
  • Vorgänger 965a8ee1
  • Nachfolger dcef8eb0

ActionBar: Unterstützung in ReportGenerator

Unterschiede anzeigen:

SL/Controller/Helper/ReportGenerator.pm
16 16
  report_generator_list_objects
17 17
);
18 18

  
19
sub _setup_action_bar {
20
  my ($self, $type) = @_;
21

  
22
  my $key   = $::form->{CONTROLLER_DISPATCH} ? 'action'                             : 'report_generator_form.report_generator_dispatch_to';
23
  my $value = $::form->{CONTROLLER_DISPATCH} ? $::form->{CONTROLLER_DISPATCH} . "/" : '';
24

  
25
  $::request->layout->get('actionbar')->add(
26
    action => [
27
      $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
28
      submit => [ '#report_generator_form', { $key => "${value}report_generator_export_as_${type}" } ],
29
    ],
30
    action => [
31
      $::locale->text('Back'),
32
      submit => [ '#report_generator_form', { $key => "${value}report_generator_back" } ],
33
    ],
34
  );
35
}
36

  
19 37
sub action_report_generator_export_as_pdf {
20 38
  my ($self) = @_;
21 39

  
......
42 60

  
43 61
  $::form->{copies} = max $::myconfig{copies} * 1, 1;
44 62
  $::form->{title} = $::locale->text('PDF export -- options');
63

  
64
  _setup_action_bar($self, 'pdf'); # Sub not exported, therefore don't call via object.
65

  
45 66
  $::form->header;
46 67
  print $::form->parse_html_template('report_generator/pdf_export_options', {
47 68
    'HIDDEN'               => \@form_values,
......
61 82
  my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
62 83

  
63 84
  $::form->{title} = $::locale->text('CSV export -- options');
85

  
86
  _setup_action_bar($self, 'csv'); # Sub not exported, therefore don't call via object.
87

  
64 88
  $::form->header;
65 89
  print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
66 90
}
......
116 140
    $params{report}->add_data(\%data);
117 141
  }
118 142

  
143
  my %options            = %{ $params{options} || {} };
144
  $options{action_bar} //= $params{action_bar};
145

  
119 146
  if ($params{layout}) {
120
    return $params{report}->generate_with_headers(%{ $params{options} || {}});
147
    return $params{report}->generate_with_headers(%options);
121 148
  } else {
122
    my $html = $params{report}->generate_html_content(%{ $params{options} || {}});
149
    my $html = $params{report}->generate_html_content(%options);
123 150
    $self->render(\$html , { layout => 0, process => 0 });
124 151
  }
125 152
}
......
235 262
An optional hash reference that's passed verbatim to the function
236 263
L<SL::ReportGenerator/generate_with_headers>.
237 264

  
265
=item C<action_bar>
266

  
267
If the buttons for exporting PDF and/or CSV variants are included in
268
the action bar. Otherwise they're rendered at the bottom of the page.
269

  
270
The value can be either a specific action bar instance or simply 1 in
271
which case the default action bar is used:
272
C<$::request-E<gt>layout-E<gt>get('actionbar')>.
273

  
238 274
=back
239 275

  
240 276
=back
SL/ReportGenerator.pm
2 2

  
3 3
use Data::Dumper;
4 4
use List::Util qw(max);
5
use Scalar::Util qw(blessed);
5 6
use Text::CSV_XS;
6 7
#use PDF::API2;    # these two eat up to .75s on startup. only load them if we actually need them
7 8
#use PDF::Table;
......
232 233
  }
233 234

  
234 235
  if ($format eq 'html') {
236
    my $content    = $self->generate_html_content(%params);
235 237
    my $title      = $form->{title};
236 238
    $form->{title} = $self->{title} if ($self->{title});
237 239
    $form->header(no_layout => $params{no_layout});
238 240
    $form->{title} = $title;
239 241

  
240
    print $self->generate_html_content();
242
    print $content;
241 243

  
242 244
  } elsif ($format eq 'csv') {
243 245
    # FIXME: don't do mini http in here
......
275 277
}
276 278

  
277 279
sub prepare_html_content {
278
  my $self = shift;
280
  my ($self, %params) = @_;
279 281

  
280 282
  my ($column, $name, @column_headers);
281 283

  
......
407 409
    'DATA_PRESENT'         => $self->{data_present},
408 410
    'CONTROLLER_DISPATCH'  => $opts->{controller_class},
409 411
    'TABLE_CLASS'          => $opts->{table_class},
412
    'SKIP_BUTTONS'         => !!$params{action_bar},
410 413
  };
411 414

  
412 415
  return $variables;
413 416
}
414 417

  
418
sub setup_action_bar {
419
  my ($self, $action_bar, $variables) = @_;
420

  
421
  my @actions;
422
  foreach my $type (qw(pdf csv)) {
423
    next unless $variables->{"ALLOW_" . uc($type) . "_EXPORT"};
424

  
425
    my $key   = $variables->{CONTROLLER_DISPATCH} ? 'action' : 'report_generator_dispatch_to';
426
    my $value = "report_generator_export_as_${type}";
427
    $value    = $variables->{CONTROLLER_DISPATCH} . "/${value}" if $variables->{CONTROLLER_DISPATCH};
428

  
429
    push @actions, action => [
430
      $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
431
      submit => [ '#report_generator_form', { $key => $value } ],
432
    ];
433
  }
434

  
435
  if (scalar(@actions) > 1) {
436
    @actions = (
437
      combobox => [
438
        action => [ $::locale->text('Export') ],
439
        @actions,
440
      ],
441
    );
442
  }
443

  
444
  $action_bar = ($::request->layout->get('actionbar'))[0] unless blessed($action_bar);
445
  $action_bar->add(@actions) if @actions;
446
}
447

  
415 448
sub generate_html_content {
416
  my $self      = shift;
417
  my $variables = $self->prepare_html_content();
449
  my ($self, %params) = @_;
450
  my $variables = $self->prepare_html_content(%params);
451

  
452
  $self->setup_action_bar($params{action_bar}, $variables) if $params{action_bar};
418 453

  
419 454
  my $stuff  = $self->{form}->parse_html_template($self->{options}->{html_template}, $variables);
420 455
  return $stuff;
......
661 696
  my $content = $pdf->stringify();
662 697

  
663 698
  $main::lxdebug->message(LXDebug->DEBUG2(),"addattachments ?? =".$form->{report_generator_addattachments}." GL=".$form->{GL});
664
  if ( $form->{report_generator_addattachments} eq 'yes' && $form->{GL}) {
699
  if ($form->{report_generator_addattachments} && $form->{GL}) {
665 700
    $content = $self->append_gl_pdf_attachments($form,$content);
666 701
  }
667 702

  
bin/mozilla/reportgenerator.pl
34 34
}
35 35

  
36 36

  
37
sub report_generator_setup_action_bar {
38
  my ($type, %params) = @_;
39

  
40
  $::request->layout->get('actionbar')->add(
41
    combobox => [
42
      action => [
43
        $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
44
        submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_export_as_${type}" } ],
45
      ],
46
      action => [
47
        $::locale->text('PDF export with attachments'),
48
        submit  => [ '#report_generator_form', { report_generator_dispatch_to => "report_generator_export_as_pdf", report_generator_addattachments => 1 } ],
49
        only_if => $params{allow_attachments},
50
      ],
51
    ],
52
    action => [
53
      $::locale->text('Back'),
54
      submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_back" } ],
55
    ],
56
  );
57
}
58

  
37 59
sub report_generator_export_as_pdf {
38 60
  $main::lxdebug->enter_sub();
39 61

  
......
64 86
  $form->{copies} = max $myconfig{copies} * 1, 1;
65 87

  
66 88
  my $allow_font_selection = 1;
67
  my $allow_attachments    = 0;
68 89
  eval { require PDF::API2; };
69 90
  $allow_font_selection = 0 if ($@);
70
  $allow_attachments    = 1 if $form->{report_generator_hidden_l_attachments};
71 91

  
72 92
  $form->{title} = $locale->text('PDF export -- options');
93

  
94
  report_generator_setup_action_bar('pdf', allow_attachments => !!$form->{report_generator_hidden_l_attachments});
95

  
73 96
  $form->header();
74 97
  print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN'               => \@form_values,
75
                                                                            'ALLOW_ATTACHMENTS'    => $allow_attachments,
76 98
                                                                            'ALLOW_FONT_SELECTION' => $allow_font_selection, });
77 99

  
78 100
  $main::lxdebug->leave_sub();
......
93 115
  my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
94 116

  
95 117
  $form->{title} = $locale->text('CSV export -- options');
118

  
119
  report_generator_setup_action_bar('csv');
120

  
96 121
  $form->header();
97 122
  print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
98 123

  
locale/de/all
482 482
  'CN'                          => 'Kd-Nr.',
483 483
  'CR'                          => 'H',
484 484
  'CSS style for pictures'      => 'CSS Style für Bilder',
485
  'CSV export'                  => 'CSV-Export',
485 486
  'CSV export -- options'       => 'CSV-Export -- Optionen',
486 487
  'CSV import: ar transactions' => 'CSV Import: Debitorenbuchungen',
487 488
  'CSV import: bank transactions' => 'CSV Import: Bankbewegungen',
......
2030 2031
  'PAYMENT POSTED'              => 'Rechnung gebucht',
2031 2032
  'PDF'                         => 'PDF',
2032 2033
  'PDF (OpenDocument/OASIS)'    => 'PDF (OpenDocument/OASIS)',
2034
  'PDF export'                  => 'PDF-Export',
2033 2035
  'PDF export -- options'       => 'PDF-Export -- Optionen',
2036
  'PDF export with attachments' => 'Als PDF mit Anhängen exportieren',
2034 2037
  'PLZ Grosskunden'             => 'PLZ Grosskunden',
2035 2038
  'POSTED'                      => 'Gebucht',
2036 2039
  'POSTED AS NEW'               => 'Als neu gebucht',
templates/webpages/report_generator/csv_export_options.html
3 3

  
4 4
 <h1>[% HTML.escape(title) %]</h1>
5 5

  
6
 <form action="[% HTML.escape(script) %]" method="post" name="report_generator_form">
6
 <form action="[% HTML.escape(script) %]" method="post" name="report_generator_form" id="report_generator_form">
7 7

  
8 8
  [%- FOREACH var = HIDDEN %]
9 9
  <input type="hidden" name="[% HTML.escape(var.key) %]" value="[% HTML.escape(var.value) %]">
......
69 69
  </table>
70 70

  
71 71
[%- IF CONTROLLER_DISPATCH %]
72
   <p>
73
    <input type="hidden" name="action" value="[% CONTROLLER_DISPATCH | html %]/dispatch">
74
    <input type="submit" name="action_report_generator_export_as_csv" value="[% 'Export as CSV' | $T8 %]">
75
    <input type="submit" name="action_report_generator_back" value="[% 'Back' | $T8 %]">
76 72
    <input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]">
77
   </p>
78 73
[%- ELSE %]
79
  <p>
80 74
   <input type="hidden" name="action" value="report_generator_dispatcher">
81
   <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_csv')" value="[% 'Export as CSV' | $T8 %]">
82
   <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]">
83
  </p>
84
 <script type="text/javascript"><!--
85
      function submit_report_generator_form(nextsub) {
86
        document.report_generator_form.report_generator_dispatch_to.value = nextsub;
87
        document.report_generator_form.submit();
88
      } // -->
89
 </script>
90 75
[%- END %]
91 76

  
92 77

  
templates/webpages/report_generator/html_report.html
30 30
 [% IF DATA_PRESENT %]
31 31
 <p>
32 32
  <table [% IF TABLE_CLASS %]class="[% TABLE_CLASS %]"[% END %] id="report_table_id" width="100%">
33
   <thead>
33 34
   [%- FOREACH row = HEADER_ROWS %]
34 35
   <tr>
35 36
    [% FOREACH col = row %]
......
49 50
    [% END %]
50 51
   </tr>
51 52
   [%- END %]
53
   </thead>
52 54

  
55
   <tbody>
53 56
   [% FOREACH row = ROWS %]
54 57
    [% IF row.IS_CONTROL %]
55 58
     [% IF row.IS_COLSPAN_DATA %]<tr><td colspan="[% row.NUM_COLUMNS %]">[% row.data %]</td></tr>[% END %]
......
82 85
    [% END %]
83 86
   [% END %]
84 87

  
88
   </tbody>
85 89
  </table>
86 90
  <hr size="3" noshade>
87 91
 </p>
......
96 100
 [% END %]
97 101

  
98 102
 [% IF SHOW_EXPORT_BUTTONS %]
99
  <form action="[% HTML.escape(script) %]" name="report_generator_form" method="post">
103
  <form action="[% HTML.escape(script) %]" name="report_generator_form" id="report_generator_form" method="post">
100 104
   [% FOREACH var = EXPORT_VARIABLES %]<input type="hidden" name="report_generator_hidden_[% var.key %]" value="[% HTML.escape(var.value) %]">
101 105
   [% END %]
102 106

  
103 107
[%- IF CONTROLLER_DISPATCH %]
108
[% IF !SKIP_BUTTONS %]
104 109
   <input type="hidden" name="action" value="[% CONTROLLER_DISPATCH %]/dispatch">
110
[%- END %][%# !SKIP_BUTTONS %]
105 111
   <input type="hidden" name="report_generator_nextsub" value="[% HTML.escape(EXPORT_NEXTSUB) %]">
106 112
   <input type="hidden" name="report_generator_variable_list" value="[% HTML.escape(EXPORT_VARIABLE_LIST) %]">
107 113
   <input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]">
108 114

  
115
[% IF !SKIP_BUTTONS %]
109 116
   <p>
110 117
    [% 'List export' | $T8 %]<br>
111 118
    [% IF ALLOW_PDF_EXPORT %]<input type="submit" name="action_report_generator_export_as_pdf" value="[% 'Export as PDF' | $T8 %]">[% END %]
112 119
    [% IF ALLOW_CSV_EXPORT %]<input type="submit" name="action_report_generator_export_as_csv" value="[% 'Export as CSV' | $T8 %]">[% END %]
113 120
   </p>
121
[%- END %][%# !SKIP_BUTTONS %]
114 122
[%- ELSE %]
115 123
   <input type="hidden" name="report_generator_nextsub" value="[% HTML.escape(EXPORT_NEXTSUB) %]">
116 124
   <input type="hidden" name="report_generator_variable_list" value="[% HTML.escape(EXPORT_VARIABLE_LIST) %]">
117 125
   <input type="hidden" name="report_generator_dispatch_to" value="">
118 126
   <input type="hidden" name="action" value="report_generator_dispatcher">
119 127

  
128
[% IF !SKIP_BUTTONS %]
120 129
   <p>
121 130
    [% 'List export' | $T8 %]<br>
122 131
    [% IF ALLOW_PDF_EXPORT %]<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf')" value="[% 'Export as PDF' | $T8 %]">[% END %]
......
128 137
        document.report_generator_form.submit();
129 138
      } // -->
130 139
 </script>
140
[%- END %][%# !SKIP_BUTTONS %]
131 141
[%- END %]
132 142

  
133 143
  </form>
templates/webpages/report_generator/pdf_export_options.html
6 6

  
7 7
 <h1>[% HTML.escape(title) %]</h1>
8 8

  
9
 <form action="[% HTML.escape(script) %]" method="post" name="report_generator_form">
9
 <form action="[% HTML.escape(script) %]" method="post" name="report_generator_form" id="report_generator_form">
10 10

  
11 11
  [%- FOREACH var = HIDDEN %]
12 12
  <input type="hidden" name="[% HTML.escape(var.key) %]" value="[% HTML.escape(var.value) %]">
......
14 14

  
15 15
  <input type="hidden" name="report_generator_pdf_options_set" value="1">
16 16
  <input type="hidden" name="report_generator_dispatch_to" value="">
17
  <input type="hidden" name="report_generator_addattachments" value="">
18 17

  
19 18
  <table>
20 19
   <tr>
......
126 125
  </table>
127 126

  
128 127
[%- IF CONTROLLER_DISPATCH %]
129
   <p>
130
    <input type="hidden" name="action" value="[% CONTROLLER_DISPATCH | html %]/dispatch">
131
    <input type="submit" name="action_report_generator_export_as_pdf" value="[% 'Export as PDF' | $T8 %]">
132
    <input type="submit" name="action_report_generator_back" value="[% 'Back' | $T8 %]">
133 128
    <input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]">
134
   </p>
135 129
[%- ELSE %]
136
  <p>
137 130
   <input type="hidden" name="action" value="report_generator_dispatcher">
138
   <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf','')" value="[% 'Export as PDF' | $T8 %]">
139
[%- IF ALLOW_ATTACHMENTS %]
140
   <input type="submit" class="submit"
141
      onclick="submit_report_generator_form('report_generator_export_as_pdf','yes')"
142
      value="[% 'Export as PDF with attachments' | $T8 %]">
143
[%- END %]
144
   <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]">
145
  </p>
146
 <script type="text/javascript"><!--
147
      function submit_report_generator_form(nextsub,att) {
148
        document.report_generator_form.report_generator_dispatch_to.value = nextsub;
149
        document.report_generator_form.report_generator_addattachments.value = att;
150
        document.report_generator_form.submit();
151
      } // -->
152
 </script>
153 131
[%- END %]
154 132

  
155 133
 </form>

Auch abrufbar als: Unified diff