Created
September 14, 2008 04:52
-
-
Save fernandotakai/10708 to your computer and use it in GitHub Desktop.
This file contains 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
function addToGoogleCalendar(eventString) { | |
var quickAddEntry = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gCal='http://schemas.google.com/gCal/2005'>"; | |
quickAddEntry += " <content type=\"html\">" + eventString + "</content>"; | |
quickAddEntry += " <gCal:quickadd value=\"true\"/>"; | |
quickAddEntry += "</entry>"; | |
var authKey = Utils.getCookie(".www.google.com", "CAL"); | |
if (authKey == "") { | |
displayMessage("Please make sure you are logged in to Google Calendar"); | |
return; | |
} | |
var currentCalendar = "http://www.google.com/calendar/feeds/default/private/full"; | |
var req = new XMLHttpRequest(); | |
req.open('POST', currentCalendar, false); | |
req.setRequestHeader('Authorization', 'GoogleLogin auth=' + authKey); | |
req.setRequestHeader('Content-type', 'application/atom+xml'); | |
req.send(quickAddEntry); | |
if (req.status == 401) { | |
displayMessage("Please make sure you are logged in to Google Calendar"); | |
return; | |
} else if (req.status != 201) { | |
displayMessage("Error creating the event. Error code: " + req.status + " " + req.statusText); | |
return; | |
} else { | |
displayMessage("Created event " + eventString); | |
} | |
} | |
CmdUtils.CreateCommand({ | |
name: "add-calendar", | |
takes: {"event": noun_arb_text}, // TODO: use DateNounType or EventNounType? | |
modifiers: {'on': noun_type_date, 'at': noun_type_time }, | |
icon : "chrome://ubiquity/skin/icons/calendar_add.png", | |
preview: "Adds the event to Google Calendar.<br/> Enter the event with the format event on date at time", | |
description: "Adds an event to your calendar.", | |
help: "Currently, only works with <a href=\"http://calendar.google.com\">Google Calendar</a>, so you'll need a " + | |
"Google account to use it. Try issuing "add lunch with dan on tomorrow at 14pm".", | |
execute: function( eventString, modifiers ) { | |
var calEvent = eventString.text + " " + modifiers.on.data.toString("dd/MM/yyyy") + " " + modifiers.at.text | |
addToGoogleCalendar( calEvent ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment