Created
September 27, 2014 21:37
-
-
Save millermedeiros/4e4bddace293b16ae660 to your computer and use it in GitHub Desktop.
gaia calendar helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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