From e8889e47af38072dc6fcbb4d97e2fdcc30d948d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Tue, 22 Dec 2015 11:43:08 +0100 Subject: [PATCH] Auftrags-Controller: Sortieren der Positionen --- SL/Controller/Order.pm | 23 +++++++++ js/locale/de.js | 1 + locale/de/all | 1 + templates/webpages/order/tabs/basic_data.html | 47 +++++++++++++++++-- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 0f715189d..5c8685fbb 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -449,6 +449,29 @@ sub action_recalc_amounts_and_taxes { $self->js->render(); } +sub action_reorder_items { + my ($self) = @_; + + my %sort_keys = ( + partnumber => sub { $_[0]->part->partnumber }, + description => sub { $_[0]->description }, + qty => sub { $_[0]->qty }, + sellprice => sub { $_[0]->sellprice }, + discount => sub { $_[0]->discount }, + ); + + my $method = $sort_keys{$::form->{order_by}}; + my @to_sort = map { { old_pos => $_->position, order_by => $method->($_) } } @{ $self->order->items_sorted }; + if ($::form->{sort_dir}) { + @to_sort = sort { $a->{order_by} cmp $b->{order_by} } @to_sort; + } else { + @to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort; + } + $self->js + ->run('redisplay_items', \@to_sort) + ->render; +} + sub action_price_popup { my ($self) = @_; diff --git a/js/locale/de.js b/js/locale/de.js index c97b7c621..cbc57d954 100644 --- a/js/locale/de.js +++ b/js/locale/de.js @@ -91,5 +91,6 @@ namespace("kivi").setupLocale({ "Version actions":"Aktionen für Versionen", "Yes":"Ja", "flat-rate position":"Pauschalposition", +"sort items":"Positionen sortieren", "time and effort based position":"Aufwandsposition" }); diff --git a/locale/de/all b/locale/de/all index 445b9becb..3fa000bea 100755 --- a/locale/de/all +++ b/locale/de/all @@ -3548,6 +3548,7 @@ $self->{texts} = { 'shipped' => 'verschickt', 'singular first char' => 'S', 'soldtotal' => 'Verkaufte Anzahl', + 'sort items' => 'Positionen sortieren', 'stock' => 'Einlagerung', 'submit' => 'abschicken', 'succeeded' => 'erfolgreich', diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index 0ee6bc863..102d5ed83 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -157,14 +157,14 @@ [%- 'position' | $T8 %] [%- LxERP.t8('reorder item') %] [%- LxERP.t8('delete item') %] - [%- 'Partnumber' | $T8 %] - [%- 'Description' | $T8 %] - [%- 'Qty' | $T8 %] + [%- 'Partnumber' | $T8 %] + [%- 'Description' | $T8 %] + [%- 'Qty' | $T8 %] [%- 'Price Factor' | $T8 %] [%- 'Unit' | $T8 %] [%- 'Price Source' | $T8 %] - [%- 'Price' | $T8 %] - [%- 'Discount' | $T8 %] + [%- 'Price' | $T8 %] + [%- 'Discount' | $T8 %] [%- 'Extended' | $T8 %] @@ -303,6 +303,8 @@ function add_item() { if ($('#add_item_parts_id').val() == '') return; if (!check_cv()) return; + $('#row_table_id thead a img').remove(); + var data = $('#order_form').serialize(); data += '&action=Order/add_item'; @@ -312,6 +314,8 @@ function add_item() { function show_multi_items_dialog() { if (!check_cv()) return; + $('#row_table_id thead a img').remove(); + kivi.popup_dialog({ url: 'controller.pl?action=Order/show_multi_items_dialog', data: { type: $('#type').val(), @@ -523,6 +527,38 @@ function renumber_positions() { }); } +function reorder_items(order_by) { + var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir"); + $('#row_table_id thead a img').remove(); + + var src; + if (dir == "1") { + dir = "0"; + src = "image/up.png"; + } else { + dir = "1"; + src = "image/down.png"; + }; + + $('#' + order_by + '_header_id a').append('[%- LxERP.t8('sort items') %]'); + + var data = $('#order_form').serialize(); + data += '&action=Order/reorder_items'; + data += '&order_by=' + order_by; + data += '&sort_dir=' + dir; + + $.post("controller.pl", data, kivi.eval_json_result); +} + +function redisplay_items(data) { + var old_rows = $('.row_entry').detach(); + var new_rows = []; + $(data).each(function(idx, elt) { + new_rows.push(old_rows[elt.old_pos - 1]); + }); + $(new_rows).appendTo($('#row_table_id')); + renumber_positions(); +} $(function(){ $('#order_[%- cv_id %]').change(reload_cv_dependend_selections); @@ -548,6 +584,7 @@ $(function(){ }); $('#row_table_id').on('sortstop', function(event, ui) { + $('#row_table_id thead a img').remove(); renumber_positions(); }); -- 2.20.1