todos
This commit is contained in:
@@ -34,11 +34,12 @@
|
||||
</style>
|
||||
<script>
|
||||
function init() {
|
||||
/* TODO when no drawFile, disable editor or somethin */
|
||||
drawTree()
|
||||
setInterval(drawTree, 10000)
|
||||
var queryF = getParameterByName("f")
|
||||
console.log("init query f:", queryF)
|
||||
if (queryF && queryF.length != "") {
|
||||
if (!queryF || queryF.length == "") {
|
||||
drawFile(queryF)
|
||||
}
|
||||
}
|
||||
@@ -50,6 +51,25 @@
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||
}
|
||||
function pushFile() {
|
||||
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
||||
const body = easyMDE.value() ? easyMDE.value() : ""
|
||||
const id = easyMDE.meta.id ? easyMDE.meta.id : ""
|
||||
const pid = easyMDE.meta.pid ? easyMDE.meta.pid : ""
|
||||
var method = "PUT"
|
||||
if (id == "")
|
||||
method = "POST"
|
||||
headers = {}
|
||||
if (title)
|
||||
headers["Title"] = title
|
||||
if (pid)
|
||||
headers["Pid"] = pid
|
||||
http(method, "/api/v0/files" + (id == "" ? "" : "/"+id), (body, status) => {
|
||||
console.log(status, body)
|
||||
alert("todo")
|
||||
}, body, headers)
|
||||
drawTree()
|
||||
}
|
||||
function drawFile(id) {
|
||||
if (!id || id.length < 1) {
|
||||
return
|
||||
@@ -67,7 +87,7 @@
|
||||
setMDE("", pid, "", "")
|
||||
}
|
||||
function setMDE(id, pid, title, body) {
|
||||
console.log(`set MDE: id=${id}, pid=${pid}, title=${title}, body=${body}`)
|
||||
alert("TODO: set title as attr for prettier here")
|
||||
document.getElementById("titlePath").innerHTML = `${pid ? "... / " : ""}<a href="#?f=${pid}"><input type="button" value="${pid}" onclick="drawFile('${pid}');"></a> / `
|
||||
if (pid == "") {
|
||||
document.getElementById("titlePath").innerHTML = "/"
|
||||
@@ -81,6 +101,7 @@
|
||||
}
|
||||
function drawTree() {
|
||||
function htmlifyBranch(pid, id, branch) {
|
||||
/* TODO width limit title */
|
||||
var children = ""
|
||||
for (var child in branch.Children)
|
||||
children += "\n" + htmlifyBranch(id, child, branch.Children[child])
|
||||
@@ -109,7 +130,7 @@
|
||||
document.getElementById("tree").innerHTML = innerHTML
|
||||
})
|
||||
}
|
||||
function http(method, remote, callback, body) {
|
||||
function http(method, remote, callback, body, headers) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
||||
@@ -120,6 +141,10 @@
|
||||
if (typeof body == "undefined") {
|
||||
body = null
|
||||
}
|
||||
if (headers) {
|
||||
for (var key in headers)
|
||||
xmlhttp.setRequestHeader(key, headers[key])
|
||||
}
|
||||
xmlhttp.send(body);
|
||||
}
|
||||
</script>
|
||||
@@ -137,6 +162,7 @@
|
||||
<span id="titlePath">
|
||||
</span>
|
||||
<span id="title" contenteditable style="flex-grow: 1;"></span>
|
||||
<input type="submit" value="SAVE" onclick="pushFile(); return false;"/>
|
||||
</h1>
|
||||
<textarea id="my-text-area"></textarea>
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user