Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f581a41b

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID f581a41b28e09f2774b96882cdd18ed21dbe4702
  • Vorgänger 3e44c8fe
  • Nachfolger b7af55b2

EmailJournal: nutze Presenter::Record um Belege anzuzeigen

Unterschiede anzeigen:

SL/Controller/EmailJournal.pm
9 9
use SL::DB::EmailJournal;
10 10
use SL::DB::EmailJournalAttachment;
11 11
use SL::Presenter::EmailJournal;
12
use SL::Presenter::Record qw(grouped_record_list);
12 13
use SL::Presenter::Tag qw(html_tag div_tag button_tag);
13 14
use SL::Helper::Flash;
14 15
use SL::Locale::String qw(t8);
......
241 242
  my $cv_type = $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer';
242 243

  
243 244
  my $record_types = $self->record_types_for_customer_vendor_type_and_action($cv_type, 'workflow_record');
244
  my @records = $self->get_records_for_types(
245
    $record_types,
246
    customer_vendor_type => $cv_type,
247
    customer_vendor_id   => $customer_vendor && $customer_vendor->id,
248
    record_number        => '',
249
    with_closed          => 0,
250
  );
251 245

  
252 246
  $self->setup_show_action_bar;
253 247
  my $cv_type_found = $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer';
......
259 253
    CUSTOMER_VENDOR => , $customer_vendor,
260 254
    CV_TYPE_FOUND => $cv_type_found,
261 255
    RECORD_TYPES_WITH_INFO => \@record_types_with_info,
262
    RECORDS => \@records,
263 256
    back_to  => $back_to
264 257
  );
265 258
}
266 259

  
267
sub get_records_for_types {
268
  my ($self, $record_types, %params) = @_;
269
  $record_types = [ $record_types ] unless ref $record_types eq 'ARRAY';
270

  
271
  my $cv_type       = $params{customer_vendor_type};
272
  my $cv_id         = $params{customer_vendor_id};
273
  my $record_number = $params{record_number};
274
  my $with_closed   = $params{with_closed};
275

  
276
  my @records = ();
277
  foreach my $record_type (@$record_types) {
278
    my $manager = $RECORD_TYPE_TO_MANAGER{$record_type};
279
    my $model = $RECORD_TYPE_TO_MODEL{$record_type};
280
    my %additional_where = ();
281
    if ($cv_type && $cv_id && $record_type !~ /^gl_transaction/) {
282
      $additional_where{"${cv_type}_id"} = $cv_id;
283
    }
284
    if ($record_number) {
285
      my $nr_key = $RECORD_TYPE_TO_NR_KEY{$record_type};
286
      $additional_where{$nr_key} = { ilike => "%$record_number%" };
287
    }
288
    unless ($with_closed) {
289
      if (any {$_ eq 'closed'} $model->meta->columns) {
290
        $additional_where{closed} = 0;
291
      } elsif (any {$_ eq 'paid'} $model->meta->columns) {
292
        $additional_where{amount} = { gt => \'paid' };
293
      }
294
    }
295
    my $records_of_type = $manager->get_all(
296
      where => [
297
        $manager->type_filter($record_type),
298
        %additional_where,
299
      ],
300
    );
301
    push @records, @$records_of_type;
302
  }
303

  
304
  return @records;
305
}
306

  
307 260
sub action_attachment_preview {
308 261
  my ($self) = @_;
309 262

  
......
467 420
    with_closed          => $with_closed,
468 421
  );
469 422

  
470
  my $new_list;
471
  if (@records) {
472
    $new_list = join('', map {
473
        button_tag(
474
          "kivi.EmailJournal.apply_action_with_attachment('${\$_->id}', '${\$_->record_type}');",
475
          $_->displayable_name,
476
          class => "record_button",
477
        );
478
      } @records);
479
  } else {
480
    $new_list = html_tag('h3', t8('No records found.'));
481
  }
482
  my $new_div = div_tag(
483
    $new_list,
484
    id => 'record_list',
485
  );
423
  my $new_div = $self->get_records_div(\@records);
486 424

  
487 425
  $self->js->replaceWith('#record_list', $new_div);
488 426
  $self->js->hide('#record_toggle_closed') if scalar @records < 20;
