kivi.SalesPurchase.edit_longdescription: Aufruf auch mit einzelnen Parametern …
[kivitendo-erp.git] / js / kivi.SalesPurchase.js
1 namespace('kivi.SalesPurchase', function(ns) {
2   this.edit_longdescription = function(row) {
3     var $element = $('#longdescription_' + row);
4
5     if (!$element.length) {
6       console.error("kivi.SalesPurchase.edit_longdescription: Element #longdescription_" + row + " not found");
7       return;
8     }
9
10     var params = { element: $element,
11                    runningnumber: row,
12                    partnumber: $('#partnumber_' + row).val() || '',
13                    description: $('#description_' + row).val() || '',
14                    default_longdescription: $('#longdescription_' + row).val() || ''
15                  };
16     this.edit_longdescription_with_params(params);
17   };
18
19   this.edit_longdescription_with_params = function(params) {
20     var $container = $('#popup_edit_longdescription_input_container');
21     var $edit      = $('<textarea id="popup_edit_longdescription_input" class="texteditor-in-dialog" wrap="soft" style="width: 750px; height: 220px;"></textarea>');
22
23     $container.children().remove();
24     $container.append($edit);
25
26     if (params.element) {
27       $container.data('element', params.element);
28     }
29
30     $edit.val(params.default_longdescription);
31
32     kivi.init_text_editor($edit);
33
34     $('#popup_edit_longdescription_runningnumber').html(params.runningnumber);
35     $('#popup_edit_longdescription_partnumber').html(params.partnumber);
36
37     var description = params.description.replace(/[\n\r]+/, '');
38     if (description.length >= 50)
39       description = description.substring(0, 50) + "…";
40     $('#popup_edit_longdescription_description').html(description);
41
42     kivi.popup_dialog({
43       id:    'edit_longdescription_dialog',
44       dialog: {
45         title: kivi.t8('Enter longdescription'),
46         open:  function() { kivi.focus_ckeditor_when_ready('#popup_edit_longdescription_input'); },
47         close: function() { $('#popup_edit_longdescription_input_container').children().remove(); }
48       }
49     });
50   };
51
52   this.set_longdescription = function() {
53     $('#popup_edit_longdescription_input_container')
54       .data('element')
55       .val( $('#popup_edit_longdescription_input').val() );
56
57     $('#edit_longdescription_dialog').dialog('close');
58   };
59
60   this.delivery_order_check_transfer_qty = function() {
61     var all_match = true;
62     var rowcount  = $('input[name=rowcount]').val();
63     for (var i = 1; i < rowcount; i++)
64       if ($('#stock_in_out_qty_matches_' + i).val() != 1)
65         all_match = false;
66
67     if (all_match)
68       return true;
69
70     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?'));
71   };
72
73   this.oe_warn_save_active_periodic_invoice = function() {
74     return confirm(kivi.t8('This sales order has an active configuration for periodic invoices. If you save then all subsequently created invoices will contain those changes as well, but not those that have already been created. Do you want to continue?'));
75   };
76
77   this.check_transaction_description = function() {
78     if ($('#transaction_description').val() != '')
79       return true;
80
81     alert(kivi.t8('A transaction description is required.'));
82     return false;
83   };
84
85   this.on_submit_checks = function() {
86     var $button = $(this);
87     if (($button.data('check-transfer-qty') == 1) && !kivi.SalesPurchase.delivery_order_check_transfer_qty())
88       return false;
89
90     if (($button.data('warn-save-active-periodic-invoice') == 1) && !kivi.SalesPurchase.oe_warn_save_active_periodic_invoice())
91       return false;
92
93     if (($button.data('require-transaction-description') == 1) && !kivi.SalesPurchase.check_transaction_description())
94       return false;
95
96     return true;
97   };
98
99   this.init_on_submit_checks = function() {
100      $('input[type=submit]').click(kivi.SalesPurchase.on_submit_checks);
101   };
102
103   this.set_duedate_on_reference_date_change = function(reference_field_id) {
104     setTimeout(function() {
105       var data = {
106         action:     'set_duedate',
107         invdate:    $('#' + reference_field_id).val(),
108         duedate:    $('#duedate').val(),
109         payment_id: $('#payment_id').val(),
110       };
111       $.post('is.pl', data, kivi.eval_json_result);
112     });
113   };
114 });