testing partial rewrite to new_task()
This commit is contained in:
parent
507c22c116
commit
2594301414
@ -15,12 +15,17 @@ function check(id) {
|
|||||||
|
|
||||||
function new_task() {
|
function new_task() {
|
||||||
let input = $("#new-task-input");
|
let input = $("#new-task-input");
|
||||||
$.post("/v1/new", {api_key: API_KEY, content: input.val()}, function(data, status) {
|
let template = $("#task-template").html();
|
||||||
if (status == "success") {
|
template = $(template);
|
||||||
$("#new-task").before("<li><input type='checkbox' id='task-" + data.task.id + "' onchange='check(" + data.task.id + ")'> " + data.task.content + "</li>");
|
$.post("/v1/new", {api_key: API_KEY, content: input.val()}, function(data) {
|
||||||
} else {
|
// $("#new-task").before("<li><input type='checkbox' id='task-" + data.task.id + "' onchange='check(" + data.task.id + ")'> " + data.task.content + "</li>");
|
||||||
console.log(data); // NOTE TEMPORARY (need to handle errors better)
|
let input = $("input", template);
|
||||||
}
|
input.prop("id", "task-" + data.task.id);
|
||||||
|
input.prop("onchange", "check('" + data.task.id + "')");
|
||||||
|
input.after(data.task.content); // not sure if will work
|
||||||
|
})
|
||||||
|
.fail(function(request) {
|
||||||
|
// TODO handle error
|
||||||
});
|
});
|
||||||
input.val("");
|
input.val("");
|
||||||
return false; // prevent form submission
|
return false; // prevent form submission
|
||||||
@ -32,12 +37,13 @@ function new_api_key() {
|
|||||||
$.get("/v1/key/new", function(data) {
|
$.get("/v1/key/new", function(data) {
|
||||||
$("code", template).text(data.api_key.key);
|
$("code", template).text(data.api_key.key);
|
||||||
$("#new-api-key").before(template);
|
$("#new-api-key").before(template);
|
||||||
}).fail(function() {
|
})
|
||||||
$("code", template)
|
.fail(function(request) {
|
||||||
.css("background-color", "red")
|
$("code", template)
|
||||||
.css("color", "white")
|
.css("background-color", "red")
|
||||||
.text(this.responseJSON.errors.join(" "));
|
.css("color", "white")
|
||||||
$("#new-api-key").before(template);
|
.text(request.responseJSON.errors.join(" "));
|
||||||
|
$("#new-api-key").before(template);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user