......
527 465
# helpers
528 466
#
529 467

  
468
sub get_records_for_types {
469
  my ($self, $record_types, %params) = @_;
470
  $record_types = [ $record_types ] unless ref $record_types eq 'ARRAY';
471

  
472
  my $cv_type       = $params{customer_vendor_type};
473
  my $cv_id         = $params{customer_vendor_id};
474
  my $record_number = $params{record_number};
475
  my $with_closed   = $params{with_closed};
476

  
477
  my @records = ();
478
  foreach my $record_type (@$record_types) {
479
    my $manager = $RECORD_TYPE_TO_MANAGER{$record_type};
480
    my $model = $RECORD_TYPE_TO_MODEL{$record_type};
481
    my %additional_where = ();
482
    if ($cv_type && $cv_id && $record_type !~ /^gl_transaction/) {
483
      $additional_where{"${cv_type}_id"} = $cv_id;
484
    }
485
    if ($record_number) {
486
      my $nr_key = $RECORD_TYPE_TO_NR_KEY{$record_type};
487
      $additional_where{$nr_key} = { ilike => "%$record_number%" };
488
    }
489
    unless ($with_closed) {
490
      if (any {$_ eq 'closed'} $model->meta->columns) {
491
        $additional_where{closed} = 0;
492
      } elsif (any {$_ eq 'paid'} $model->meta->columns) {
493
        $additional_where{amount} = { gt => \'paid' };
494
      }
495
    }
496
    my $records_of_type = $manager->get_all(
497
      where => [
498
        $manager->type_filter($record_type),
499
        %additional_where,
500
      ],
501
    );
502
    push @records, @$records_of_type;
503
  }
504

  
505
  return @records;
506
}
507

  
508
sub get_records_div {
509
  my ($self, $records) = @_;
510
  my $div = div_tag(
511
    grouped_record_list(
512
      $records,
513
      with_columns => [ qw(email_journal_action) ],
514
    ),
515
    id => 'record_list',
516
  );
517
  return $div;
518
}
519

  
530 520
sub link_and_add_attachment_to_record {
531 521
 my ($self, $params) = @_;
532 522

  
SL/Presenter/Record.pm
4 4

  
5 5
use SL::Presenter;
6 6
use SL::Presenter::EscapedText qw(escape is_escaped);
7
use SL::Presenter::Tag qw(html_tag);
7
use SL::Presenter::Tag qw(html_tag button_tag);
8 8

  
9 9
use Exporter qw(import);
10 10
our @EXPORT_OK = qw(grouped_record_list empty_record_list record_list record);
......
529 529
    $output .= record_list($groups{$type}, _get_type_params($type, %params)) if $groups{$type};
530 530
  }
531 531

  
532
  $output  = SL::Presenter->get->render('presenter/record/grouped_record_list',       %params, output => $output);
532
  $output  = SL::Presenter->get->render('presenter/record/grouped_record_list', %params, output => $output);
533 533

  
534 534
  return $output;
535 535
}
......
596 596
        : $::locale->text('Row was created from current record') },
597 597
    };
598 598
  }
599
  if ($with_columns{email_journal_action}) {
600
    push @columns, {
601
      title => $::locale->text('Action'),
602
      data  => sub {
603
        my $id = $_[0]->id;
604
        my $record_type = $_[0]->record_type;
605
        is_escaped(button_tag(
606
            "kivi.EmailJournal.apply_action_with_attachment(
607
            '$id', '$record_type');",
608
            $::locale->text('Select'),
609
          ))
610
      },
611
    };
612
  }
599 613

  
600 614
  my %column_meta   = map { $_->name => $_ } @{ $list->[0]->meta->columns       };
601 615
  my %relationships = map { $_->name => $_ } @{ $list->[0]->meta->relationships };
css/design40/email_journal.css
1
/* E-Mail-Journal */
2
input.record_button {
3
  color: var(--color-dark);
4
  background-color: var(--color-lighter);
5
  width: 300px;
6
  padding: 5px;
7
  margin: 5px;
8
  float: left;
9
}
templates/design40_webpages/email_journal/show.html
215 215
        </div>
216 216
      </div></div> <!-- filter_div -->
217 217

  
218
      <!-- gets updated on $(document).ready -->
218 219
      <div id="record_div">
219
        [% SET show_records = (RECORDS.size < 20);
220
           IF show_records;
221
             SET display_toggle_off = 'style="display:none;"' ;
222
             SET display_toggle_on  = 'style="display:block;"' ;
223
           ELSE ;
224
             SET display_toggle_off = 'style="display:block;"' ;
225
             SET display_toggle_on  = 'style="display:none;"' ;
226
           END ;
227
        %]
228 220
        <div id="record_toggle_closed"
229
          class="record_toggle toggle_panel control-panel" [% display_toggle_off %]>
