Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d0172f91

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID d0172f91bb58d5aac0748d673f29b0565631447e
  • Vorgänger 60e1aa55
  • Nachfolger 7ff0d2ab

Verknüpfte Belege: Implementation "Verknüpfungen löschen"

Unterschiede anzeigen:

SL/Controller/RecordLinks.pm
10 10
use SL::DB::PurchaseInvoice;
11 11
use SL::Locale::String;
12 12

  
13
__PACKAGE__->run_before('check_object_params', only => [ qw(ajax_list ajax_delete) ]);
14

  
13 15
#
14 16
# actions
15 17
#
......
18 20
  my ($self) = @_;
19 21

  
20 22
  eval {
21
    die $::locale->text("Invalid parameters") if (!$::form->{object_id} || ($::form->{object_model} !~ m/^(?:Order|DeliveryOrder|Invoice|PurchaseInvoice)$/));
22

  
23 23
    my $model          = 'SL::DB::' . $::form->{object_model};
24 24
    my $object         = $model->new(id => $::form->{object_id})->load || die $::locale->text("Record not found");
25 25
    my $linked_records = $object->linked_records(direction => 'both');
26
    my $output         = SL::Presenter->get->grouped_record_list($linked_records, with_columns => [ qw(record_link_direction) ]);
26
    my $output         = SL::Presenter->get->grouped_record_list(
27
      $linked_records,
28
      with_columns      => [ qw(record_link_direction) ],
29
      edit_record_links => 1,
30
      object_model      => $::form->{object_model},
31
      object_id         => $::form->{object_id},
32
    );
27 33
    $self->render(\$output, { layout => 0, process => 0 });
28 34

  
29 35
    1;
......
32 38
  };
33 39
}
34 40

  
41
sub action_ajax_delete {
42
  my ($self) = @_;
43

  
44
  my $prefix = $::form->{form_prefix} || 'record_links';
45
  foreach my $str (@{ $::form->{"${prefix}_delete"} || [] }) {
46
    my ($from_table, $from_id, $to_table, $to_id) = split m/__/, $str, 4;
47
    $from_id *= 1;
48
    $to_id   *= 1;
49

  
50
    next if !$from_table || !$from_id || !$to_table || !$to_id;
51

  
52
    # $::lxdebug->message(0, "INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES ('${from_table}', ${from_id}, '${to_table}', ${to_id});");
53

  
54
    SL::DB::Manager::RecordLink->delete_all(where => [
55
      from_table => $from_table,
56
      from_id    => $from_id,
57
      to_table   => $to_table,
58
      to_id      => $to_id,
59
    ]);
60
  }
61

  
62
  $self->action_ajax_list;
63
}
64

  
65
#
66
# filters
67
#
68

  
69
sub check_object_params {
70
  my ($self) = @_;
71

  
72
  return $::form->{object_id} && ($::form->{object_model} =~ m/^(?:Order|DeliveryOrder|Invoice|PurchaseInvoice)$/);
73
}
74

  
35 75
1;
SL/Presenter/Record.pm
20 20
sub grouped_record_list {
21 21
  my ($self, $list, %params) = @_;
22 22

  
23
  %params    = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(selectable with_columns);
23
  %params                = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(edit_record_links form_prefix with_columns object_id object_model);
24
  $params{form_prefix} ||= 'record_links';
24 25

  
25 26
  my %groups = _group_records($list);
26 27
  my $output = '';
......
37 38
  $output .= _purchase_invoice_list(       $self, $groups{purchase_invoices},        %params) if $groups{purchase_invoices};
38 39
  $output .= _ar_transaction_list(         $self, $groups{ar_transactions},          %params) if $groups{ar_transactions};
39 40

  
41
  $output  = $self->render('presenter/record/grouped_record_list', %params, output => $output, nownow => DateTime->now) if $output;
42

  
40 43
  return $output || $self->empty_record_list;
41 44
}
42 45

  
......
110 113
      push @row, \%cell;
111 114
    }
112 115

  
113
    push @data, \@row;
116
    push @data, { columns => \@row, record_link => $obj->{_record_link} };
114 117
  }
115 118

  
116 119
  my @header =
117 120
    map +{ value     => $columns[$_]->{title},
118
           alignment => $data[0]->[$_]->{alignment},
121
           alignment => $data[0]->{columns}->[$_]->{alignment},
119 122
         }, (0..scalar(@columns) - 1);
120 123

  
124
  $params{form_prefix} ||= 'record_links';
