Move delete functio javascript back into html

The {{.Filename}} does not propogate to the javascript files
This commit is contained in:
James Musselman 2023-11-29 23:50:13 -06:00
parent 9ce0d02be7
commit 9e04cd43b0
2 changed files with 34 additions and 31 deletions

View file

@ -88,12 +88,6 @@ function confirmOverwrite() {
}
}
function confirmDeletion() {
if (confirm("Are you sure you want to delete {{.Filename}}?")) {
const filename = "{{.Filename}}";
deleteFile(filename);
}
}
// Function to focus on the editor when body is clicked
function focusOnEditor() {
@ -241,27 +235,6 @@ function addVideo() {
}
}
function deleteFile(filename) {
// Send a POST request to the server to delete the specified file
fetch("/delete", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ files: [filename] }),
})
.then(response => {
if (response.ok) {
window.location.replace("/home");
} else {
// Handle the error, e.g., display an error message
console.error("Error deleting file");
}
})
.catch(error => {
console.error("Error deleting file:", error);
});
}
function insertLink() {
var url = prompt('Enter the URL:');

View file

@ -166,13 +166,43 @@
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="document.getElementById('tableModal').style.display = 'none'">Cancel</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"
onclick="document.getElementById('tableModal').style.display = 'none'">Cancel</button>
<button type="button" class="btn btn-primary" onclick="createTable()">Create Table</button>
</div>
</div>
</div>
</div>
<script>
// The deletion is kept here as I (Musselman) have not found a way to implement the {{.Filename}} into the javascript.
function confirmDeletion() {
if (confirm("Are you sure you want to delete {{.Filename}}?")) {
const filename = "{{.Filename}}";
deleteFile(filename);
}
}
function deleteFile(filename) {
// Send a POST request to the server to delete the specified file
fetch("/delete", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ files: [filename] }),
})
.then(response => {
if (response.ok) {
window.location.replace("/home");
} else {
// Handle the error, e.g., display an error message
console.error("Error deleting file");
}
})
.catch(error => {
console.error("Error deleting file:", error);
});
}
</script>
</body>