Advertisement
NinoSkopac

Untitled

Jul 30th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     $(function() {
  3.         var ncal_individual_pickup_hours = [];
  4.         var ncal_individual_pickup_hours_helper = []; // to overcome JS' limitation to of not being able to use assoc arrays >:[
  5.        
  6.         var ncal_individual_delivery_hours = ncal_individual_delivery_hours_helper = [];
  7.        
  8.         ncal_individual_pickup_hours.push("8 9 10");
  9.         ncal_individual_pickup_hours_helper.push("07/31/2015");
  10.         ncal_individual_pickup_hours.push("8 9 10");
  11.         ncal_individual_pickup_hours_helper.push("08/01/2015");
  12.         ncal_individual_pickup_hours.push("8 9 10");
  13.         ncal_individual_pickup_hours_helper.push("08/03/2015");
  14.         ncal_individual_delivery_hours.push("17 18 19 20");
  15.         ncal_individual_delivery_hours_helper.push("07/31/2015");
  16.         ncal_individual_delivery_hours.push("17 18 19 20");
  17.         ncal_individual_delivery_hours_helper.push("08/01/2015");
  18.         ncal_individual_delivery_hours.push("17 18 19 20");
  19.         ncal_individual_delivery_hours_helper.push("08/03/2015");
  20.         ncal_individual_delivery_hours.push("17 18 19 20");
  21.         ncal_individual_delivery_hours_helper.push("08/04/2015");
  22.        
  23.         function fill_select_times(array_hours, selector) {
  24.             array_hours = array_hours.split(" ");
  25.             ar_hrs_c = array_hours.length;
  26.            
  27.             $(selector).empty();
  28.            
  29.             $.each(array_hours, function(index, value) {
  30.                 if (index == (ar_hrs_c - 1)) {
  31.                     return false;
  32.                 }
  33.                
  34.                 if (index == 0) {
  35.                     var selected = "selected";
  36.                 } else {
  37.                     var selected = "";
  38.                 }
  39.                
  40.                 if (value > 12) {
  41.                     ampm = "pm";
  42.                 } else {
  43.                     ampm = "am";
  44.                 }
  45.                
  46.                 var next_hour = array_hours[index + 1];
  47.                
  48.                 if (next_hour > 12) {
  49.                     ampm2 = "pm";
  50.                 } else {
  51.                     ampm2 = "am";
  52.                 }
  53.                
  54.                 var option_text = value + ampm;
  55.                 option_text += " - " + next_hour + ampm2;
  56.                 var value_value = option_text;
  57.                
  58.                 $(selector).append('<option value="' + value_value + '"' + selected + '>' + option_text + '</option>');
  59.             });
  60.         }
  61.        
  62.         // for when page intially loads
  63.         fill_select_times(ncal_individual_pickup_hours[0], "#pickup_times");
  64.        
  65.        
  66.         // date changed on pickup calendar? update pickup hours for new date
  67.         $("#pickup_date").on("dp.change", function(e) {
  68.             var ncal_new_date = ($(this).val());
  69.             var ncal_find_pickup_array = ncal_individual_pickup_hours_helper.indexOf(ncal_new_date);
  70.            
  71.             if (ncal_find_pickup_array == -1) {
  72.                 console.log("unexpected error"); // this shouldn't happen, but just to be safe
  73.                 return;
  74.             }
  75.            
  76.             fill_select_times(ncal_individual_pickup_hours[ncal_find_pickup_array], "#pickup_times");
  77.         });
  78.        
  79.        
  80.         $("#pickup_date").datetimepicker({
  81.             pickDate: true,
  82.             pickTime: false,
  83.             //dateFormat: 'dd-mm-yyyy',
  84.             dateFormat: 'mm/dd/yyyy',
  85.             enabledDates: ["07/31/2015","08/01/2015","08/03/2015",],
  86.             defaultDate: "07/31/2015"
  87.         });
  88.        
  89.         $("#delivery_date").datetimepicker({
  90.             pickDate: true,
  91.             pickTime: false,
  92.             dateFormat: 'mm/dd/yyyy',
  93.             defaultDate: "07/31/2015"
  94.         });
  95.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement