Auftrags-Controller: E-Mail-Dialog: nach Speichern hiddens der ids wieder setzen
[kivitendo-erp.git] / js / kivi.TimeRecording.js
1 namespace('kivi.TimeRecording', function(ns) {
2   'use strict';
3
4   ns.inputs_to_disable = [];
5
6   ns.set_end_date = function() {
7     if ($('#start_date').val() !== '' && $('#end_date').val() === '') {
8       var kivi_start_date  = kivi.format_date(kivi.parse_date($('#start_date').val()));
9       $('#end_date').val(kivi_start_date);
10     }
11   };
12
13   ns.set_current_date_time = function(what) {
14     if (what !== 'start' && what !== 'end') return;
15
16     var $date = $('#' + what + '_date');
17     var $time = $('#' + what + '_time');
18     var date = new Date();
19
20     $date.val(kivi.format_date(date));
21     $time.val(kivi.format_time(date));
22   };
23
24   var order_changed_called;
25   ns.order_changed = function(value) {
26     order_changed_called = true;
27
28     if (!value) {
29       $('#time_recording_customer_id').data('customer_vendor_picker').set_item({});
30       $('#time_recording_customer_id_name').prop('disabled', false);
31       $('#time_recording_project_id').data('project_picker').set_item({});
32       $('#time_recording_project_id_name').prop('disabled', false);
33       $('#time_recording_project_id ~ .ppp_popup_button').show()
34       return;
35     }
36
37     var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value;
38     $.getJSON(url, function(data) {
39       $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
40       $('#time_recording_customer_id_name').prop('disabled', true);
41       $('#time_recording_project_id').data('project_picker').set_item(data.project);
42       $('#time_recording_project_id_name').prop('disabled', true);
43       $('#time_recording_project_id ~ .ppp_popup_button').hide()
44     });
45   };
46
47   ns.project_changed = function(event) {
48     if (order_changed_called) {
49       order_changed_called = false;
50       return;
51     }
52
53     var project_id = $('#time_recording_project_id').val();
54
55     if (!project_id) {
56       $('#time_recording_customer_id_name').prop('disabled', false);
57       return;
58     }
59
60     var url = 'controller.pl?action=TimeRecording/ajaj_get_project_info&id='+ project_id;
61     $.getJSON(url, function(data) {
62       if (data) {
63         $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
64         $('#time_recording_customer_id_name').prop('disabled', true);
65       } else {
66         $('#time_recording_customer_id_name').prop('disabled', false);
67       }
68     });
69   };
70
71   ns.set_input_constraints = function() {
72     $(ns.inputs_to_disable).each(function(idx, elt) {
73       if ("customer" === elt) {
74         $('#time_recording_customer_id_name').prop('disabled', true);
75       }
76       if ("project" === elt) {
77         $('#time_recording_project_id_name').prop('disabled', true);
78         setTimeout(function() {$('#time_recording_project_id ~ .ppp_popup_button').hide();}, 100);
79       }
80     });
81   };
82
83 });
84
85 $(function() {
86   kivi.TimeRecording.set_input_constraints();
87   $('#time_recording_project_id').on('set_item:ProjectPicker', function(){ kivi.TimeRecording.project_changed() });
88 });