1 namespace('kivi.DeliveryOrder', function(ns) {
2 ns.check_cv = function() {
3 if ($('#type').val() == 'sales_delivery_order') {
4 if ($('#order_customer_id').val() === '') {
5 alert(kivi.t8('Please select a customer.'));
9 if ($('#order_vendor_id').val() === '') {
10 alert(kivi.t8('Please select a vendor.'));
17 ns.check_duplicate_parts = function(question) {
18 var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() { return this.value; }).get();
20 var i, obj = {}, pos = [];
22 for (i = 0; i < id_arr.length; i++) {
24 if (obj.hasOwnProperty(id)) {
31 question = question || kivi.t8("Do you really want to continue?");
32 return confirm(kivi.t8("There are duplicate parts at positions") + "\n"
33 + pos.join(', ') + "\n"
39 ns.check_valid_reqdate = function() {
40 if ($('#order_reqdate_as_date').val() === '') {
41 alert(kivi.t8('Please select a delivery date.'));
48 ns.save = function(action, warn_on_duplicates, warn_on_reqdate) {
49 if (!ns.check_cv()) return;
50 if (warn_on_duplicates && !ns.check_duplicate_parts()) return;
51 if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
53 var data = $('#order_form').serializeArray();
54 data.push({ name: 'action', value: 'DeliveryOrder/' + action });
56 $.post("controller.pl", data, kivi.eval_json_result);
59 ns.delete_order = function() {
60 var data = $('#order_form').serializeArray();
61 data.push({ name: 'action', value: 'DeliveryOrder/delete' });
63 $.post("controller.pl", data, kivi.eval_json_result);
66 ns.show_print_options = function(warn_on_duplicates, warn_on_reqdate) {
67 if (!ns.check_cv()) return;
68 if (warn_on_duplicates && !ns.check_duplicate_parts(kivi.t8("Do you really want to print?"))) return;
69 if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
74 title: kivi.t8('Print options'),
81 ns.open_stock_in_out_dialog = function(clicked, in_out) {
82 var $row = $(clicked).parents("tbody").first();
83 var id = $row.find('[name="orderitem_ids[+]"]').val();
87 id: "stock_in_out_dialog",
88 url: "controller.pl?action=DeliveryOrder/stock_in_out_dialog",
91 type: $("#type").val(),
92 parts_id: $row.find("[name$=parts_id]").val(),
93 unit: $row.find("[name$=unit]").val(),
94 qty_as_number: $row.find("[name$=qty_as_number]").val(),
95 stock: $row.find("[name$=stock_info]").val(),
99 dialog: { title: kivi.t8('Transfer stock') }
103 ns.save_updated_stock = function() {
104 // stock information is saved in DOM as a yaml dump.
105 // we don't want to do this in javascript so we do a tiny roundtrip to the backend
108 $("#stock-in-out-table tr.listrow").each((i,row) => {
109 let qty = kivi.parse_amount($(row).find(".data-qty").val());
111 if (qty === 0) return;
115 warehouse_id: $(row).find(".data-warehouse-id").val(),
116 bin_id: $(row).find(".data-bin-id").val(),
117 chargenumber: $(row).find(".data-chargenumber").val(),
118 bestbefore: $(row).find(".data-bestbefore").val(),
119 unit: $(row).find(".data-unit").val(),
120 delivery_order_items_stock_id: $(row).find(".data-stock-id").val(),
124 let row = $(".data-row").val();
126 $.post("controller.pl",
128 action: "DeliveryOrder/update_stock_information",
129 unit: $("#" + row).find("[name$=unit]").val(),
134 $("#" + row + " .data-stock-info").val(data.stock_info);
135 $("#" + row + " .data-stock-qty").text(data.stock_qty)
136 $("#stock_in_out_dialog").dialog("close");
141 ns.print = function() {
142 $('#print_options').dialog('close');
144 var data = $('#order_form').serializeArray();
145 data = data.concat($('#print_options_form').serializeArray());
146 data.push({ name: 'action', value: 'DeliveryOrder/print' });
148 $.post("controller.pl", data, kivi.eval_json_result);
153 ns.setup_send_email_dialog = function() {
154 kivi.SalesPurchase.show_all_print_options_elements();
155 kivi.SalesPurchase.show_print_options_elements([ 'sendmode', 'media', 'copies', 'remove_draft' ], false);
157 $('#print_options_form table').first().remove().appendTo('#email_form_print_options');
159 var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject';
160 $('#email_form_' + to_focus).focus();
163 ns.finish_send_email_dialog = function() {
164 kivi.SalesPurchase.show_all_print_options_elements();
166 $('#email_form_print_options table').first().remove().prependTo('#print_options_form');
170 ns.show_email_dialog = function(html) {
171 var id = 'send_email_dialog';
172 var dialog_params = {
176 title: kivi.t8('Send email'),
178 beforeClose: kivi.DeliveryOrder.finish_send_email_dialog,
179 close: function(event, ui) {
180 email_dialog.remove();
184 $('#' + id).remove();
186 email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
187 email_dialog.html(html);
188 email_dialog.dialog(dialog_params);
190 kivi.DeliveryOrder.setup_send_email_dialog();
192 $('.cancel').click(ns.close_email_dialog);
197 ns.send_email = function() {
198 // push button only once -> slow response from mail server
199 ns.email_dialog_disable_send();
201 var data = $('#order_form').serializeArray();
202 data = data.concat($('[name^="email_form."]').serializeArray());
203 data = data.concat($('[name^="print_options."]').serializeArray());
204 data.push({ name: 'action', value: 'DeliveryOrder/send_email' });
205 $.post("controller.pl", data, kivi.eval_json_result);
208 ns.email_dialog_disable_send = function() {
209 // disable mail send event to prevent
210 // impatient users to send multiple times
211 $('#send_email').prop('disabled', true);
214 ns.close_email_dialog = function() {
215 email_dialog.dialog("close");
218 ns.set_number_in_title = function(elt) {
219 $('#nr_in_title').html($(elt).val());
222 ns.reload_cv_dependent_selections = function() {
223 $('#order_shipto_id').val('');
224 var data = $('#order_form').serializeArray();
225 data.push({ name: 'action', value: 'DeliveryOrder/customer_vendor_changed' });
227 $.post("controller.pl", data, kivi.eval_json_result);
230 ns.reformat_number = function(event) {
231 $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
234 ns.reformat_number_as_null_number = function(event) {
235 if ($(event.target).val() === '') {
238 ns.reformat_number(event);
241 ns.update_exchangerate = function(event) {
242 if (!ns.check_cv()) {
243 $('#order_currency_id').val($('#old_currency_id').val());
247 var rate_input = $('#order_exchangerate_as_null_number');
248 // unset exchangerate if currency changed
249 if ($('#order_currency_id').val() !== $('#old_currency_id').val()) {
253 // only set exchangerate if unset
254 if (rate_input.val() !== '') {
258 var data = $('#order_form').serializeArray();
259 data.push({ name: 'action', value: 'DeliveryOrder/update_exchangerate' });
262 url: 'controller.pl',
266 success: function(data){
267 if (!data.is_standard) {
268 $('#currency_name').text(data.currency_name);
269 if (data.exchangerate) {
270 rate_input.val(data.exchangerate);
274 $('#exchangerate_settings').show();
277 $('#exchangerate_settings').hide();
279 if ($('#order_currency_id').val() != $('#old_currency_id').val() ||
280 !data.is_standard && data.exchangerate != $('#old_exchangerate').val()) {
281 kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.'));
283 $('#old_currency_id').val($('#order_currency_id').val());
284 $('#old_exchangerate').val(data.exchangerate);
289 ns.exchangerate_changed = function(event) {
290 if (kivi.parse_amount($('#order_exchangerate_as_null_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) {
291 kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.'));
292 $('#old_exchangerate').val($('#order_exchangerate_as_null_number').val());
296 ns.unit_change = function(event) {
297 var row = $(event.target).parents("tbody").first();
298 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
299 var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
300 var select_elt = $(row).find('[name="order.orderitems[].unit"]');
302 var oldval = $(select_elt).data('oldval');
303 $(select_elt).data('oldval', $(select_elt).val());
305 var data = $('#order_form').serializeArray();
306 data.push({ name: 'action', value: 'DeliveryOrder/unit_changed' },
307 { name: 'item_id', value: item_id_dom.val() },
308 { name: 'old_unit', value: oldval },
309 { name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
311 $.post("controller.pl", data, kivi.eval_json_result);
314 ns.update_sellprice = function(item_id, price_str) {
315 var row = $('#item_' + item_id).parents("tbody").first();
316 var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
317 var html_elt = $(row).find('[name="sellprice_text"]');
318 price_elt.val(price_str);
319 html_elt.html(price_str);
322 ns.load_second_row = function(row) {
323 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
324 var div_elt = $(row).find('[name="second_row"]');
326 if ($(div_elt).data('loaded') == 1) {
329 var data = $('#order_form').serializeArray();
330 data.push({ name: 'action', value: 'DeliveryOrder/load_second_rows' },
331 { name: 'item_ids[]', value: item_id_dom.val() });
333 $.post("controller.pl", data, kivi.eval_json_result);
336 ns.load_all_second_rows = function() {
337 var rows = $('.row_entry').filter(function(idx, elt) {
338 return $(elt).find('[name="second_row"]').data('loaded') != 1;
341 var item_ids = $.map(rows, function(elt) {
342 var item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
343 return { name: 'item_ids[]', value: item_id };
346 if (item_ids.length == 0) {
350 var data = $('#order_form').serializeArray();
351 data.push({ name: 'action', value: 'DeliveryOrder/load_second_rows' });
352 data = data.concat(item_ids);
354 $.post("controller.pl", data, kivi.eval_json_result);
357 ns.hide_second_row = function(row) {
358 $(row).children().not(':first').hide();
359 $(row).data('expanded', 0);
360 var elt = $(row).find('.expand');
361 elt.attr('src', "image/expand.svg");
362 elt.attr('alt', kivi.t8('Show details'));
363 elt.attr('title', kivi.t8('Show details'));
366 ns.show_second_row = function(row) {
367 $(row).children().not(':first').show();
368 $(row).data('expanded', 1);
369 var elt = $(row).find('.expand');
370 elt.attr('src', "image/collapse.svg");
371 elt.attr('alt', kivi.t8('Hide details'));
372 elt.attr('title', kivi.t8('Hide details'));
375 ns.toggle_second_row = function(row) {
376 if ($(row).data('expanded') == 1) {
377 ns.hide_second_row(row);
379 ns.show_second_row(row);
383 ns.init_row_handlers = function() {
384 kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
385 $(elt).change(ns.reformat_number);
388 kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) {
389 $(elt).data('oldval', $(elt).val());
390 $(elt).change(ns.unit_change);
393 kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
394 $(elt).keydown(function(event) {
396 if (event.keyCode == 40 && event.shiftKey === true) {
398 event.preventDefault();
399 row = $(event.target).parents(".row_entry").first();
400 ns.load_second_row(row);
401 ns.show_second_row(row);
404 if (event.keyCode == 38 && event.shiftKey === true) {
406 event.preventDefault();
407 row = $(event.target).parents(".row_entry").first();
408 ns.hide_second_row(row);
414 kivi.run_once_for('.expand', 'expand_second_row', function(elt) {
415 $(elt).click(function(event) {
416 event.preventDefault();
417 var row = $(event.target).parents(".row_entry").first();
418 ns.load_second_row(row);
419 ns.toggle_second_row(row);
426 ns.redisplay_line_values = function(is_sales, data) {
427 $('.row_entry').each(function(idx, elt) {
428 $(elt).find('[name="linetotal"]').html(data[idx][0]);
429 if (is_sales && $(elt).find('[name="second_row"]').data('loaded') == 1) {
430 var mt = data[idx][1];
431 var mp = data[idx][2];
433 if (mt[0] === '-') h += ' class="plus0"';
434 h += '>' + mt + ' ' + mp + '%';
436 $(elt).find('[name="linemargin"]').html(h);
441 ns.redisplay_cvpartnumbers = function(data) {
442 $('.row_entry').each(function(idx, elt) {
443 $(elt).find('[name="cvpartnumber"]').html(data[idx][0]);
447 ns.renumber_positions = function() {
448 $('.row_entry [name="position"]').each(function(idx, elt) {
451 $('.row_entry').each(function(idx, elt) {
452 $(elt).data("position", idx+1);
456 ns.reorder_items = function(order_by) {
457 var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
458 $('#row_table_id thead a img').remove();
463 src = "image/up.png";
466 src = "image/down.png";
469 $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');
471 var data = $('#order_form').serializeArray();
472 data.push({ name: 'action', value: 'DeliveryOrder/reorder_items' },
473 { name: 'order_by', value: order_by },
474 { name: 'sort_dir', value: dir });
476 $.post("controller.pl", data, kivi.eval_json_result);
479 ns.redisplay_items = function(data) {
480 var old_rows = $('.row_entry').detach();
482 $(data).each(function(idx, elt) {
483 new_rows.push(old_rows[elt.old_pos - 1]);
485 $(new_rows).appendTo($('#row_table_id'));
486 ns.renumber_positions();
489 ns.get_insert_before_item_id = function(wanted_pos) {
490 if (wanted_pos === '') return;
492 var insert_before_item_id;
493 // selection by data does not seem to work if data is changed at runtime
494 // var elt = $('.row_entry [data-position="' + wanted_pos + '"]');
495 $('.row_entry').each(function(idx, elt) {
496 if ($(elt).data("position") == wanted_pos) {
497 insert_before_item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
502 return insert_before_item_id;
505 ns.add_item = function() {
506 if ($('#add_item_parts_id').val() === '') return;
507 if (!ns.check_cv()) return;
509 $('#row_table_id thead a img').remove();
511 var insert_before_item_id = ns.get_insert_before_item_id($('#add_item_position').val());
513 var data = $('#order_form').serializeArray();
514 data.push({ name: 'action', value: 'DeliveryOrder/add_item' },
515 { name: 'insert_before_item_id', value: insert_before_item_id });
517 $.post("controller.pl", data, kivi.eval_json_result);
520 ns.open_multi_items_dialog = function() {
521 if (!ns.check_cv()) return;
523 var pp = $("#add_item_parts_id").data("part_picker");
528 ns.add_multi_items = function(data) {
529 var insert_before_item_id = ns.get_insert_before_item_id($('#multi_items_position').val());
530 data = data.concat($('#order_form').serializeArray());
531 data.push({ name: 'action', value: 'DeliveryOrder/add_multi_items' },
532 { name: 'insert_before_item_id', value: insert_before_item_id });
533 $.post("controller.pl", data, kivi.eval_json_result);
536 ns.delete_order_item_row = function(clicked) {
537 var row = $(clicked).parents("tbody").first();
540 ns.renumber_positions();
543 ns.row_table_scroll_down = function() {
544 $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
547 ns.show_longdescription_dialog = function(clicked) {
548 var row = $(clicked).parents("tbody").first();
549 var position = $(row).find('[name="position"]').html();
550 var partnumber = $(row).find('[name="partnumber"]').html();
551 var description_elt = $(row).find('[name="order.orderitems[].description"]');
552 var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]');
555 runningnumber: position,
556 partnumber: partnumber,
557 description: description_elt.val(),
558 default_longdescription: longdescription_elt.val(),
559 set_function: function(val) {
560 longdescription_elt.val(val);
564 kivi.SalesPurchase.edit_longdescription_with_params(params);
567 ns.price_chooser_item_row = function(clicked) {
568 if (!ns.check_cv()) return;
569 var row = $(clicked).parents("tbody").first();
570 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
572 var data = $('#order_form').serializeArray();
573 data.push({ name: 'action', value: 'DeliveryOrder/price_popup' },
574 { name: 'item_id', value: item_id_dom.val() });
576 $.post("controller.pl", data, kivi.eval_json_result);
579 ns.show_vc_details_dialog = function() {
580 if (!ns.check_cv()) return;
584 if ($('#order_customer_id').val()) {
586 vc_id = $('#order_customer_id').val();
587 title = kivi.t8('Customer details');
590 vc_id = $('#order_vendor_id').val();
591 title = kivi.t8('Vendor details');
595 url: 'controller.pl',
596 data: { action: 'DeliveryOrder/show_customer_vendor_details_dialog',
597 type : $('#type').val(),
601 id: 'jq_customer_vendor_details_dialog',
611 ns.update_row_from_master_data = function(clicked) {
612 var row = $(clicked).parents("tbody").first();
613 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
615 var data = $('#order_form').serializeArray();
616 data.push({ name: 'action', value: 'DeliveryOrder/update_row_from_master_data' });
617 data.push({ name: 'item_ids[]', value: item_id_dom.val() });
619 $.post("controller.pl", data, kivi.eval_json_result);
622 ns.update_all_rows_from_master_data = function() {
623 var item_ids = $.map($('.row_entry'), function(elt) {
624 var item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
625 return { name: 'item_ids[]', value: item_id };
628 if (item_ids.length == 0) {
632 var data = $('#order_form').serializeArray();
633 data.push({ name: 'action', value: 'DeliveryOrder/update_row_from_master_data' });
634 data = data.concat(item_ids);
636 $.post("controller.pl", data, kivi.eval_json_result);
639 ns.show_calculate_qty_dialog = function(clicked) {
640 var row = $(clicked).parents("tbody").first();
641 var input_id = $(row).find('[name="order.orderitems[].qty_as_number"]').attr('id');
642 var formula_id = $(row).find('[name="formula[+]"]').attr('id');
644 calculate_qty_selection_dialog("", input_id, "", formula_id);
648 ns.edit_custom_shipto = function() {
649 if (!ns.check_cv()) return;
651 kivi.SalesPurchase.edit_custom_shipto();
654 ns.purchase_order_check_for_direct_delivery = function() {
655 if ($('#type').val() != 'sales_order') {
656 kivi.submit_form_with_action($('#order_form'), 'DeliveryOrder/purchase_order');
661 if ($('#order_shipto_id').val() !== '') {
663 shipto = $('#order_shipto_id option:selected').text();
665 $('#shipto_inputs [id^="shipto"]').each(function(idx, elt) {
666 if (!empty) return true;
667 if (/^shipto_to_copy/.test($(elt).prop('id'))) return true;
668 if (/^shiptocp_gender/.test($(elt).prop('id'))) return true;
669 if (/^shiptocvar_/.test($(elt).prop('id'))) return true;
670 if ($(elt).val() !== '') {
675 var shipto_elements = [];
676 $([$('#shiptoname').val(), $('#shiptostreet').val(), $('#shiptozipcode').val(), $('#shiptocity').val()]).each(function(idx, elt) {
677 if (elt !== '') shipto_elements.push(elt);
679 shipto = shipto_elements.join('; ');
684 ns.direct_delivery_dialog(shipto);
686 kivi.submit_form_with_action($('#order_form'), 'DeliveryOrder/purchase_order');
690 ns.direct_delivery_callback = function(accepted) {
691 $('#direct-delivery-dialog').dialog('close');
694 $('<input type="hidden" name="use_shipto">').appendTo('#order_form').val('1');
697 kivi.submit_form_with_action($('#order_form'), 'DeliveryOrder/purchase_order');
700 ns.direct_delivery_dialog = function(shipto) {
701 $('#direct-delivery-dialog').remove();
703 var text1 = kivi.t8('You have entered or selected the following shipping address for this customer:');
704 var text2 = kivi.t8('Do you want to carry this shipping address over to the new purchase order so that the vendor can deliver the goods directly to your customer?');
705 var html = '<div id="direct-delivery-dialog"><p>' + text1 + '</p><p>' + shipto + '</p><p>' + text2 + '</p>';
706 html = html + '<hr><p>';
707 html = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.DeliveryOrder.direct_delivery_callback(true)">';
708 html = html + ' ';
709 html = html + '<input type="button" value="' + kivi.t8('No') + '" size="30" onclick="kivi.DeliveryOrder.direct_delivery_callback(false)">';
710 html = html + '</p></div>';
711 $(html).hide().appendTo('#order_form');
713 kivi.popup_dialog({id: 'direct-delivery-dialog',
714 dialog: {title: kivi.t8('Carry over shipping address'),
719 ns.follow_up_window = function() {
720 var id = $('#id').val();
721 var type = $('#type').val();
723 var number_info = '';
724 if ($('#type').val() == 'sales_order' || $('#type').val() == 'purchase_order') {
725 number_info = $('#order_ordnumber').val();
726 } else if ($('#type').val() == 'sales_quotation' || $('#type').val() == 'request_quotation') {
727 number_info = $('#order_quonumber').val();
731 if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation') {
732 name_info = $('#order_customer_id_name').val();
733 } else if ($('#type').val() == 'purchase_order' || $('#type').val() == 'request_quotation') {
734 name_info = $('#order_vendor_id_name').val();
738 if (number_info !== '') { info += ' (' + number_info + ')' }
739 if (name_info !== '') { info += ' (' + name_info + ')' }
741 if (!$('#follow_up_rowcount').lenght) {
742 $('<input type="hidden" name="follow_up_rowcount" id="follow_up_rowcount">').appendTo('#order_form');
743 $('<input type="hidden" name="follow_up_trans_id_1" id="follow_up_trans_id_1">').appendTo('#order_form');
744 $('<input type="hidden" name="follow_up_trans_type_1" id="follow_up_trans_type_1">').appendTo('#order_form');
745 $('<input type="hidden" name="follow_up_trans_info_1" id="follow_up_trans_info_1">').appendTo('#order_form');
746 $('<input type="hidden" name="follow_up_trans_subject_1" id="follow_up_trans_subject_1">').appendTo('#order_form');
748 $('#follow_up_rowcount').val(1);
749 $('#follow_up_trans_id_1').val(id);
750 $('#follow_up_trans_type_1').val(type);
751 $('#follow_up_trans_info_1').val(info);
752 $('#follow_up_trans_subject_1').val($('#order_transaction_description').val());
757 ns.create_part = function() {
758 var data = $('#order_form').serializeArray();
759 data.push({ name: 'action', value: 'DeliveryOrder/create_part' });
761 $.post("controller.pl", data, kivi.eval_json_result);
767 $('#order_customer_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections);
768 $('#order_vendor_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections);
770 $('#order_currency_id').change(kivi.DeliveryOrder.update_exchangerate);
771 $('#order_transdate_as_date').change(kivi.DeliveryOrder.update_exchangerate);
772 $('#order_exchangerate_as_null_number').change(kivi.DeliveryOrder.exchangerate_changed);
774 $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
775 $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });
777 $('.add_item_input').keydown(function(event) {
778 if (event.keyCode == 13) {
779 event.preventDefault();
780 kivi.DeliveryOrder.add_item();
785 kivi.DeliveryOrder.init_row_handlers();
787 $('#row_table_id').on('sortstop', function(event, ui) {
788 $('#row_table_id thead a img').remove();
789 kivi.DeliveryOrder.renumber_positions();
792 $('#expand_all').on('click', function(event) {
793 event.preventDefault();
794 if ($('#expand_all').data('expanded') == 1) {
795 $('#expand_all').data('expanded', 0);
796 $('#expand_all').attr('src', 'image/expand.svg');
797 $('#expand_all').attr('alt', kivi.t8('Show all details'));
798 $('#expand_all').attr('title', kivi.t8('Show all details'));
799 $('.row_entry').each(function(idx, elt) {
800 kivi.DeliveryOrder.hide_second_row(elt);
803 $('#expand_all').data('expanded', 1);
804 $('#expand_all').attr('src', "image/collapse.svg");
805 $('#expand_all').attr('alt', kivi.t8('Hide all details'));
806 $('#expand_all').attr('title', kivi.t8('Hide all details'));
807 kivi.DeliveryOrder.load_all_second_rows();
808 $('.row_entry').each(function(idx, elt) {
809 kivi.DeliveryOrder.show_second_row(elt);
815 $('.reformat_number_as_null_number').change(kivi.DeliveryOrder.reformat_number_as_null_number);