Netorica
Netorica

Reputation: 19327

JQuery Full Calendar can't use ajax event resource and static resource at the same time

ok im using FullCalendar of Adam Shaw and its really great... and i want to get the most of its features. Ok. my problem is I can't make 2 event resources which is static JSON data in my page which is stored in window.initial_task_items and another which is a jquery.ajax function.

eventSources: [{
            //static events
            events: window.initial_task_items},
        { //ajax fetching
            events: function(start, end, callback) {
                if (window.task_calendar_firstrun == true) {
                    window.task_calendar_firstrun = false;
                }
                else if (window.task_calendar_firstrun == false) {
                    window.AjaxRegistry["gettasks"] = $.ajax({
                        url: window.cvars.userburl + "gettasks",
                        type: "GET",
                        dataType: 'json',
                        data: {
                            procdate: new XDate($('#task-full-calendar').fullCalendar('getDate')).toString("yyyy-MM-dd"),
                            user_hash: window.cvars.acuserhash
                        },
                        beforeSend: function() {

                        },
                        success: function(rsp) {
                            $('#task-full-calendar').fullCalendar('removeEvents');
                            var events = [];
                            $.each(rsp, function(i, task) {
                                events.push({
                                    start: task.start,
                                    end: task.end,
                                    allDay: task.allDay,
                                    title: task.title,
                                    color: task.color
                                });
                            });
                            callback(events);
                        },
                        error: function(ex) {
                            alert("error occured");
                        },
                        complete: function(obj, rsptype) {

                        }
                    });
                }
            }}]

Now I tested that code above lately and this doesn't work. the only working is the ajax request when i click the previous and next button in fullcalendar, but the data in static JSON is not rendered.

Is there anyway i can make the two event resources work?

NOTE: I want to load my page already rendered the tasks on the month that is shown upon seeing the page.

Upvotes: 0

Views: 2439

Answers (1)

domi27
domi27

Reputation: 6923

Well, maybe i don't really understand your problem, but the way to handle your purpose is like this.

You have to pass all of your "sources" (static and dynamic) within the eventsources option, and not to "overwrite" the events like you did :

eventSources: [
     // 1. event source
     array_of_static_events
     // 2. event source
     , { 
         url: "/getevents"
         data: { param1: "test" }
         error: function(){ alert("error"); }
     }
] // end of eventSources

Everything is described in detail in the relating remote events , eventsource object.

Here's an running example with mixed up static and remote sources for fullcalendar events.

Upvotes: 1

Related Questions