221
          class="record_toggle toggle_panel control-panel" style="display:block;">
230 222
          <a href="#" onClick='javascript:$(".record_toggle").toggle()'
231 223
             class="button toggle off neutral">
232 224
            [% LxERP.t8('Show Records') %]
233 225
          </a>
234 226
        </div><!-- /.record_toggle -->
235

  
236 227
        <div id="record_toggle_open"
237
          class="record_toggle toggle_panel control-panel" [% display_toggle_on %]>
228
          class="record_toggle toggle_panel control-panel" style="display:none;">
238 229
          <a href="#" onClick='javascript:$(".record_toggle").toggle()'
239 230
             class="button toggle on neutral with-panel">
240 231
            [% LxERP.t8('Hide Records') %]
241 232
          </a>
242 233
          <div class="toggle_panel_block">
243
            <div id="record_list">
244
            [% FOREACH record = RECORDS %]
245
              [% L.button_tag(
246
                  'kivi.EmailJournal.apply_action_with_attachment("'
247
                  _ record.id _ '", "' _ record.record_type
248
                  _ '");',
249
                  record.displayable_name,
250
                  class="record_button"
251
                ) %]
252
            [% END %]
253
            [% IF RECORDS.size == 0 %]
254
              <h3> [% LxERP.t8("No records found.") %] </h3>
255
            [% END %]
256
            </div>
234
            <div id="record_list">LxERP.t8("Loading...")</div>
257 235
          </div>
258 236
        </div><!-- /.record_toggle -->
259 237
      </div><!-- record_div -->
......
276 254
<script type="text/javascript">
277 255
  $(document).ready(function() {
278 256
    kivi.EmailJournal.update_email_workflow_options();
279
    kivi.EmailJournal.update_record_list();
280 257
    kivi.EmailJournal.update_attachment_preview();
281 258
  });
282 259
</script>
templates/webpages/email_journal/show.html
206 206
             ) %]
207 207
        </div>
208 208
      </div>
209
      <!-- gets updated on $(document).ready -->
209 210
      <div id="record_div">
210
        [% SET show_records = (RECORDS.size < 20);
211
           IF show_records;
212
             SET display_toggle_off = 'style="display:none;"' ;
213
             SET display_toggle_on  = 'style="display:block;"' ;
214
           ELSE ;
215
             SET display_toggle_off = 'style="display:block;"' ;
216
             SET display_toggle_on  = 'style="display:none;"' ;
217
           END ;
218
        %]
219 211
        <div id="record_toggle_closed"
220
          class="record_toggle toggle_panel control-panel" [% display_toggle_off %]>
212
          class="record_toggle toggle_panel control-panel" style="display:block;">
221 213
          <a href="#" onClick='javascript:$(".record_toggle").toggle()'
222 214
             class="button toggle off neutral">
223 215
            [% LxERP.t8('Show Records') %]
224 216
          </a>
225 217
        </div><!-- /.record_toggle -->
226

  
227 218
        <div id="record_toggle_open"
228
          class="record_toggle toggle_panel control-panel" [% display_toggle_on %]>
219
          class="record_toggle toggle_panel control-panel" style="display:none;">
229 220
          <a href="#" onClick='javascript:$(".record_toggle").toggle()'
230 221
             class="button toggle on neutral with-panel">
231 222
            [% LxERP.t8('Hide Records') %]
232 223
          </a>
233 224
          <div class="toggle_panel_block">
234
            <div id="record_list">
235
            [% FOREACH record = RECORDS %]
236
              [% L.button_tag(
237
                  'kivi.EmailJournal.apply_action_with_attachment("'
238
                  _ record.id _ '", "' _ record.record_type
239
                  _ '");',
240
                  record.displayable_name,
241
                  class="record_button"
242
                ) %]
243
            [% END %]
244
            [% IF RECORDS.size == 0 %]
245
              <h3> [% LxERP.t8("No records found.") %] </h3>
246
            [% END %]
247
            </div>
225
            <div id="record_list">LxERP.t8("Loading...")</div>
248 226
          </div>
249 227
        </div><!-- /.record_toggle -->
250 228
      </div><!-- record_div -->
......
265 243
<script type="text/javascript">
266 244
  $(document).ready(function() {
267 245
    kivi.EmailJournal.update_email_workflow_options();
268
    kivi.EmailJournal.update_record_list();
269 246
    kivi.EmailJournal.update_attachment_preview();
270 247
  });
271 248
</script>

Auch abrufbar als: Unified diff