Skip to content

Instantly share code, notes, and snippets.

@millermedeiros
Created September 27, 2014 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save millermedeiros/4e4bddace293b16ae660 to your computer and use it in GitHub Desktop.
Save millermedeiros/4e4bddace293b16ae660 to your computer and use it in GitHub Desktop.
gaia calendar helpers
// jshint esnext:true
var app = Calendar.App;
var busyStore = app.store('Busytime');
var calendarStore = app.store('Calendar');
var eventStore = app.store('Event');
var syncController = app.syncController;
// this will delete all the events/busytimes from all calendars.
// triggering a new sync will fetch all the busytimes/ical data and expand
// all the busytimes again.
function removeAllEvents() {
// easier to get the calendar ids by the busytimes :P
busyStore.loadSpan(new Calendar.Timespan(0, Infinity), (err, busies) => {
var eventIds = new Set(busies.map(b => b.eventId));
eventIds.forEach(id => eventStore.remove(id));
});
// also need to remove any sync info so next sync will get all the data and
// expand the components
calendarStore.all((err, calendars) => {
// for some weird reason for..in wasn't working, so Object.keys FTW!
Object.keys(calendars).map(k => calendars[k]).forEach(c => {
c.firstEventSyncDate = null;
c.lastEventSyncDate = null;
c.lastEventSyncToken = '';
if (c.remote) {
c.remote.syncToken = '';
}
calendarStore.persist(c);
});
});
}
// sync all calendars
function sync() {
syncController.all();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment