delete button works, server returns 302 over 301 so browser cache is less bad, ui sorts filetree alpha by title

This commit is contained in:
Bel LaPointe
2022-02-16 08:49:45 -07:00
parent e025f3835a
commit 51bd874063
4 changed files with 24 additions and 11 deletions

View File

@@ -43,7 +43,7 @@
function pushFile() {
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
const body = easyMDE.value() ? easyMDE.value() : ""
const id = window.location.pathname.includes("/ui/files/") ? window.location.pathname.split("/ui/files/")[1] : ""
const id = {{ js .This.ID }}
headers = {}
if (title)
headers["Title"] = title
@@ -59,6 +59,17 @@
saveFeedbackInterval = setTimeout(() => {document.getElementById("saveFeedback").innerHTML = ""}, 5000)
}, body, headers)
}
function deleteFile() {
const id = {{ js .This.ID }}
const pid = {{ js .This.PID }}
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}`
}
window.location.href = `${window.location.protocol}\/\/${window.location.host}/ui/files/${pid}`
})
}
</script>
<div class="fullscreen tb_fullscreen">
<article id="article">
@@ -76,8 +87,8 @@
</span>
<span id="title" class="thic_flex" contenteditable>{{ .This.Title }}</span>
<span class="l_buffer">
<form action="" method="delete" onsubmit="return confirm('are you sure?');"> <!-- TODO -->
<input class="button-error lil_btn" type="submit" value="DELETE"/>
<form onsubmit="deleteFile(); return false;"> <!-- TODO -->
<input class="button-error lil_btn" type="submit" onclick="confirm('are you sure?');" value="DELETE"/>
</form>
</span>
</div>