Created
February 6, 2009 19:32
-
-
Save tvon/59565 to your computer and use it in GitHub Desktop.
Todoist plugin for Ubiquity
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
TODOIST_DUE = ""; | |
TODOIST_PRIORITY = 4; | |
Todoist = { | |
setToken:function(key){ | |
if (!Application.prefs.has("todoist_token")) { | |
Application.prefs.setValue("todoist_token", key); | |
} else { | |
var new_key = Application.prefs.get("todoist_token"); | |
new_key.value = key; | |
return new_key.value; | |
} | |
}, | |
setDefaultProject:function(key){ | |
if (!Application.prefs.has("todoist_default_project")) { | |
Application.prefs.setValue("todoist_default_project", key); | |
} else { | |
Application.prefs.setValue("todoist_default_project", key); | |
} | |
}, | |
getDefaultProject:function(){ | |
return Application.prefs.get("todoist_default_project").value; | |
}, | |
getToken:function(){ | |
return Application.prefs.get("todoist_token").value; | |
}, | |
everythingIsOK:function(){ | |
return Application.prefs.has("todoist_token") && Application.prefs.has("todoist_default_project"); | |
} | |
}; | |
CmdUtils.CreateCommand({ | |
name: "todo", | |
icon: "http://todoist.com/favicon.ico", | |
takes: {entry: noun_arb_text}, | |
homepage: "http://www.baltimoresquirrels.com/projects/todoist-plugin-for-ubiquity/", | |
author: { | |
name: "Tom von Schwerdtner", | |
homepage: "http://baltimoresquirrels.com/" | |
}, | |
license: "MPL", | |
preview: function(previewBlock, inputText) { | |
if (!Todoist.everythingIsOK()){ | |
previewBlock.innerHTML = "Something is wrong..."; | |
} else { | |
var previewTemplate = "Add entry to Todoist: <br/>" + | |
"<strong>${entry}</strong>"; | |
var previewData = { | |
entry: inputText.text | |
}; | |
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData); | |
//previewBlock.innerHTML = previewHTML; | |
previewBlock.innerHtml = Todoist.getDefaultProject(); | |
} | |
}, | |
execute: function(inputText) { | |
if(inputText.text.length < 1) { | |
displayMessage("Don't have anything to do eh? Must be nice!"); | |
return; | |
} | |
var addItemUrl = "http://todoist.com/API/addItem"; | |
var itemParams = { | |
token: Todoist.getToken(), | |
project_id: Todoist.getDefaultProject(), | |
content: inputText.text, | |
priority: TODOIST_PRIORITY | |
}; | |
if(TODOIST_DUE != "") itemParams.date_string = TODOIST_DUE; | |
res = jQuery.ajax({ | |
type: "POST", | |
url: addItemUrl, | |
data: itemParams, | |
dataType: "json", | |
error: function(XMLHttpRequest, textStatus, errorThrown) { | |
displayMessage("Todoist error - entry not added: " + XMLHttpRequest.responseText); | |
}, | |
success: function() { | |
displayMessage("Todoist entry added"); | |
} | |
}); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "todo-token", | |
takes: {token: noun_arb_text}, | |
icon: "http://todoist.com/favicon.ico", | |
homepage: "http://www.baltimoresquirrels.com/projects/todoist-plugin-for-ubiquity/", | |
author: { | |
name: "Tom von Schwerdtner", | |
homepage: "http://baltimoresquirrels.com/" | |
}, | |
license: "MPL", | |
description: "Set your Todoist API token. Check your web servies token at http://todoist.com", | |
help: "Type todo-setup <token>. Find your token in your account preferences under the 'Account' tab.", | |
execute: function(token) { | |
if(token.length < 1) { | |
displayMessage("Please, enter your web services token"); | |
return; | |
} | |
Todoist.setToken(token.text); | |
displayMessage("Your token has been set."); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "todo-project", | |
takes: {project: noun_arb_text}, | |
homepage: "http://www.baltimoresquirrels.com/projects/todoist-plugin-for-ubiquity/", | |
icon: "http://todoist.com/favicon.ico", | |
author: { | |
name: "Tom von Schwerdtner", | |
homepage: "http://baltimoresquirrels.com/" | |
}, | |
license: "MPL", | |
description: "Set the default project for todo entries.", | |
help: "Type todo-project <project id>. You can find a project id by looking at the URL of a project when viewing it..", | |
execute: function(project) { | |
if(project.length < 1) { | |
displayMessage("Please, enter a project id"); | |
return; | |
} | |
Todoist.setDefaultProject(project.text); | |
displayMessage("Your default project has been set."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment