Created
October 29, 2008 06:19
-
-
Save ngerakines/20639 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
Backpack = { | |
setUser:function(val){ | |
Application.prefs.setValue("backpack_user", val); | |
}, | |
setDomain:function(val){ | |
Application.prefs.setValue("backpack_domain", val); | |
}, | |
setToken:function(val){ | |
Application.prefs.setValue("backpack_token", val); | |
}, | |
getUser:function(){ | |
return Application.prefs.get("backpack_user").value; | |
}, | |
getDomain:function(){ | |
return Application.prefs.get("backpack_domain").value; | |
}, | |
getToken:function(){ | |
return Application.prefs.get("backpack_token").value; | |
}, | |
everythingIsOK:function(){ | |
return Application.prefs.has("backpack_user") | |
&& Application.prefs.has("backpack_domain") | |
&& Application.prefs.has("backpack_token"); | |
} | |
}; | |
CmdUtils.CreateCommand({ | |
name: "reminder", | |
takes: {reminder: noun_arb_text}, | |
author: {name: "Nick Gerakines", homepage: "http://socklabs.com/"}, | |
license: "MPL", | |
preview: function(previewBlock, reminderText) { | |
var previewTemplate = "Creates the new reminder: <br/><b>${reminder}</b><br /><br />"; | |
var previewData = { | |
reminder: reminderText.text | |
}; | |
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData); | |
previewBlock.innerHTML = previewHTML; | |
}, | |
execute: function(reminderText) { | |
if (! Backpack.everythingIsOK()) { | |
displayMessage("Please set your user, token and domain using the reminder-set* commands."); | |
return; | |
} | |
if (reminderText.text.length < 1) { | |
displayMessage("Reminders can't be empty."); | |
return; | |
} | |
if (reminderText.text.charAt(0) != '+') { | |
displayMessage("Reminders must include a fuzzy time (+5, +180, etc)."); | |
return; | |
} | |
var url = "http://" + Backpack.getDomain() + ".backpackit.com/" + Backpack.getToken() + "/reminders.xml"; | |
Components.utils.reportError(url); | |
var messageTemplate = '<reminder><content>${reminder}</content><remindees type="array"><user_id>${user}</user_id></remindees></reminder>'; | |
var messageData = { | |
reminder: reminderText.text, | |
user: Backpack.getUser() | |
}; | |
var messageXML = CmdUtils.renderTemplate(messageTemplate, messageData); | |
Components.utils.reportError(messageXML); | |
var req = new XMLHttpRequest(); | |
req.open("POST", url); | |
req.onreadystatechange=function() { | |
if (req.readyState == 4) { | |
displayMessage("Reminder created."); | |
Components.utils.reportError(req.responseText); | |
Components.utils.reportError(req.status); | |
} | |
} | |
req.setRequestHeader("Content-Type", "application/xml"); | |
req.send(messageXML); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "reminder-setuser", | |
takes: {user: noun_arb_text}, | |
author: {name: "Nick Gerakines", homepage: "http://socklabs.com/"}, | |
license: "MPL", | |
description: "Sets the user ID used by the 'reminder' command.", | |
help: "Type 'reminder-setuser <userid>'.", | |
execute: function(input) { | |
if(input.text.length < 1) { | |
displayMessage("Please, enter a value"); | |
return; | |
} | |
Backpack.setUser(input.text); | |
displayMessage("Your reminder user id has been set."); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "reminder-settoken", | |
takes: {token: noun_arb_text}, | |
author: {name: "Nick Gerakines", homepage: "http://socklabs.com/"}, | |
license: "MPL", | |
description: "Sets the API token used by the 'reminder' command.", | |
help: "Type 'reminder-settoken <API token>'.", | |
execute: function(input) { | |
if(input.text.length < 1) { | |
displayMessage("Please, enter a value"); | |
return; | |
} | |
Backpack.setToken(input.text); | |
displayMessage("Your reminder API token has been set."); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "reminder-setdomain", | |
takes: {domain: noun_arb_text}, | |
author: {name: "Nick Gerakines", homepage: "http://socklabs.com/"}, | |
license: "MPL", | |
description: "Sets the API domain used by the 'reminder' command.", | |
help: "Type 'reminder-settoken <domain>'.", | |
execute: function(input) { | |
if(input.text.length < 1) { | |
displayMessage("Please, enter a value"); | |
return; | |
} | |
Backpack.setDomain(input.text); | |
displayMessage("Your reminder domain has been set."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment