Lieferscheinmaske: JavaScript-Checks für Lagermenge nach kivi.SalesPurchase verschoben
[kivitendo-erp.git] / js / kivi.SalesPurchase.js
1 namespace('kivi.SalesPurchase', function(ns) {
2   this.edit_longdescription = function(row) {
3     var $edit    = $('#popup_edit_longdescription_input');
4     var $element = $('#longdescription_' + row);
5
6     if (!$element.length) {
7       console.error("kivi.SalesPurchase.edit_longdescription: Element #longdescription_" + row + " not found");
8       return;
9     }
10
11     $edit.data('element', $element);
12     $edit.val($element.val());
13
14     $('#popup_edit_longdescription_runningnumber').html(row);
15     $('#popup_edit_longdescription_partnumber').html($('#partnumber_' + row).val() || '');
16
17     var description = ($('#description_' + row).val() || '').replace(/[\n\r]+/, '');
18     if (description.length >= 50)
19       description = description.substring(0, 50) + "…";
20     $('#popup_edit_longdescription_description').html(description);
21
22     kivi.popup_dialog({
23       id:    'edit_longdescription_dialog',
24       dialog: {
25         title: kivi.t8('Enter longdescription'),
26         open:  function() { kivi.set_focus('#popup_edit_longdescription_input'); }
27       }
28     });
29   };
30
31   this.set_longdescription = function() {
32     var $edit    = $('#popup_edit_longdescription_input');
33     var $element = $edit.data('element');
34
35     $element.val($edit.val());
36     $('#edit_longdescription_dialog').dialog('close');
37   };
38
39   this.delivery_order_check_transfer_qty = function() {
40     var all_match = true;
41     var rowcount  = $('input[name=rowcount]').val();
42     for (var i = 1; i < rowcount; i++)
43       if ($('#stock_in_out_qty_matches_' + i).val() != 1)
44         all_match = false;
45
46     if (all_match)
47       return true;
48
49     return confirm(kivi.t8('There are still transfers not matching the qty of the delivery order. Stock operations can not be changed later. Do you really want to proceed?'));
50   };
51
52   this.on_submit_checks = function() {
53     var $button = $(this);
54     if (($button.data('check-transfer-qty') == 1) && !kivi.SalesPurchase.delivery_order_check_transfer_qty())
55       return false;
56
57     return true;
58   };
59
60   this.init_on_submit_checks = function() {
61      $('input[type=submit]').click(kivi.SalesPurchase.on_submit_checks);
62   };
63 });