vikram singh chandel vikram singh chandel - 14 days ago 7
CSS Question

Copy one week event into next week full calender

From some days I am working in html full calender, my default view is week view, I want to copy one week events into next week by click in html button. I got event array by below mention code but I am not getting, how should I copy this events into next week, I have googled but didn't get any thing regarding this. Please help to resolve this Thanks in advance.

$('#btn_copy_calendar_next_week').click(function () {
$('#calendar').fullCalendar('next');
events = $('#calendar').fullCalendar('clientEvents');
console.log(events);
});


enter image description here

Answer

I got solution of my own problem after very long time, it works for me I hope this will help other too, whoever need it.

$('#btn_copy_calendar_next_week').click(function () { 
    all_events = $('#calendar').fullCalendar('clientEvents');
    var current_view = $('#calendar').fullCalendar('getView');

    var start_date=current_view.start;
    var end_date=current_view.end;  
    var event_obj = new Object();
    var check_current_week_event=false;     

    all_events.forEach(function(evnt) {
        if (evnt['start'].format() >= start_date.format() && evnt['end'].format() <= end_date.format()){
            --l;        
            check_current_week_event=true;
           D1=evnt['start']._d;
           console.log(D1);
            D2=evnt['end']._d;          
            var X1=D1.format("yyyy-mm-dd'T'HH:MM:ss'Z'");
            var X2=D2.format("yyyy-mm-dd'T'HH:MM:ss'Z'");           
            var XD1=new Date(X1);
            var XD2=new Date(X2);                       
            XD1.setUTCDate(XD1.getUTCDate() + 7);
            XD2.setUTCDate(XD2.getUTCDate() + 7);       

            var str_d1 = convertLocalDateToUTCDate(XD1,true);
            var str_d2 =convertLocalDateToUTCDate(XD2,true);            

            var mb_test1 = convertLocalDateToUTCDate(str_d1,true);
            var mb_test2 = convertLocalDateToUTCDate(str_d2,true);

            event_obj.id='vkm_test'+l;
            event_obj.title=evnt['title'];
            event_obj.start= mb_test1.format("yyyy-mm-dd'T'HH:MM:ss'Z'");           
                event_obj.end= mb_test2.format("yyyy-mm-dd'T'HH:MM:ss'Z'");
            event_obj.allDay = false;
            event_obj.offer_id=evnt['offer_id'];
            console.log('=========================');

            customData = {
                           'event_id':"chunked-test"+l,  
                           'offer_id':event_obj.offer_id,                   
                                'title': event_obj.title,
                                'start':event_obj.start,
                                'end':event_obj.end,
                               'rest_id':{{restaurant.restaurant_id}}
                            };      

            console.log(event_obj.start);
            console.log(event_obj.end);         
       // $('#calendar').fullCalendar( 'renderEvent',event_obj);
          $("#calendar").fullCalendar( "removeEvents", "chunked-helper");
        $("#calendar").fullCalendar( "addEventSource",chunk_test(event_obj,'test'+l));
        offers_list.push(customData);  

      }
    }); 
    if(check_current_week_event==true){
      $('#calendar').fullCalendar('next');}
   else{
     $('#hd_id').text('DealMonk');
         $('#txt_error_msg').text('There is Nothing to Copy in Next Week!');
         $('#error_msg').modal('show'); 
   }    
});

Happy Coding..