Auftrags-Controller: longdescription
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Tue, 8 Mar 2016 13:19:43 +0000 (14:19 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Fri, 11 Mar 2016 11:53:26 +0000 (12:53 +0100)
SL/Controller/Order.pm
templates/webpages/order/tabs/_row.html
templates/webpages/order/tabs/basic_data.html

index 5c8685f..68b5ca9 100644 (file)
@@ -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 {
index b15424c..bfd14cc 100644 (file)
                        confirm=LxERP.t8("Are you sure?")) %]
     </td>
     <td>
-      [% HTML.escape(ITEM.part.partnumber) %]
+      <div name="partnumber">[% HTML.escape(ITEM.part.partnumber) %]</div>
     </td>
     <td>
       [% L.input_tag("order.orderitems[].description",
                      ITEM.description,
                      style='width: 300px') %]
+      [%- L.button_tag("show_longdescription_dialog(this)", LxERP.t8("L")) %]
     </td>
     <td>
       [%- L.input_tag("order.orderitems[].qty_as_number",
index 102d5ed..a6ddd0c 100644 (file)
@@ -3,6 +3,8 @@
 [%- USE LxERP %]
 [%- USE L %]
 
+[%- INCLUDE 'generic/set_longdescription.html' %]
+
 <div id="ui-tabs-basic-data">
   <table width="100%">
     <tr valign="top">
@@ -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();
+                   $('<input type="hidden" name="order.orderitems[].longdescription">').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' %]