From d0172f91bb58d5aac0748d673f29b0565631447e Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 28 Feb 2013 12:40:28 +0100 Subject: [PATCH] =?utf8?q?Verkn=C3=BCpfte=20Belege:=20Implementation=20"Ve?= =?utf8?q?rkn=C3=BCpfungen=20l=C3=B6schen"?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RecordLinks.pm | 46 +++++++++++++++++-- SL/Presenter/Record.pm | 34 ++++++++++++-- locale/de/all | 3 +- .../presenter/record/grouped_record_list.html | 39 ++++++++++++++++ .../presenter/record/record_list.html | 6 ++- 5 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 templates/webpages/presenter/record/grouped_record_list.html diff --git a/SL/Controller/RecordLinks.pm b/SL/Controller/RecordLinks.pm index 8edd78754..a76144333 100644 --- a/SL/Controller/RecordLinks.pm +++ b/SL/Controller/RecordLinks.pm @@ -10,6 +10,8 @@ use SL::DB::Invoice; use SL::DB::PurchaseInvoice; use SL::Locale::String; +__PACKAGE__->run_before('check_object_params', only => [ qw(ajax_list ajax_delete) ]); + # # actions # @@ -18,12 +20,16 @@ sub action_ajax_list { my ($self) = @_; eval { - die $::locale->text("Invalid parameters") if (!$::form->{object_id} || ($::form->{object_model} !~ m/^(?:Order|DeliveryOrder|Invoice|PurchaseInvoice)$/)); - my $model = 'SL::DB::' . $::form->{object_model}; my $object = $model->new(id => $::form->{object_id})->load || die $::locale->text("Record not found"); my $linked_records = $object->linked_records(direction => 'both'); - my $output = SL::Presenter->get->grouped_record_list($linked_records, with_columns => [ qw(record_link_direction) ]); + my $output = SL::Presenter->get->grouped_record_list( + $linked_records, + with_columns => [ qw(record_link_direction) ], + edit_record_links => 1, + object_model => $::form->{object_model}, + object_id => $::form->{object_id}, + ); $self->render(\$output, { layout => 0, process => 0 }); 1; @@ -32,4 +38,38 @@ sub action_ajax_list { }; } +sub action_ajax_delete { + my ($self) = @_; + + my $prefix = $::form->{form_prefix} || 'record_links'; + foreach my $str (@{ $::form->{"${prefix}_delete"} || [] }) { + my ($from_table, $from_id, $to_table, $to_id) = split m/__/, $str, 4; + $from_id *= 1; + $to_id *= 1; + + next if !$from_table || !$from_id || !$to_table || !$to_id; + + # $::lxdebug->message(0, "INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES ('${from_table}', ${from_id}, '${to_table}', ${to_id});"); + + SL::DB::Manager::RecordLink->delete_all(where => [ + from_table => $from_table, + from_id => $from_id, + to_table => $to_table, + to_id => $to_id, + ]); + } + + $self->action_ajax_list; +} + +# +# filters +# + +sub check_object_params { + my ($self) = @_; + + return $::form->{object_id} && ($::form->{object_model} =~ m/^(?:Order|DeliveryOrder|Invoice|PurchaseInvoice)$/); +} + 1; diff --git a/SL/Presenter/Record.pm b/SL/Presenter/Record.pm index 64cb21ba7..db0caa542 100644 --- a/SL/Presenter/Record.pm +++ b/SL/Presenter/Record.pm @@ -20,7 +20,8 @@ sub _arrayify { sub grouped_record_list { my ($self, $list, %params) = @_; - %params = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(selectable with_columns); + %params = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(edit_record_links form_prefix with_columns object_id object_model); + $params{form_prefix} ||= 'record_links'; my %groups = _group_records($list); my $output = ''; @@ -37,6 +38,8 @@ sub grouped_record_list { $output .= _purchase_invoice_list( $self, $groups{purchase_invoices}, %params) if $groups{purchase_invoices}; $output .= _ar_transaction_list( $self, $groups{ar_transactions}, %params) if $groups{ar_transactions}; + $output = $self->render('presenter/record/grouped_record_list', %params, output => $output, nownow => DateTime->now) if $output; + return $output || $self->empty_record_list; } @@ -110,14 +113,16 @@ sub record_list { push @row, \%cell; } - push @data, \@row; + push @data, { columns => \@row, record_link => $obj->{_record_link} }; } my @header = map +{ value => $columns[$_]->{title}, - alignment => $data[0]->[$_]->{alignment}, + alignment => $data[0]->{columns}->[$_]->{alignment}, }, (0..scalar(@columns) - 1); + $params{form_prefix} ||= 'record_links'; + return $self->render( 'presenter/record/record_list', %params, @@ -425,6 +430,9 @@ The order in which the records are grouped is: Objects of unknown types are skipped. +Parameters are passed to C include C and +C. + =item C Returns a rendered version (actually an instance of @@ -465,6 +473,26 @@ If the column spec is a hash reference then the same arguments are expected. The corresponding hash keys are C, C<data> and C<link>. +=item C<with_columns> + +Can be set by the caller to indicate additional columns to +list. Currently supported: + +=over 2 + +=item C<record_link_destination> + +The record link destination. Requires that the records to list have +been retrieved via the L<SL::DB::Helper::LinkedRecords> helper. + +=back + +=item C<edit_record_links> + +If trueish additional controls will be rendered that allow the user to +remove and add record links. Requires that the records to list have +been retrieved via the L<SL::DB::Helper::LinkedRecords> helper. + =back =back diff --git a/locale/de/all b/locale/de/all index 80f80e98d..a7e2ef11d 100644 --- a/locale/de/all +++ b/locale/de/all @@ -612,6 +612,7 @@ $self->{texts} = { 'Delete delivery order' => 'Lieferschein löschen', 'Delete drafts' => 'Entwürfe löschen', 'Delete group' => 'Gruppe löschen', + 'Delete links' => 'Verknüpfungen löschen', 'Delete profile' => 'Profil löschen', 'Delete transaction' => 'Buchung löschen', 'Deleted' => 'Gelöscht', @@ -661,6 +662,7 @@ $self->{texts} = { 'Do you really want to delete AP transaction #1?' => 'Wollen Sie wirklich die Kreditorenbuchung #1 löschen?', 'Do you really want to delete AR transaction #1?' => 'Wollen Sie wirklich die Debitorenbuchung #1 löschen?', 'Do you really want to delete GL transaction #1?' => 'Wollen Sie wirklich die Dialogbuchung #1 löschen?', + 'Do you really want to delete the selected links?' => 'Wollen Sie wirklich die ausgewählten Verknüpfungen löschen?', 'Do you really want to delete this group?' => 'Gruppe wirklich löschen?', 'Do you really want to delete this object?' => 'Wollen Sie dieses Objekt wirklich löschen?', 'Do you really want to delete this warehouse?' => 'Wollen Sie dieses Lager wirklich löschen?', @@ -1029,7 +1031,6 @@ $self->{texts} = { 'Inv. Duedate' => 'Rg. Fälligkeit', 'Invalid' => 'Ungültig', 'Invalid follow-up ID.' => 'Ungültige Wiedervorlage-ID.', - 'Invalid parameters' => 'Ungültige Parameter', 'Invalid quantity.' => 'Die Mengenangabe ist ungültig.', 'Invalid request type \'#1\'' => 'Ungültiger Request-Typ \'#1\'', 'Invdate' => 'Rechnungsdatum', diff --git a/templates/webpages/presenter/record/grouped_record_list.html b/templates/webpages/presenter/record/grouped_record_list.html new file mode 100644 index 000000000..0016612df --- /dev/null +++ b/templates/webpages/presenter/record/grouped_record_list.html @@ -0,0 +1,39 @@ +[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%] + +<div id="[% form_prefix %]_list"> + <p>[% nownow %]</p> + + [% output %] + +[%- IF edit_record_links %] + <div> + [% L.button_tag(form_prefix _ '_delete()', LxERP.t8('Delete links')) %] + </div> + + <script type="text/javascript"> + <!-- +function [% form_prefix %]_delete() { + var checkboxes = $('.record_links_delete').filter(function () { return $(this).attr('checked'); }); + + if ((checkboxes.size() == 0) || !confirm('[% LxERP.t8('Do you really want to delete the selected links?') %]')) + return false; + + var data = { + action: 'RecordLinks/ajax_delete', + object_model: '[% JavaScript.escape(object_model) %]', + object_id: '[% JavaScript.escape(object_id) %]' + }; + + $.ajax({ + url: "controller.pl?" + checkboxes.serialize(), + data: data, + success: function(new_data) { $('#[% form_prefix %]_list').replaceWith(new_data); } + }); + + return false; +} + + --> + </script> +[%- END %] +</div> diff --git a/templates/webpages/presenter/record/record_list.html b/templates/webpages/presenter/record/record_list.html index d701d6fc8..e1395a24d 100644 --- a/templates/webpages/presenter/record/record_list.html +++ b/templates/webpages/presenter/record/record_list.html @@ -5,6 +5,7 @@ <table style="width: 100%"> <thead> <tr> + [%- IF edit_record_links %]<th class="listheading"></th>[%- END %] [%- FOREACH column = TABLE_HEADER %] <th class="listheading"[% IF column.alignment %] align="[% column.alignment %]"[% END %]>[%- P.escape(column.value) %]</th> [%- END %] @@ -14,7 +15,10 @@ <tbody> [%- FOREACH row = TABLE_ROWS %] <tr class="listrow[% loop.count % 2 %]"> - [%- FOREACH column = row %] + [%- IF edit_record_links %] + <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> + [%- END %] + [%- FOREACH column = row.columns %] <td[% IF column.alignment %] align="[% column.alignment %]"[% END %]> [%- IF column.link %]<a href="[% column.link %]">[%- END %] [%- P.escape(column.value) %] -- 2.20.1