tvon (owner)

Revisions

  • d89dd1 Tom von... Fri Feb 06 14:33:37 -0800 2009
  • 263665 Tom von... Fri Feb 06 14:11:05 -0800 2009
  • 667c3b Fri Feb 06 11:32:05 -0800 2009
gist: 59565 Download_button fork
public
Description:
Todoist plugin for Ubiquity
Public Clone URL: git://gist.github.com/59565.git
Embed All Files: show embed
ubiquity-todoist.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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.");
  }
});