2018-04-23 12:22:27 +00:00
|
|
|
function check(id) {
|
2018-04-24 22:02:13 +00:00
|
|
|
let checkbox = $("#task-" + id);
|
|
|
|
let uri = "/v1/undo";
|
|
|
|
if (checkbox.prop("checked")) {
|
|
|
|
uri = "/v1/do";
|
2018-04-23 12:22:27 +00:00
|
|
|
}
|
2018-04-24 22:02:13 +00:00
|
|
|
$.post(uri, {api_key: API_KEY, id: id}, function(data, status) {
|
|
|
|
if (status == "success") {
|
|
|
|
checkbox.prop("checked", data.task.done);
|
|
|
|
} else {
|
|
|
|
console.log(data); // NOTE TEMPORARY (need to handle errors better)
|
|
|
|
}
|
|
|
|
});
|
2018-04-23 12:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function new_task() {
|
2018-04-24 22:02:13 +00:00
|
|
|
let input = $("#new-task-input");
|
2018-04-24 22:56:40 +00:00
|
|
|
$.post("/v1/new", {api_key: API_KEY, content: input.val()}, function(data, status) {
|
2018-04-24 22:02:13 +00:00
|
|
|
if (status == "success") {
|
|
|
|
$("#new-task").before("<li><input type='checkbox' id='task-" + data.task.id + "' onchange='check(" + data.task.id + ")'> " + data.task.content + "</li>");
|
|
|
|
} else {
|
|
|
|
console.log(data); // NOTE TEMPORARY (need to handle errors better)
|
2018-04-23 12:22:27 +00:00
|
|
|
}
|
2018-04-24 22:02:13 +00:00
|
|
|
});
|
2018-04-24 22:56:40 +00:00
|
|
|
input.val("");
|
2018-04-23 12:22:27 +00:00
|
|
|
return false; // prevent form submission
|
|
|
|
}
|
|
|
|
|
|
|
|
function new_api_key() {
|
2018-04-24 22:56:40 +00:00
|
|
|
$.get("/v1/key/new", function(data, status) {
|
2018-04-24 23:04:37 +00:00
|
|
|
let template = $("#api-key-template").html();
|
2018-04-24 23:09:49 +00:00
|
|
|
template = $(template);
|
2018-04-24 23:04:37 +00:00
|
|
|
$("code", template).text(data.api_key.key);
|
|
|
|
$("#new-api-key").before(template);
|
|
|
|
}).fail(function(a) {
|
|
|
|
console.log(a);
|
|
|
|
let template = $("#api-key-template").html();
|
2018-04-24 23:09:49 +00:00
|
|
|
template = $(template);
|
2018-04-24 23:04:37 +00:00
|
|
|
$("code", template).text("Failure!");
|
|
|
|
$("#new-api-key").before(template);
|
2018-04-24 22:02:13 +00:00
|
|
|
});
|
2018-04-23 12:22:27 +00:00
|
|
|
}
|
2018-04-24 22:56:40 +00:00
|
|
|
|
|
|
|
function delete_item(e) {
|
|
|
|
e = $(e);
|
|
|
|
while (!e.is("li")) {
|
|
|
|
e = e.parent();
|
|
|
|
}
|
|
|
|
e.remove();
|
|
|
|
}
|