Merge pull request #30 from rebootl/csv-import-script-fix
[kivitendo-erp.git] / js / kivi.TimeRecording.js
1 namespace('kivi.TimeRecording', function(ns) {
2   'use strict';
3
4   ns.set_end_date = function() {
5     if ($('#start_date').val() !== '' && $('#end_date').val() === '') {
6       var kivi_start_date  = kivi.format_date(kivi.parse_date($('#start_date').val()));
7       $('#end_date').val(kivi_start_date);
8     }
9   };
10
11   ns.set_current_date_time = function(what) {
12     if (what !== 'start' && what !== 'end') return;
13
14     var $date = $('#' + what + '_date');
15     var $time = $('#' + what + '_time');
16     var date = new Date();
17
18     $date.val(kivi.format_date(date));
19     $time.val(kivi.format_time(date));
20   };
21
22   ns.order_changed = function(value) {
23     if (!value) {
24       $('#time_recording_customer_id').data('customer_vendor_picker').set_item({});
25       $('#time_recording_customer_id_name').prop('disabled', false);
26       $('#time_recording_project_id').data('project_picker').set_item({});
27       $('#time_recording_project_id_name').prop('disabled', false);
28       return;
29     }
30
31     var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value;
32     $.getJSON(url, function(data) {
33       $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
34       $('#time_recording_customer_id_name').prop('disabled', true);
35       $('#time_recording_project_id').data('project_picker').set_item(data.project);
36       $('#time_recording_project_id_name').prop('disabled', true);
37     });
38   };
39
40   ns.project_changed = function() {
41     var project_id = $('#time_recording_project_id').val();
42
43     if (!project_id) {
44       $('#time_recording_customer_id_name').prop('disabled', false);
45       return;
46     }
47
48     var url = 'controller.pl?action=TimeRecording/ajaj_get_project_info&id='+ project_id;
49     $.getJSON(url, function(data) {
50       if (data) {
51         $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
52         $('#time_recording_customer_id_name').prop('disabled', true);
53       } else {
54         $('#time_recording_customer_id_name').prop('disabled', false);
55       }
56     });
57   };
58
59 });