51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
function check(id) {
|
|
let checkbox = $("#task-" + id);
|
|
let uri = "/v1/undo";
|
|
if (checkbox.prop("checked")) {
|
|
uri = "/v1/do";
|
|
}
|
|
$.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)
|
|
}
|
|
});
|
|
}
|
|
|
|
function new_task() {
|
|
let input = $("#new-task-input");
|
|
$.post("/v1/new", {api_key: API_KEY, content: input.val()}, function(data, status) {
|
|
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)
|
|
}
|
|
});
|
|
input.val("");
|
|
return false; // prevent form submission
|
|
}
|
|
|
|
function new_api_key() {
|
|
$.get("/v1/key/new", function(data, status) {
|
|
let template = $("#api-key-template").html();
|
|
template = $(template);
|
|
$("code", template).text(data.api_key.key);
|
|
$("#new-api-key").before(template);
|
|
}).fail(function(a) {
|
|
console.log(a);
|
|
let template = $("#api-key-template").html();
|
|
template = $(template);
|
|
$("code", template).text("Failure!");
|
|
$("#new-api-key").before(template);
|
|
});
|
|
}
|
|
|
|
function delete_item(e) {
|
|
e = $(e);
|
|
while (!e.is("li")) {
|
|
e = e.parent();
|
|
}
|
|
e.remove();
|
|
}
|