Skip to content

Commit

Permalink
fixed issues 554, 586, and 616
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Oct 11, 2010
1 parent 82aacbb commit 453fcf0
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 30 deletions.
68 changes: 39 additions & 29 deletions src/EventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function EventManager(options, eventSources) {


// locals
var fetchID = 0;
var eventStart, eventEnd;
var events = [];
var loadingLevel = 0;
Expand Down Expand Up @@ -64,45 +65,49 @@ function EventManager(options, eventSources) {

// Fetch from ALL sources. Clear 'events' array and populate
function fetchEvents(callback) {
var view = getView();
events = [];
eventStart = cloneDate(view.visStart);
eventEnd = cloneDate(view.visEnd);
var queued = eventSources.length,
sourceDone = function() {
fetchEventSources(eventSources, callback);
}


// appends to the events array
function fetchEventSources(sources, callback) {
var savedID = ++fetchID;
var queued = sources.length;
var view = getView();
eventStart = cloneDate(view.visStart); // we don't need to make local copies b/c
eventEnd = cloneDate(view.visEnd); // eventStart/eventEnd is only assigned/manipulated here
function sourceDone(source, sourceEvents) {
if (savedID == fetchID && eventStart >= view.visStart && eventEnd <= view.visEnd) {
// same fetchEventSources call, and still in correct date range
if ($.inArray(source, eventSources) != -1) { // source hasn't been removed since we started
for (var i=0; i<sourceEvents.length; i++) {
normalizeEvent(sourceEvents[i]);
sourceEvents[i].source = source;
}
events = events.concat(sourceEvents);
}
if (!--queued) {
if (callback) {
callback(events);
}
}
}, i=0;
for (; i<eventSources.length; i++) {
fetchEventSource(eventSources[i], sourceDone);
}
}
for (var i=0; i<sources.length; i++) {
_fetchEventSource(sources[i], sourceDone);
}
}


// Fetch from a particular source. Append to the 'events' array
function fetchEventSource(src, callback) {
var prevView = getView(),
prevDate = getDate(),
reportEvents = function(a) {
if (prevView == getView() && +prevDate == +getDate() && // protects from fast switching
$.inArray(src, eventSources) != -1) { // makes sure source hasn't been removed
for (var i=0; i<a.length; i++) {
normalizeEvent(a[i]);
a[i].source = src;
}
events = events.concat(a);
if (callback) {
callback(a);
}
}
},
reportEventsAndPop = function(a) {
reportEvents(a);
popLoading();
};
function _fetchEventSource(src, callback) {
function reportEvents(a) {
callback(src, a);
}
function reportEventsAndPop(a) {
reportEvents(a);
popLoading();
}
if (typeof src == 'string') {
var params = {};
params[options.startParam] = Math.round(eventStart.getTime() / 1000);
Expand Down Expand Up @@ -130,6 +135,11 @@ function EventManager(options, eventSources) {
}


function fetchEventSource(src, callback) {
fetchEventSources([src], callback);
}


function refetchEvents() {
fetchEvents(rerenderEvents);
}
Expand Down
1 change: 0 additions & 1 deletion tests/issue_417_refetchEvents.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel='stylesheet' type='text/css' href='../demos/redmond/theme.css' />
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>
Expand Down
50 changes: 50 additions & 0 deletions tests/issue_554.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>

$(document).ready(function() {

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
year: 2010,
month: 9,
date: 31,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaDay'
},
events: $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic')
});

});

</script>
<style type='text/css'>

body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}

#calendar {
width: 900px;
margin: 0 auto;
}

</style>
</head>
<body>
<button onclick="$('#calendar').fullCalendar('gotoDate',2010,10,11);$('#calendar').fullCalendar('changeView','agendaDay')">gotoDate + changeView</button>
<div id='calendar'></div>
</body>
</html>
57 changes: 57 additions & 0 deletions tests/issue_586_refetchEvents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>

$(document).ready(function() {

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
events: $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic')
});

});

function doit() {
var calendar = $('#calendar');
calendar.fullCalendar('removeEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('refetchEvents');
}

</script>
<style type='text/css'>

body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}

#calendar {
width: 900px;
margin: 0 auto;
}

</style>
</head>
<body>
<button onclick='doit()'>do it</button>
<div id='calendar'></div>
</body>
</html>
56 changes: 56 additions & 0 deletions tests/issue_616.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='../src/_loader.js?debug'></script>
<script type='text/javascript' src='../src/gcal/_loader.js'></script>
<script type='text/javascript'>

$(document).ready(function() {

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true
});

});


function doit() {
var calendar = $('#calendar');
var gcal = $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic');
calendar.fullCalendar('addEventSource', gcal);
calendar.fullCalendar('refetchEvents');
}


</script>
<style type='text/css'>

body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}

#calendar {
width: 900px;
margin: 0 auto;
}

</style>
</head>
<body>
<button onclick='doit()'>do it</button>
<div id='calendar'></div>
</body>
</html>

0 comments on commit 453fcf0

Please sign in to comment.