0

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);
                }
            });
           }
        }
  • Calling intervals within datesRender depends on the result of `if($process.length!=0)`, but we cannot see how $process is defined or set, you have not provided any information about that. So we cannot tell whether that value is changing, and whether that is the reason for your problem. Have you tried to debug that? – ADyson May 21 '20 at 19:10
  • Check this: https://stackoverflow.com/questions/10324311/re-draw-fullcalendar-on-the-fly and call it in the click function. The click function is not specified to trigger any rerendering. You have to trigger this on your own. – Paul May 21 '20 at 19:15
  • @ADyson yes $process is pending events array when we have anything pending then book now button will appear so we can use it to process payment at the time this issue occurred $process is not empty. – Muhammad Afaq Umar May 21 '20 at 19:22
  • @Paul this is not what I'm looking for but thanks for mention – Muhammad Afaq Umar May 21 '20 at 19:33
  • ok. so to clarify, you said "when i click booknow button and then change month" ...how are you changing the month in that instance? Are you calling a fullCalendar method, or clicking the arrow buttons already on the calendar? It would be useful to know precisely what is going on. – ADyson May 21 '20 at 19:43
  • @ADyson yes arrow buttons on calendar – Muhammad Afaq Umar May 21 '20 at 20:58
  • Ok so I made a demo. Based on the code you've given, I cannot reproduce the problem. See here: https://codepen.io/ADyson82/pen/WNQPdYO . It logs "interval" to the console every time the the "intervals" function runs. So I assume there is something important happening in the intervals() or booking_payment() functions which is affecting it. I can't help more unless you show some more of the relevant code. – ADyson May 21 '20 at 21:39
  • @ADyson I have added both functions. – Muhammad Afaq Umar May 22 '20 at 08:08
  • Why are you setting an interval to remove events every 50 milliseconds? This will just repeat the exact same code 200 times in very quick succession. I don't think that's necessarily linked to your problem, but it also doesn't make any sense at all as far as I can see. What was the intended purpose of setting the interval like that? I'm pretty sure you only need to run it once. – ADyson May 22 '20 at 08:31
  • Ok so, from what I can see, the booking_payment() button shows a bootstrap modal. Normally, showing a modal will make everything else on the page un-clickable. You would have to close the modal and then click the next/previous buttons. Is that your problem?? Or are you closing the modal first and _then_ finding that the "intervals" function isn't called when you change the month? It would help to tell us, step by step, precisely what you are doing. – ADyson May 22 '20 at 08:42
  • Also can we have some sample data for the contents of $process please, because it's very hard to run the code without that. – ADyson May 22 '20 at 08:43
  • @ADyson yes I need interval only one time when events for the current view is completely loaded I want to check how many of them are in our process list and remove them – Muhammad Afaq Umar May 23 '20 at 09:39
  • @ADyson yes when i close booking modal intervals does not work here is a sample of process (2) [Array(5), Array(5)] 0: (5) ["Science", "2020-06-18", "2020-06-18", "17.57", "19.57"] 1: (5) ["Chemistry", "2020-07-09", "2020-07-09", "20.58", "21.58"] length: 2 – Muhammad Afaq Umar May 23 '20 at 09:43
  • "when events for the current view is completely loaded"...well "datesRender" doesn't tell you when the events are completely loaded, it only tells you when the calendar layout has been drawn – ADyson May 23 '20 at 09:45
  • @ADyson yes i know i am using datesRender for layout change but the issues is it does work after booking modal apears – Muhammad Afaq Umar May 26 '20 at 04:33
  • You said " I need interval only one time when events for the current view is completely loaded"...so it makes no sense to use that during datesRender, because at that time the events may not have loaded yet. [eventSourceSuccess](https://fullcalendar.io/docs/eventSourceSuccess) would be a more suitable callback because that will fire when all events have been downloaded from the server. That was my point. – ADyson May 26 '20 at 07:53
  • @ADyson thank you my problem is resolved by eventSourceSucess – Muhammad Afaq Umar May 27 '20 at 15:56

0 Answers0