mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-08-14 12:20:24 +08:00
removeEvents call with an array source doesn't persist (issue 2187)
This commit is contained in:
+42
-23
@@ -82,11 +82,21 @@ function EventManager(options) { // assumed to be a calendar
|
||||
|
||||
function fetchEventSource(source, fetchID) {
|
||||
_fetchEventSource(source, function(events) {
|
||||
var isArraySource = $.isArray(source.events);
|
||||
var i;
|
||||
var event;
|
||||
|
||||
if (fetchID == currentFetchID) {
|
||||
|
||||
if (events) {
|
||||
for (var i=0; i<events.length; i++) {
|
||||
var event = buildEvent(events[i], source);
|
||||
for (i=0; i<events.length; i++) {
|
||||
event = events[i];
|
||||
|
||||
// event array sources have already been convert to Event Objects
|
||||
if (!isArraySource) {
|
||||
event = buildEvent(event, source);
|
||||
}
|
||||
|
||||
if (event) {
|
||||
cache.push(event);
|
||||
}
|
||||
@@ -247,6 +257,14 @@ function EventManager(options) { // assumed to be a calendar
|
||||
}
|
||||
|
||||
if (source) {
|
||||
|
||||
// for array sources, we convert to standard Event Objects up front
|
||||
if ($.isArray(source.events)) {
|
||||
source.events = $.map(source.events, function(eventInput) {
|
||||
return buildEvent(eventInput, source);
|
||||
});
|
||||
}
|
||||
|
||||
for (i=0; i<normalizers.length; i++) {
|
||||
normalizers[i].call(t, source);
|
||||
}
|
||||
@@ -345,30 +363,31 @@ function EventManager(options) { // assumed to be a calendar
|
||||
|
||||
|
||||
function removeEvents(filter) {
|
||||
var eventID;
|
||||
var i;
|
||||
if (filter == null) { // null or undefined. remove all
|
||||
cache = [];
|
||||
// clear all array sources
|
||||
for (i=0; i<sources.length; i++) {
|
||||
if ($.isArray(sources[i].events)) {
|
||||
sources[i].events = [];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (!$.isFunction(filter)) { // an event ID
|
||||
var id = filter + '';
|
||||
filter = function(e) {
|
||||
return e._id == id;
|
||||
};
|
||||
}
|
||||
cache = $.grep(cache, filter, true);
|
||||
// remove events from array sources
|
||||
for (i=0; i<sources.length; i++) {
|
||||
if ($.isArray(sources[i].events)) {
|
||||
sources[i].events = $.grep(sources[i].events, filter, true);
|
||||
}
|
||||
|
||||
if (filter == null) { // null or undefined. remove all events
|
||||
filter = function() { return true; }; // will always match
|
||||
}
|
||||
else if (!$.isFunction(filter)) { // an event ID
|
||||
eventID = filter + '';
|
||||
filter = function(event) {
|
||||
return event._id == eventID;
|
||||
};
|
||||
}
|
||||
|
||||
// Purge event(s) from our local cache
|
||||
cache = $.grep(cache, filter, true); // inverse=true
|
||||
|
||||
// Remove events from array sources.
|
||||
// This works because they have been converted to official Event Objects up front.
|
||||
// (and as a result, event._id has been calculated).
|
||||
for (i=0; i<sources.length; i++) {
|
||||
if ($.isArray(sources[i].events)) {
|
||||
sources[i].events = $.grep(sources[i].events, filter, true);
|
||||
}
|
||||
}
|
||||
|
||||
reportEvents(cache);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user