delete
parent
ae7f9e18a8
commit
26f645e4dc
|
|
@ -50,6 +50,26 @@
|
||||||
if (!results[2]) return '';
|
if (!results[2]) return '';
|
||||||
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||||
}
|
}
|
||||||
|
function deleteFile() {
|
||||||
|
if (!confirm("would you like to delete this file?"))
|
||||||
|
return
|
||||||
|
const id = easyMDE.meta.id
|
||||||
|
if (!id || id.length == 0)
|
||||||
|
return
|
||||||
|
http("DELETE", "/api/v0/files/" + id, (body, status) => {
|
||||||
|
if (status != 200) {
|
||||||
|
alert(`failed to delete file ${id}: ${status}: ${body}`)
|
||||||
|
throw `failed to delete file ${id}: ${status}: ${body}`
|
||||||
|
}
|
||||||
|
drawTree()
|
||||||
|
var pid = id.slice(0, id.lastIndexOf("/"))
|
||||||
|
if (pid) {
|
||||||
|
drawFile(pid)
|
||||||
|
} else {
|
||||||
|
disableMDE()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
function pushFile() {
|
function pushFile() {
|
||||||
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
||||||
const body = easyMDE.value() ? easyMDE.value() : ""
|
const body = easyMDE.value() ? easyMDE.value() : ""
|
||||||
|
|
@ -60,7 +80,7 @@
|
||||||
http("PUT", "/api/v0/files/" + id, (body, status) => {
|
http("PUT", "/api/v0/files/" + id, (body, status) => {
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
alert(`failed to push file ${id}: ${status}: ${body}`)
|
alert(`failed to push file ${id}: ${status}: ${body}`)
|
||||||
raise `failed to push file ${id}: ${status}: ${body}`
|
throw `failed to push file ${id}: ${status}: ${body}`
|
||||||
}
|
}
|
||||||
drawTree()
|
drawTree()
|
||||||
drawFile(id)
|
drawFile(id)
|
||||||
|
|
@ -75,7 +95,7 @@
|
||||||
}
|
}
|
||||||
http("GET", "/api/v0/files/"+id, (body, status, headers) => {
|
http("GET", "/api/v0/files/"+id, (body, status, headers) => {
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
raise `ERR loading file: ${status}: ${body}`
|
throw `ERR loading file: ${status}: ${body}`
|
||||||
}
|
}
|
||||||
const title = headers("title") ? headers("title") : ""
|
const title = headers("title") ? headers("title") : ""
|
||||||
setMDE(id, title, body)
|
setMDE(id, title, body)
|
||||||
|
|
@ -141,7 +161,7 @@
|
||||||
}
|
}
|
||||||
http("GET", "/api/v0/tree", (body, status) => {
|
http("GET", "/api/v0/tree", (body, status) => {
|
||||||
if (status != 200)
|
if (status != 200)
|
||||||
raise `bad status getting tree: ${status}: ${body}`
|
throw `bad status getting tree: ${status}: ${body}`
|
||||||
const tree = JSON.parse(body)
|
const tree = JSON.parse(body)
|
||||||
document.getElementById("tree").innerHTML = htmlifyBranch("", tree)
|
document.getElementById("tree").innerHTML = htmlifyBranch("", tree)
|
||||||
})
|
})
|
||||||
|
|
@ -176,6 +196,7 @@
|
||||||
<article id="article" style="display: none; flex-grow: 1; margin-left: 1em;">
|
<article id="article" style="display: none; flex-grow: 1; margin-left: 1em;">
|
||||||
<div>
|
<div>
|
||||||
<h1 style="display: flex; flex-direction: row;">
|
<h1 style="display: flex; flex-direction: row;">
|
||||||
|
<input type="submit" value="DELETE" onclick="deleteFile(); return false;" style="margin-left: 5%; margin-right: 5%"/>
|
||||||
<span id="titlePath">
|
<span id="titlePath">
|
||||||
</span>
|
</span>
|
||||||
<span id="title" contenteditable style="flex-grow: 1;"></span>
|
<span id="title" contenteditable style="flex-grow: 1;"></span>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue