From ed04f337a0e565a3d0621a10bd273298e33c7fa1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Tue, 8 Mar 2016 14:19:43 +0100 Subject: [PATCH] Auftrags-Controller: longdescription --- SL/Controller/Order.pm | 29 ++++++++----- templates/webpages/order/tabs/_row.html | 3 +- templates/webpages/order/tabs/basic_data.html | 43 +++++++++++++++++++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 5c8685fbb..68b5ca95e 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -481,6 +481,18 @@ sub action_price_popup { $self->render_price_dialog($item); } +sub action_get_item_longdescription { + my $longdescription; + + if ($::form->{item_id}) { + $longdescription = SL::DB::OrderItem->new(id => $::form->{item_id})->load->longdescription; + } elsif ($::form->{parts_id}) { + $longdescription = SL::DB::Part->new(id => $::form->{parts_id})->load->notes; + } + $_[0]->render(\ $longdescription, { type => 'text' }); +} + + sub _js_redisplay_linetotals { my ($self) = @_; @@ -684,11 +696,15 @@ sub _make_item { my $item; $item = first { $_->id == $attr->{id} } @{$record->items} if $attr->{id}; + my $is_new = !$item; + # add_custom_variables adds cvars to an orderitem with no cvars for saving, but # they cannot be retrieved via custom_variables until the order/orderitem is # saved. Adding empty custom_variables to new orderitem here solves this problem. $item ||= SL::DB::OrderItem->new(custom_variables => []); + $item->assign_attributes(%$attr); + $item->longdescription($item->part->notes) if $is_new && !defined $attr->{longdescription}; return $item; } @@ -735,6 +751,8 @@ sub _new_item { $new_attr{active_price_source} = $price_src; $new_attr{active_discount_source} = $discount_src; + $new_attr{longdescription} = $part->notes if ! defined $attr->{longdescription}; + # add_custom_variables adds cvars to an orderitem with no cvars for saving, but # they cannot be retrieved via custom_variables until the order/orderitem is # saved. Adding empty custom_variables to new orderitem here solves this problem. @@ -770,15 +788,6 @@ sub _get_unalterable_data { my ($self) = @_; foreach my $item (@{ $self->order->items }) { - if ($item->id) { - # load data from orderitems (db) - my $db_item = SL::DB::OrderItem->new(id => $item->id)->load; - $item->$_($db_item->$_) for qw(longdescription); - } else { - # set data from part (or other sources) - $item->longdescription($item->part->notes); - } - # autovivify all cvars that are not in the form (cvars_by_config can do it). # workaround to pre-parse number-cvars (parse_custom_variable_values does not parse number values). foreach my $var (@{ $item->cvars_by_config }) { @@ -863,7 +872,7 @@ sub _pre_render { } } @all_objects; } - $::request->{layout}->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery); + $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery); } sub _create_pdf { diff --git a/templates/webpages/order/tabs/_row.html b/templates/webpages/order/tabs/_row.html index b15424c68..bfd14cc3f 100644 --- a/templates/webpages/order/tabs/_row.html +++ b/templates/webpages/order/tabs/_row.html @@ -25,12 +25,13 @@ confirm=LxERP.t8("Are you sure?")) %] - [% HTML.escape(ITEM.part.partnumber) %] +
[% HTML.escape(ITEM.part.partnumber) %]
[% L.input_tag("order.orderitems[].description", ITEM.description, style='width: 300px') %] + [%- L.button_tag("show_longdescription_dialog(this)", LxERP.t8("L")) %] [%- L.input_tag("order.orderitems[].qty_as_number", diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index 102d5ed83..a6ddd0cf9 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -3,6 +3,8 @@ [%- USE LxERP %] [%- USE L %] +[%- INCLUDE 'generic/set_longdescription.html' %] +
@@ -560,6 +562,47 @@ function redisplay_items(data) { renumber_positions(); } +function show_longdescription_dialog(clicked) { + var row = $(clicked).parents("tbody").first(); + var position = $(row).find('[name="position"]').html(); + var partnumber = $(row).find('[name="partnumber"]').html(); + var description_elt = $(row).find('[name="order.orderitems[].description"]'); + var description = description_elt.val(); + var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]'); + var longdescription; + + if (!longdescription_elt.length) { + var data = 'action=Order/get_item_longdescription'; + data += '&type=' + $('#type').val(); + data += '&item_id=' + $(row).find('[name="order.orderitems[+].id"]').val(); + data += '&parts_id=' + $(row).find('[name="order.orderitems[].parts_id"]').val(); + $.ajax({ + url: 'controller.pl', + data: data, + method: "GET", + async: false, + dataType: 'text', + success: function(val){ + longdescription = val; + } + }); + } else { + longdescription = longdescription_elt.val(); + } + + var params = { runningnumber: position, + partnumber: partnumber, + description: description, + default_longdescription: longdescription, + set_function: function(val){ + longdescription_elt.remove(); + $('').insertAfter(description_elt).val(val); + } + }; + + kivi.SalesPurchase.edit_longdescription_with_params(params); +} + $(function(){ $('#order_[%- cv_id %]').change(reload_cv_dependend_selections); [%- IF SELF.cv == 'customer' %] -- 2.20.1