Zeiterfassung: Eingaben: Wenn Projekt-Picker gesperrt, dann auch Lupe nicht erlauben
[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   ns.order_changed = function(value) {
25     if (!value) {
26       $('#time_recording_customer_id').data('customer_vendor_picker').set_item({});
27       $('#time_recording_customer_id_name').prop('disabled', false);
28       $('#time_recording_project_id').data('project_picker').set_item({});
29       $('#time_recording_project_id_name').prop('disabled', false);
30       $('#time_recording_project_id ~ .ppp_popup_button').show()
31       return;
32     }
33
34     var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value;
35     $.getJSON(url, function(data) {
36       $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
37       $('#time_recording_customer_id_name').prop('disabled', true);
38       $('#time_recording_project_id').data('project_picker').set_item(data.project);
39       $('#time_recording_project_id_name').prop('disabled', true);
40       $('#time_recording_project_id ~ .ppp_popup_button').hide()
41     });
42   };
43
44   ns.project_changed = function() {
45     var project_id = $('#time_recording_project_id').val();
46
47     if (!project_id) {
48       $('#time_recording_customer_id_name').prop('disabled', false);
49       return;
50     }
51
52     var url = 'controller.pl?action=TimeRecording/ajaj_get_project_info&id='+ project_id;
53     $.getJSON(url, function(data) {
54       if (data) {
55         $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
56         $('#time_recording_customer_id_name').prop('disabled', true);
57       } else {
58         $('#time_recording_customer_id_name').prop('disabled', false);
59       }
60     });
61   };
62
63   ns.set_input_constraints = function() {
64     $(ns.inputs_to_disable).each(function(idx, elt) {
65       if ("customer" === elt) {
66         $('#time_recording_customer_id_name').prop('disabled', true);
67       }
68       if ("project" === elt) {
69         $('#time_recording_project_id_name').prop('disabled', true);
70         setTimeout(function() {$('#time_recording_project_id ~ .ppp_popup_button').hide();}, 100);
71       }
72     });
73   };
74
75 });
76
77 $(function() {
78   kivi.TimeRecording.set_input_constraints();
79   $('#time_recording_project_id').on('set_item:ProjectPicker', function(){ kivi.TimeRecording.project_changed() });
80 });