125

  
121 126
  return $self->render(
122 127
    'presenter/record/record_list',
123 128
    %params,
......
425 430

  
426 431
Objects of unknown types are skipped.
427 432

  
433
Parameters are passed to C<record_list> include C<with_objects> and
434
C<edit_record_links>.
435

  
428 436
=item C<record_list $list, %params>
429 437

  
430 438
Returns a rendered version (actually an instance of
......
465 473
expected. The corresponding hash keys are C<title>, C<data> and
466 474
C<link>.
467 475

  
476
=item C<with_columns>
477

  
478
Can be set by the caller to indicate additional columns to
479
list. Currently supported:
480

  
481
=over 2
482

  
483
=item C<record_link_destination>
484

  
485
The record link destination. Requires that the records to list have
486
been retrieved via the L<SL::DB::Helper::LinkedRecords> helper.
487

  
488
=back
489

  
490
=item C<edit_record_links>
491

  
492
If trueish additional controls will be rendered that allow the user to
493
remove and add record links. Requires that the records to list have
494
been retrieved via the L<SL::DB::Helper::LinkedRecords> helper.
495

  
468 496
=back
469 497

  
470 498
=back
locale/de/all
612 612
  'Delete delivery order'       => 'Lieferschein l&ouml;schen',
613 613
  'Delete drafts'               => 'Entwürfe löschen',
614 614
  'Delete group'                => 'Gruppe l&ouml;schen',
615
  'Delete links'                => 'Verknüpfungen löschen',
615 616
  'Delete profile'              => 'Profil löschen',
616 617
  'Delete transaction'          => 'Buchung löschen',
617 618
  'Deleted'                     => 'Gelöscht',
......
661 662
  'Do you really want to delete AP transaction #1?' => 'Wollen Sie wirklich die Kreditorenbuchung #1 löschen?',
662 663
  'Do you really want to delete AR transaction #1?' => 'Wollen Sie wirklich die Debitorenbuchung #1 löschen?',
663 664
  'Do you really want to delete GL transaction #1?' => 'Wollen Sie wirklich die Dialogbuchung #1 löschen?',
665
  'Do you really want to delete the selected links?' => 'Wollen Sie wirklich die ausgewählten Verknüpfungen löschen?',
664 666
  'Do you really want to delete this group?' => 'Gruppe wirklich l&ouml;schen?',
665 667
  'Do you really want to delete this object?' => 'Wollen Sie dieses Objekt wirklich löschen?',
666 668
  'Do you really want to delete this warehouse?' => 'Wollen Sie dieses Lager wirklich l&ouml;schen?',
......
1029 1031
  'Inv. Duedate'                => 'Rg. Fälligkeit',
1030 1032
  'Invalid'                     => 'Ungültig',
1031 1033
  'Invalid follow-up ID.'       => 'Ung&uuml;ltige Wiedervorlage-ID.',
1032
  'Invalid parameters'          => 'Ungültige Parameter',
1033 1034
  'Invalid quantity.'           => 'Die Mengenangabe ist ung&uuml;ltig.',
1034 1035
  'Invalid request type \'#1\'' => 'Ungültiger Request-Typ \'#1\'',
1035 1036
  'Invdate'                     => 'Rechnungsdatum',
templates/webpages/presenter/record/grouped_record_list.html
1
[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%]
2

  
3
<div id="[% form_prefix %]_list">
4
 <p>[% nownow %]</p>
5

  
6
 [% output %]
7

  
8
[%- IF edit_record_links %]
9
 <div>
10
  [% L.button_tag(form_prefix _ '_delete()', LxERP.t8('Delete links')) %]
11
 </div>
12

  
13
 <script type="text/javascript">
14
  <!--
15
function [% form_prefix %]_delete() {
16
  var checkboxes = $('.record_links_delete').filter(function () { return $(this).attr('checked'); });
17

  
18
  if ((checkboxes.size() == 0) || !confirm('[% LxERP.t8('Do you really want to delete the selected links?') %]'))
19
    return false;
20

  
21
  var data = {
22
   action:       'RecordLinks/ajax_delete',
23
   object_model: '[% JavaScript.escape(object_model) %]',
24
   object_id:    '[% JavaScript.escape(object_id) %]'
25
  };
26

  
27
  $.ajax({
28
    url:     "controller.pl?" + checkboxes.serialize(),
29
    data:    data,
30
    success: function(new_data) { $('#[% form_prefix %]_list').replaceWith(new_data); }
31
  });
32

  
33
  return false;
34
}
35

  
36
 -->
37
 </script>
38
[%- END %]
39
</div>
templates/webpages/presenter/record/record_list.html
5 5
 <table style="width: 100%">
6 6
  <thead>
7 7
   <tr>
8
    [%- IF edit_record_links %]<th class="listheading"></th>[%- END %]
8 9
    [%- FOREACH column = TABLE_HEADER %]
9 10
    <th class="listheading"[% IF column.alignment %] align="[% column.alignment %]"[% END %]>[%- P.escape(column.value) %]</th>
10 11
    [%- END %]
......
14 15
  <tbody>
15 16
   [%- FOREACH row = TABLE_ROWS %]
16 17
   <tr class="listrow[% loop.count % 2 %]">
17
    [%- FOREACH column = row %]
18
    [%- IF edit_record_links %]
19
     <td>[%- L.checkbox_tag(form_prefix _ '_delete[]', 'value'=row.record_link.from_table _ '__' _ row.record_link.from_id _ '__' _ row.record_link.to_table _ '__' _ row.record_link.to_id, 'class'='record_links_delete') %]</td>
20
    [%- END %]
21
    [%- FOREACH column = row.columns %]
18 22
    <td[% IF column.alignment %] align="[% column.alignment %]"[% END %]>
19 23
     [%- IF column.link %]<a href="[% column.link %]">[%- END %]
20 24
      [%- P.escape(column.value) %]

Auch abrufbar als: Unified diff