draw new file button stubbed

master
Bel LaPointe 2022-02-08 17:01:07 -07:00
parent 867da930a4
commit 7b51fd077d
1 changed files with 26 additions and 18 deletions

View File

@ -35,11 +35,7 @@
<script>
function init() {
drawTree()
function drawTreeLoop() {
drawTree()
setInterval(drawTreeLoop, 10000)
}
drawTreeLoop()
setInterval(drawTree, 10000)
var queryF = getParameterByName("f")
console.log("init query f:", queryF)
if (queryF && queryF.length != "") {
@ -62,26 +58,38 @@
if (status != 200) {
throw Exception(`ERR loading file: ${status}: ${body}`)
}
const pid = headers("pid")
document.getElementById("titlePath").innerHTML = `${pid ? "... / " : ""}<a href="#?f=${pid ? pid : ""}"><input type="button" value="${pid ? pid : ""}" onclick="drawFile('${pid}');"></a> / `
if (!pid) {
document.getElementById("titlePath").innerHTML = "/"
}
document.getElementById("title").innerHTML = headers("title")
easyMDE.value(body)
const pid = headers("pid") ? headers("pid") : ""
const title = headers("title") ? headers("title") : ""
setMDE(id, pid, title, body)
})
}
function drawNewFile(pid) {
setMDE("", pid, "", "")
}
function setMDE(id, pid, title, body) {
console.log(`set MDE: id=${id}, pid=${pid}, title=${title}, body=${body}`)
document.getElementById("titlePath").innerHTML = `${pid ? "... / " : ""}<a href="#?f=${pid}"><input type="button" value="${pid}" onclick="drawFile('${pid}');"></a> / `
if (pid == "") {
document.getElementById("titlePath").innerHTML = "/"
}
document.getElementById("title").innerHTML = title
easyMDE.value(body)
easyMDE.meta = {
id: id,
pid: pid,
}
}
function drawTree() {
function htmlifyBranch(id, branch) {
function htmlifyBranch(pid, id, branch) {
var children = ""
for (var child in branch.Children)
children += "\n" + htmlifyBranch(child, branch.Children[child])
children += "\n" + htmlifyBranch(id, child, branch.Children[child])
return `
<details open>
<summary>
<div>
<a href="#?f=${id}"><input type="button" value="${branch.Title}" onclick="drawFile('${id}');"/></a>
<input type="button" value="+" onclick="alert('todo'); return false;"/>
<input type="button" value="+" onclick="drawNewFile('${id}');"/>
</div>
</summary>
${children}
@ -92,9 +100,9 @@
const tree = JSON.parse(body)
var innerHTML = ""
for(var id in tree) {
innerHTML += htmlifyBranch(id, tree[id])
innerHTML += htmlifyBranch("", id, tree[id])
}
innerHTML = htmlifyBranch("", {
innerHTML = htmlifyBranch("", "", {
Title: "Files",
Children: {},
}).replace("</summary>", "</summary>"+innerHTML)
@ -119,7 +127,7 @@
<body style="width: 90%; max-width: 1024px; margin: auto;" onload="init(); return false;">
<div style="width: 100%; display: flex; flex-direction: column;">
<div style="margin: 1em; display: flex; flex-direction: row;">
<input type="text" style="flex-grow: 1;" placeholder="not impl"/>
<input type="text" style="flex-grow: 1;" placeholder="todo"/>
<input type="submit" value="search"/>
</div>
<div style="width: 100%; display: flex; flex-direction: row; flex-grow: 1;">