';
@@ -179,13 +195,26 @@ function readFileB64(file) {
}
document.getElementById("books").addEventListener("click", async function (e) {
- var pick = e.target.getAttribute("data-pick");
- var del = e.target.getAttribute("data-del");
+ var t = e.target;
+ var pick = t.getAttribute("data-pick"), del = t.getAttribute("data-del");
+ var edit = t.getAttribute("data-edit"), save = t.getAttribute("data-save");
+ if (t.getAttribute("data-cancel")) { EDIT = null; paintBooks(); return; }
+ if (edit) { EDIT = edit; paintBooks(); return; }
+ if (save) {
+ var title = document.getElementById("rt").value.trim();
+ var author = document.getElementById("ra").value.trim();
+ if (!title) { showMsg("msg", "A book needs a title."); return; }
+ t.disabled = true;
+ var u = await api("update_book", { book_id: save, title: title, author: author });
+ if (!u.ok) { showMsg("msg", u.error || "That did not save."); t.disabled = false; return; }
+ hideMsg("msg"); EDIT = null; loadBooks();
+ return;
+ }
if (pick) { PICKED = pick; hideMsg("msg"); paintBooks(); paintQuote(); return; }
if (del) {
- e.target.disabled = true;
+ t.disabled = true;
var r = await api("delete_book", { book_id: del });
- if (!r.ok) { showMsg("msg", r.error || "Could not remove that."); e.target.disabled = false; return; }
+ if (!r.ok) { showMsg("msg", r.error || "Could not remove that."); t.disabled = false; return; }
if (PICKED === del) PICKED = null;
loadBooks();
}
@@ -227,6 +256,9 @@ function readFileB64(file) {
resetPick();
if (!r.ok) { showMsg("msg", r.error || "That upload did not go through."); return; }
PICKED = null;
+ // Straight into rename: the derived title is a guess and this is the one
+ // moment the author is looking at it.
+ EDIT = r.book && r.book.id;
loadBooks();
}
@@ -275,7 +307,7 @@ function readFileB64(file) {
// Writing is the cheap half. Drawing the storyboards is priced separately,
// per writer, once you have read the scripts.
el.innerHTML = n + " writer" + (n > 1 ? "s" : "")
- + " · about $" + (n * 0.6).toFixed(2) + " to write"
+ + " · about $" + (n * 0.85).toFixed(2) + " to write a full-length novel"
+ " · storyboards are priced separately once you have read them";
}