...
The Datepicker routine will look like this:
Code Block | ||
---|---|---|
| ||
<script> $(function () { $.datepicker.regional['en'] = { dateFormat: 'dd/mm/yy', minDate: 0, firstDay: 1, isRTL: false, beforeShowDay: function(date) { let nonAvailable = jQuery.datepicker.formatDate('dd/mm/yy', date); return [ nonAvailableCheckin.indexOf(nonAvailable) == -1 ] } }; $.datepicker.setDefaults($.datepicker.regional['en']); }); $('#checkinDate').datepicker({ setDate: '{clickedDate}', minDate: '{minDate}', onSelect: function (selected) { let date = $(this).datepicker('getDate'); if (date) { date.setDate(date.getDate() + {minimumStay}); } $('#checkoutDate').datepicker('option', 'minDate', date); let today = new Date(); let diffToday = 0; for (let x = 0; x < nonAvailableCheckout.length; x++) { let parts = nonAvailableCheckout[x].split('/'); let mydate = new Date(parts[2], parts[1] - 1, parts[0]); if (mydate > date) { $('#checkoutDate').datepicker('option', 'maxDate', mydate); break; } } } }); $('#checkoutDate').datepicker({ setDate: '{clickedDate}', minDate: '{minDate}', beforeShowDay: function(date) { let nonAvailable = jQuery.datepicker.formatDate('dd/mm/yy', date); return [ nonAvailableCheckout.indexOf(nonAvailable) == -1 ]; } }); </script> |
...
Code Block | ||||
---|---|---|---|---|
| ||||
Dim property_id As Integer = 1001 'Variables needed for the logic: Dim arrivalDaysNotAvailable As String = "" Dim departureDaysNotAvailable As String = "" Dim minimumStays As String = "" Dim dayBeforeAvailable As Boolean = False 'Reading the Calendar WS for the next 12 months 'Here we will create 2 arrays, one for arrivals and one for departures, where we will put all the unavailable dates: Dim cson As String = icnea.Calendar(property_id, Today, 12, Funcions.Empresa, Funcions.Password) Dim css As Object = New JavaScriptSerializer() With {.MaxJsonLength = Int32.MaxValue} Dim c As Object = css.Deserialize(Of Object)(cson) If c("Calendar").length > 0 Then For i As Integer = 0 To c("Calendar").length - 1 If CBool(c("Calendar")(i)("available")) Then 'available days dayBeforeAvailable = True Else If dayBeforeAvailable Then 'it is the first unavailable day of the interval Else 'unavailable days for the departure calendar departureDaysNotAvailable &= """" & CDate(c("Calendar")(i)("date")).ToString("dd/MM/yyy").Replace(".", "/").Replace("-", "/") & """," End If 'unavailable days for the arrival calendar arrivalDaysNotAvailable &= """" & CDate(c("Calendar")(i)("date")).ToString("dd/MM/yyy").Replace(".", "/").Replace("-", "/") & """," dayBeforeAvailable = False End If 'minimum stay minimumStays += c("Calendar")(i)("minimum_stay") & "," Next End If 'We delete the last character for each array, which is a comma If arrivalDaysNotAvailable.Length > 0 Then arrivalDaysNotAvailable = arrivalDaysNotAvailable.Remove(arrivalDaysNotAvailable.Length - 1) End If If departureDaysNotAvailable.Length > 0 Then departureDaysNotAvailable = departureDaysNotAvailable.Remove(departureDaysNotAvailable.Length - 1) End If If minimumStays.Length > 0 Then minimumStays = minimumStays.Remove(minimumStays.Length - 1) End If 'We add the arrays in this variable that will be the script that we will add before the Datepicker routine: Dim datePickerArrays As String = "" datePickerArrays &= "<script>" datePickerArrays &= "let nonAvailableCheckin = [" & arrivalDaysNotAvailable & "];" datePickerArrays &= "let nonAvailableCheckout = [" & departureDaysNotAvailable & "];" datePickerArrays &= "let minimumStay = [" & minimumStays & "];" datePickerArrays &= "</script>" |
...