From eedda2f58be60f96810c28bd3e9870eef7854ecf Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 27 Jul 2016 09:25:29 -0400 Subject: [PATCH] adding js logic for the off canvas reservation widget to restrict the arrival and departure times based on a 1 day minimum requirement --- js/app.js | 45 ++++++++++++++++++++++++++++++++++++++++++ js/custom/pageSetup.js | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/js/app.js b/js/app.js index 0419507..944a050 100644 --- a/js/app.js +++ b/js/app.js @@ -80,5 +80,50 @@ $(document).ready(function () { $("#departCal").click(function () { $(departure_date).datepicker("show"); }); + + var extraDay, end, arrival, currentDate, currentDate2, + requiredDate, requiredDate1, minDays, departure, + stay, d, dd, m, y; + $(document).on('change', '#arriveOff', function () { + currentDate = $("#arriveOff").val(); + currentDate = new Date(currentDate); + + // this section is used to circumvent issues with selecting the last day of the month without a proper rollover to the following month. + currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); + currentDate.setDate(currentDate.getDate()); + + dd = currentDate.getDate() + 1; + if (dd <= 9) { + dd = '0' + dd; + } + d = currentDate.getDate(); + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + + // this variable is for passing to booking site + requiredDate = y + '-' + m + '-' + d; + minDays = y + '-' + m + '-' + dd; + $("#departOff").attr("min", minDays); + if (requiredDate <= $("#arriveOff").attr("min")) { + minDays = $("#arriveOff").attr("min"); + $("#arriveOff").val(minDays); + } + }); + // restrict departure date /////////////////////////////// + $(document).on('change', '#departOff', function () { + currentDate2 = $("#departOff").val(); + currentDate2 = new Date(currentDate2); + currentDate2 = new Date(currentDate2.getUTCFullYear(), currentDate2.getUTCMonth(),currentDate2.getUTCDate()); + currentDate2.setDate(currentDate2.getDate()); + if($("#departOff").val() <= requiredDate){ + $("#departOff").val(minDays); + } + }); }); diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 8adf876..69d7fcd 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -71,5 +71,50 @@ $(document).ready(function () { $("#departCal").click(function () { $(departure_date).datepicker("show"); }); + + var extraDay, end, arrival, currentDate, currentDate2, + requiredDate, requiredDate1, minDays, departure, + stay, d, dd, m, y; + $(document).on('change', '#arriveOff', function () { + currentDate = $("#arriveOff").val(); + currentDate = new Date(currentDate); + + // this section is used to circumvent issues with selecting the last day of the month without a proper rollover to the following month. + currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); + currentDate.setDate(currentDate.getDate()); + + dd = currentDate.getDate() + 1; + if (dd <= 9) { + dd = '0' + dd; + } + d = currentDate.getDate(); + if (d <= 9) { + d = '0' + d; + } + m = currentDate.getMonth() + 1; + if (m <= 9) { + m = '0' + m; + } + y = currentDate.getFullYear(); + + // this variable is for passing to booking site + requiredDate = y + '-' + m + '-' + d; + minDays = y + '-' + m + '-' + dd; + $("#departOff").attr("min", minDays); + if (requiredDate <= $("#arriveOff").attr("min")) { + minDays = $("#arriveOff").attr("min"); + $("#arriveOff").val(minDays); + } + }); + // restrict departure date /////////////////////////////// + $(document).on('change', '#departOff', function () { + currentDate2 = $("#departOff").val(); + currentDate2 = new Date(currentDate2); + currentDate2 = new Date(currentDate2.getUTCFullYear(), currentDate2.getUTCMonth(),currentDate2.getUTCDate()); + currentDate2.setDate(currentDate2.getDate()); + if($("#departOff").val() <= requiredDate){ + $("#departOff").val(minDays); + } + }); }); -- 2.17.1