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   var order_changed_called;
 
  25   ns.order_changed = function(value) {
 
  26     order_changed_called = true;
 
  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()
 
  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()
 
  47   ns.project_changed = function(event) {
 
  48     if (order_changed_called) {
 
  49       order_changed_called = false;
 
  53     var project_id = $('#time_recording_project_id').val();
 
  56       $('#time_recording_customer_id_name').prop('disabled', false);
 
  60     var url = 'controller.pl?action=TimeRecording/ajaj_get_project_info&id='+ project_id;
 
  61     $.getJSON(url, function(data) {
 
  63         $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
 
  64         $('#time_recording_customer_id_name').prop('disabled', true);
 
  66         $('#time_recording_customer_id_name').prop('disabled', false);
 
  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);
 
  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);
 
  86   kivi.TimeRecording.set_input_constraints();
 
  87   $('#time_recording_project_id').on('set_item:ProjectPicker', function(){ kivi.TimeRecording.project_changed() });