when i change month intervals function in datesRender work perfectly but when i click booknow button and then change month on my calender it does not call intervals. i have added code you can check if there is any solution let me know
calendar = new Calendar(calendarEl, {
customButtons: {
booknow: {
text: 'Confirm Booking',
click: function() {
booking_payment();
}
}
},
height: 650,
plugins: ['bootstrap', 'interaction', 'dayGrid', 'timeGrid'],
// defaultView: 'timeGridWeek',
selectable: true,
// selectHelper: true,
unselectAuto: false,
header: {
left: 'prev,next today booknow',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
eventRender: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
},
datesRender: function(info){
if($process.length!=0)
{
intervals();
}
},
events: "{{ url('/student/tutor/'.$tutor->id.'/booking') }}",
showNonCurrentDates: false,
// editable: true,
droppable: true, // this allows things to be dropped onto the calendar !!!
drop: function (info) {
// is the "remove after drop" checkbox checked?
if (checkbox.checked) {
// if so, remove the element from the "Draggable Events" list
info.draggedEl.parentNode.removeChild(info.draggedEl);
}
},
dayClick: function(date, jsEvent, view) {
console.log('Clicked on: ' + date.getDate()+"/"+date.getMonth()+"/"+date.getFullYear());
},
});
calendar.render();
here is booking payment method it calculates all pending process and show their summary on a modal name exampleModal a simple modal with payment preview from the pending process
function booking_payment()
{
$('#exampleModal').modal("show");
$values="<table style='border:4px'><tr><th>Subject</th><th>Time Slot </th><th>Amount</th>"
$process.forEach(myFunction);
$values+="<tr><td></td><td>Total Amount </td><td> " + $totalprice+"</td></tr></table>"
$('#show_processing').html($values)
}
function myFunction(item, index) {
$values=$values+"<tr><td>"+ item[0] +" </td><td> "+item[1]+" "+item[3]+" - "+item[2]+" "+item[4]+" </td><td> "
item[4]=item[4].replace(':', '.')
item[3]=item[3].replace(':', '.')
$values=$values .concat(Math.floor(((parseFloat(item[4])-parseFloat(item[3]))*$price_per_hour * 100 / 100) * 100)/100)
$values+="</td></tr>"
$totalhours+=(parseFloat(item[4])-parseFloat(item[3])* 100) / 100
$totalhours=Math.floor($totalhours * 100) / 100
$totalprice+=((parseFloat(item[4])-parseFloat(item[3]))*$price_per_hour * 100) / 100
$totalprice=Math.floor($totalprice * 100) / 100
}
Here is code for intervals it takes all events from a given view and checks if we have any pending process in given time so it replaces the event.
function intervals()
{
var myVar = setInterval(function (){
var events_this_date=calendar.getEvents()
events_this_date.forEach(events_remove_fun);
}, 50);
setTimeout(function(){
clearInterval(myVar);
}, 10000);
}
function events_remove_fun(item, index) {
if (item.id.substring(0,6) == "Booked")
{
console.log("Already Booked");
}
else if (item.id.substring(0,9) == "c_pending")
{
console.log("pending");
}
else if(item.id.substring(0,7) == "c_avail")
{
console.log("available added by user");
}
else
{
var event_start=new Date(item.start).valueOf();
var event_end=new Date(item.end).valueOf();
var item_id=item.id;
$process.forEach(function(item, index){
$osd=item[1]+" "+item[3];
$oed=item[1]+" "+item[4];
$osd=$osd.replace("-", "/");
$osd=$osd.replace("-", "/");
$oed=$oed.replace("-", "/");
$oed=$oed.replace("-", "/");
if(new Date($osd).valueOf()>= event_start && new Date($oed).valueOf()<= event_end)
{
var event = calendar.getEventById(item_id);
event.remove();
console.log(item_id);
}
});
}
}