1 namespace('kivi.TimeRecording', function(ns) {
4 ns.inputs_to_disable = [];
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);
13 ns.set_current_date_time = function(what) {
14 if (what !== 'start' && what !== 'end') return;
16 var $date = $('#' + what + '_date');
17 var $time = $('#' + what + '_time');
18 var date = new Date();
20 $date.val(kivi.format_date(date));
21 $time.val(kivi.format_time(date));
24 ns.order_changed = function(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);
33 var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value;
34 $.getJSON(url, function(data) {
35 $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
36 $('#time_recording_customer_id_name').prop('disabled', true);
37 $('#time_recording_project_id').data('project_picker').set_item(data.project);
38 $('#time_recording_project_id_name').prop('disabled', true);
42 ns.project_changed = function() {
43 var project_id = $('#time_recording_project_id').val();
46 $('#time_recording_customer_id_name').prop('disabled', false);
50 var url = 'controller.pl?action=TimeRecording/ajaj_get_project_info&id='+ project_id;
51 $.getJSON(url, function(data) {
53 $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
54 $('#time_recording_customer_id_name').prop('disabled', true);
56 $('#time_recording_customer_id_name').prop('disabled', false);
61 ns.set_input_constraints = function() {
62 $(ns.inputs_to_disable).each(function(idx, elt) {
63 if ("customer" === elt) {
64 $('#time_recording_customer_id_name').prop('disabled', true);
66 if ("project" === elt) {
67 $('#time_recording_project_id_name').prop('disabled', true);
75 kivi.TimeRecording.set_input_constraints();
76 $('#time_recording_project_id').on('set_item:ProjectPicker', function(){ kivi.TimeRecording.project_changed() });