Robin
Robin

Reputation: 21

How to extract event from one source only Fullcalendar

I have to build a program for the employees of my company to declare days of work, vacation, days of illness etc.. My idea was to use fullcalendar drag and drop function to make something nice. Only on Month view, you drag the event "Work" and put it to the days you worked, as simple as that.

What i try to do, is to extract the event displayed to put them in the database, i tried using :

$('#calendar').fullCalendar('clientEvents');

but i also get the event from my googlecalendar used to display public holidays in background event.

In other words, I have two types of events, the ones I drag and drop, and the ones put there by googlecalendar on backgroundEvents.

Simply put, how can I filter the event I extract to ignore those from googlecalendar? So I put in an array all the event from the calendar, but i don't want those from google.

If possible, i'd be really grateful for any hint on the next step, putting those events in the data base.

What is the solution to extract only the event I added by hand?

Upvotes: 2

Views: 392

Answers (2)

A1rPun
A1rPun

Reputation: 16847

You can pass a function to the clientEvents function like this:

var data = $('#calendar').fullCalendar('clientEvents',function(event){
    return !(event.source && event.source.googleCalendarId);
});

Upvotes: 0

Robin
Robin

Reputation: 21

Alright, i finally got this thanks to a mate at the office. Leaving the answer here just in case:

googlecalendars events and manually added events don't have the same attributs, the googlecalendars ones have 'source' and 'url' attribut that the others don't have.

What you want to do is to get all the event, loop through your array with and select only thoses who doesn't have the source attribut. :

function send(){
        var  cal_events = ''
       data= $('#calendar').fullCalendar('clientEvents');

       for (var key in data) {
            var event = data[key];

            if (typeof(event.source) == 'undefined'){
                 //Your stuff
                    }

                });
            }
        }
    }

That way you can act only on the events without the 'source' attribut.

Thanks anyway. Robin

Upvotes: 0

Related Questions