From 26f645e4dc4c0ccebad5fa5f06f188ff7ca61f99 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 9 Feb 2022 16:00:03 -0700 Subject: [PATCH] delete --- spike/review/reinvent/ezmded/ui/index.html | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/spike/review/reinvent/ezmded/ui/index.html b/spike/review/reinvent/ezmded/ui/index.html index 4c1ba08..7c1a051 100644 --- a/spike/review/reinvent/ezmded/ui/index.html +++ b/spike/review/reinvent/ezmded/ui/index.html @@ -50,6 +50,26 @@ if (!results[2]) return ''; 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() { const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : "" const body = easyMDE.value() ? easyMDE.value() : "" @@ -60,7 +80,7 @@ http("PUT", "/api/v0/files/" + id, (body, status) => { if (status != 200) { 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() drawFile(id) @@ -75,7 +95,7 @@ } http("GET", "/api/v0/files/"+id, (body, status, headers) => { if (status != 200) { - raise `ERR loading file: ${status}: ${body}` + throw `ERR loading file: ${status}: ${body}` } const title = headers("title") ? headers("title") : "" setMDE(id, title, body) @@ -141,7 +161,7 @@ } http("GET", "/api/v0/tree", (body, status) => { if (status != 200) - raise `bad status getting tree: ${status}: ${body}` + throw `bad status getting tree: ${status}: ${body}` const tree = JSON.parse(body) document.getElementById("tree").innerHTML = htmlifyBranch("", tree) }) @@ -176,6 +196,7 @@