]> wagnertech.de Git - mfinanz.git/blobdiff - templates/webpages/order/tabs/basic_data.html
Auftrags-Controller: serializeArray und push statt serialize und += auf Strings
[mfinanz.git] / templates / webpages / order / tabs / basic_data.html
index 0ee6bc863ad7afea65791836c2bb12ea52e82b97..b3c9fa050333cfd0cf70f3b45698a55ee90abbc1 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">
                 <th class="listheading" nowrap width="3" >[%- 'position'     | $T8 %] </th>
                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
                 <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th>
-                <th class="listheading" nowrap width="15">[%- 'Partnumber'   | $T8 %] </th>
-                <th class="listheading" nowrap           >[%- 'Description'  | $T8 %] </th>
-                <th class="listheading" nowrap width="5" >[%- 'Qty'          | $T8 %] </th>
+                <th id="partnumber_header_id"  class="listheading" nowrap width="15"><a href='#' onClick='javascript:reorder_items("partnumber")'> [%- 'Partnumber'  | $T8 %]</a></th>
+                <th id="description_header_id" class="listheading" nowrap           ><a href='#' onClick='javascript:reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
+                <th id="qty_header_id"         class="listheading" nowrap width="5" ><a href='#' onClick='javascript:reorder_items("qty")'>        [%- 'Qty'         | $T8 %]</a></th>
                 <th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th>
                 <th class="listheading" nowrap width="5" >[%- 'Unit'         | $T8 %] </th>
                 <th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th>
-                <th class="listheading" nowrap width="15">[%- 'Price'        | $T8 %] </th>
-                <th class="listheading" nowrap width="5" >[%- 'Discount'     | $T8 %] </th>
+                <th id="sellprice_header_id"   class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("sellprice")'> [%- 'Price'       | $T8 %]</a></th>
+                <th id="discount_header_id"    class="listheading" nowrap width="15" ><a href='#' onClick='javascript:reorder_items("discount")'>  [%- 'Discount'    | $T8 %]</a></th>
                 <th class="listheading" nowrap width="10">[%- 'Extended'     | $T8 %] </th>
               </tr>
             </thead>
 
 <script type='text/javascript'>
 function reload_cv_dependend_selections() {
-  var data = $('#order_form').serialize();
-  data += '&action=Order/customer_vendor_changed';
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -282,11 +284,11 @@ function unit_change(event) {
   var oldval = $(select_elt).data('oldval');
   $(select_elt).data('oldval', $(select_elt).val());
 
-  var data = $('#order_form').serialize();
-  data += '&action=Order/unit_changed';
-  data += '&item_id=' + item_id_dom.val();
-  data += '&old_unit=' + oldval;
-  data += '&sellprice_dom_id=' + sellprice_dom.attr('id');
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/unit_changed' });
+  data.push({ name: 'item_id', value: item_id_dom.val() });
+  data.push({ name: 'old_unit', value: oldval });
+  data.push({ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -303,8 +305,10 @@ function add_item() {
   if ($('#add_item_parts_id').val() == '') return;
   if (!check_cv()) return;
 
-  var data = $('#order_form').serialize();
-  data += '&action=Order/add_item';
+  $('#row_table_id thead a img').remove();
+
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/add_item' });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -312,6 +316,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(),
@@ -343,9 +349,9 @@ function price_chooser_item_row(clicked) {
   var row = $(clicked).parents("tbody").first();
   var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
 
-  var data = $('#order_form').serialize();
-  data += '&action=Order/price_popup';
-  data += '&item_id=' + item_id_dom.val();
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/price_popup' });
+  data.push({ name: 'item_id', value: item_id_dom.val() });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -425,8 +431,8 @@ function reformat_number(event) {
 }
 
 function recalc_amounts_and_taxes() {
-  var data = $('#order_form').serialize();
-  data += '&action=Order/recalc_amounts_and_taxes';
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
 
   $.post("controller.pl", data, kivi.eval_json_result);
 }
@@ -523,6 +529,80 @@ 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('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="[%- LxERP.t8('sort items') %]">');
+
+  var data = $('#order_form').serializeArray();
+  data.push({ name: 'action', value: 'Order/reorder_items' });
+  data.push({ name: 'order_by', value: order_by });
+  data.push({ name: 'sort_dir', value: 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 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 = [];
+    data.push({ name: 'action', value: 'Order/get_item_longdescription' });
+    data.push({ name: 'type', value: $('#type').val() });
+    data.push({ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() });
+    data.push({ name: 'parts_id', value: $(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);
@@ -548,6 +628,7 @@ $(function(){
 });
 
 $('#row_table_id').on('sortstop', function(event, ui) {
+  $('#row_table_id thead a img').remove();
   renumber_positions();
 });
 </script>