Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function() {
- var ncal_individual_pickup_hours = [];
- var ncal_individual_pickup_hours_helper = []; // to overcome JS' limitation to of not being able to use assoc arrays >:[
- var ncal_individual_delivery_hours = ncal_individual_delivery_hours_helper = [];
- ncal_individual_pickup_hours.push("8 9 10");
- ncal_individual_pickup_hours_helper.push("07/31/2015");
- ncal_individual_pickup_hours.push("8 9 10");
- ncal_individual_pickup_hours_helper.push("08/01/2015");
- ncal_individual_pickup_hours.push("8 9 10");
- ncal_individual_pickup_hours_helper.push("08/03/2015");
- ncal_individual_delivery_hours.push("17 18 19 20");
- ncal_individual_delivery_hours_helper.push("07/31/2015");
- ncal_individual_delivery_hours.push("17 18 19 20");
- ncal_individual_delivery_hours_helper.push("08/01/2015");
- ncal_individual_delivery_hours.push("17 18 19 20");
- ncal_individual_delivery_hours_helper.push("08/03/2015");
- ncal_individual_delivery_hours.push("17 18 19 20");
- ncal_individual_delivery_hours_helper.push("08/04/2015");
- function fill_select_times(array_hours, selector) {
- array_hours = array_hours.split(" ");
- ar_hrs_c = array_hours.length;
- $(selector).empty();
- $.each(array_hours, function(index, value) {
- if (index == (ar_hrs_c - 1)) {
- return false;
- }
- if (index == 0) {
- var selected = "selected";
- } else {
- var selected = "";
- }
- if (value > 12) {
- ampm = "pm";
- } else {
- ampm = "am";
- }
- var next_hour = array_hours[index + 1];
- if (next_hour > 12) {
- ampm2 = "pm";
- } else {
- ampm2 = "am";
- }
- var option_text = value + ampm;
- option_text += " - " + next_hour + ampm2;
- var value_value = option_text;
- $(selector).append('<option value="' + value_value + '"' + selected + '>' + option_text + '</option>');
- });
- }
- // for when page intially loads
- fill_select_times(ncal_individual_pickup_hours[0], "#pickup_times");
- // date changed on pickup calendar? update pickup hours for new date
- $("#pickup_date").on("dp.change", function(e) {
- var ncal_new_date = ($(this).val());
- var ncal_find_pickup_array = ncal_individual_pickup_hours_helper.indexOf(ncal_new_date);
- if (ncal_find_pickup_array == -1) {
- console.log("unexpected error"); // this shouldn't happen, but just to be safe
- return;
- }
- fill_select_times(ncal_individual_pickup_hours[ncal_find_pickup_array], "#pickup_times");
- });
- $("#pickup_date").datetimepicker({
- pickDate: true,
- pickTime: false,
- //dateFormat: 'dd-mm-yyyy',
- dateFormat: 'mm/dd/yyyy',
- enabledDates: ["07/31/2015","08/01/2015","08/03/2015",],
- defaultDate: "07/31/2015"
- });
- $("#delivery_date").datetimepicker({
- pickDate: true,
- pickTime: false,
- dateFormat: 'mm/dd/yyyy',
- defaultDate: "07/31/2015"
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement