var dp = new DayPilot.Calendar("dp"); dp.onTimeRangeSelected = (args) => { var start = args.start.value; var end = args.end.value; //check for valid drags if (!is_day_acceptable(start)) { alert("Bookings only available online for Monday to Wednesdays.") $(".calendar_default_shadow").remove(); return false; } if (!is_start_time_acceptable(start) || !is_end_time_acceptable(end)) { alert("Working hours are between 8am and 4pm."); $(".calendar_default_shadow").remove(); return false; } $.ajax({ url: "/booking", data: { start: start, end: end }, dataType: "json", type: "post", success: (result) => { if (!result.success) { alert(result.message); $(".calendar_default_shadow").remove(); return false; } // otherwise we can book it window.location.href = "/booking/form"; } }); }; dp.viewType = "Week"; dp.dayBeginsHour = 7; dp.dayEndsHour = 18; dp.businessBeginsHour = 8; dp.businessEndsHour = 16; dp.businessBeginsDay = 1; dp.businessEndsDay = 4; dp.headerDateFormat = "dd/MM/yyyy"; dp.events.list = ; dp.init();