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

@ -11,7 +11,7 @@
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
<script>
</script>
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<script src="/static/build/editor.js" type="text/javascript"></script>
@ -95,7 +95,7 @@
disabled><i class="fas fa-code"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('insertHorizontalRule')"><i
class="fas fa-grip-lines"></i></button>
<button class="btn btn-light" onclick="insertLink()"><i class="fas fa-link"></i></button>
</div>
@ -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>