Issue 288: Different event sources for different views
Status:  Done
Owner: ----
Closed:  Feb 2010
Reported by mhask...@gmail.com, Jan 13, 2010
I'm sorry if I am posting this in the wrong place. I couldn't find the
place to do a feature request.

I have a situation where I am building out a scheduler utility in a project
where an event consists of a title that is associated with a date and many
time level details that fit better on an agenda view.

Example:
     Event: 1/1/2010 - My Schedule
     Details: 8am - 9am Breakfast w/Family
              10am - 6pm Work
              7pm - 9 Dinner

I have customized your code a little to add a new event that allows me to
replace an event source to facilitate displaying one source for the
calendar view and another for the agenda view, but I didn't seem to catch
the processing in the right place.

In any case, I just thought this would be a really cool feature.

Thanks!
Jan 14, 2010
#1 bibendus...@gmail.com
I think you can already customize the event calling depending on the current view.
Try this:

events: function(start, end, callback) {
	if ($('#calendar').fullCalendar('getView').name == "month") {
		$.getJSON(
			"request_month.php", {
				_: data.getTime(),
				start: (start.getTime()/1000),
				end: (end.getTime()/1000)               
			},
			
			function(result) {    
				callback(result);
			}
		);
	} else {
		$.getJSON(
			"request_week.php", {
				_: data.getTime(),
				start: (start.getTime()/1000),
				end: (end.getTime()/1000)               
			},
			
			function(result) {    
				callback(result);
			}
		);
	}
}
Jan 14, 2010
#2 mhask...@gmail.com
I tried the code posted above. But the problem is that the changeView method does not
trigger the fetchEvents method that would pull from the new source. I have also tried
using the viewDisplay method that is triggered by changeView, but this event occurs
after the fetchEvents.

viewDisplay: function(view) {

                 if (view.name != 'month') {
                     calendar.fullCalendar("useEventSource", eventSource_WeekOrDay);
                 }
                 else {
                     calendar.fullCalendar("useEventSource", eventSource_Month);
                 }

                 //calendar.fullCalendar("refetchEvents", eventSource_WeekOrDay);
             }

I added a new method called useEventSource to tell the plugin to clear all event
sources and use the one specified.
Jan 14, 2010
#3 mhask...@gmail.com
In order to make the event source switch for each calendar view type I needed to do
the following:
1. Make sure that I always have ONLY one event source in the array
2. Create a method that will enforce (1) and allow me to add the appropriate event
source. Code for this is copied below ("useEventSource").
3. Tell the fullCalendar to switch the event source when the view is changed using
the existing "viewDisplay" method.

viewDisplay: function(view) {

                 if (view.name != 'month') {
                     calendar.fullCalendar("useEventSource", eventSource_WeekOrDay);
                 }
                 else {
                     calendar.fullCalendar("useEventSource", eventSource_Month);
                 }
             }

Custom "useEventSource" method added to the public events section of the
fullCalendar.js file:

useEventSource: function(source) {

                    if (eventSources.length >= 0) {
                        if (eventSources.length == 1) {
                            if (eventSources[0] != source) {
                                eventSources.pop();
                            }
                        }
                        else {
                            while (eventSources.length > 1) {
                                eventSources.pop();
                                eventsChanged();
                            }

                            // Remove all events
                            events = [];
                            // clear all array sources
                            for (var i = 0; i < eventSources.length; i++) {
                                if (typeof eventSources[i] == 'object') {
                                    eventSources[i] = [];
                                }
                            }
                        }
                        eventSources.push(source);
                    }
                    
                    if (loadingLevel == 0) {
                        fetchEvents(eventsChanged);
                    }
                }

Note: This is nowhere near an optimized solution but it may be a started place for
someone else.
Jan 15, 2010
#4 bibendus...@gmail.com
Then I think you encountered the caching problem!
Look at this issue:
https://code.google.com/p/fullcalendar/issues/detail?id=240

Usually when you change view a refetch should be called. Unfortunately fullcalendar
has an optimization cache that stores data after a request. If you change view from
month to week or from week to day another request is not needed because fullcalendar
already has this informations. In these cases the refetch event is not called.

Let's hope that Adam will fix this soon!

Jan 15, 2010
#5 mhask...@gmail.com
Thanks for your help bibendus1983! I'll take a look at that issue.
Feb 6, 2010
Project Member #6 adamrs...@gmail.com
thanks for the help bibendus1983. that caching issue will definitely be solved in the 
next release. wanted to get it out for 1.4.4, but didnt have time. will simplify 
things in this case.
Status: Done
Oct 25, 2010
#7 frode.fu...@gmail.com
Thanks! This one fixed my issues with duplicate events being rendered. (v1.4.5)

(Done too many changes, can't easily upgrade to 1.4.7)