-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline delete process for all deletable items
- Loading branch information
Showing
9 changed files
with
36 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
"user strict" | ||
|
||
const deleteModal = document.getElementById('deleteModal'); | ||
const deleteForm = document.getElementById('delete-form'); | ||
|
||
deleteModal.addEventListener('show.bs.modal', event => { | ||
const link = event.relatedTarget; | ||
const slug = link.getAttribute('data-bs-slug'); | ||
const modalInputSlug = deleteModal.querySelector('.slug'); | ||
const link = event.relatedTarget | ||
const id = link.getAttribute('data-id') | ||
const modalInput = deleteModal.querySelector('.id') | ||
|
||
modalInputSlug.value = slug; | ||
modalInput.value = id; | ||
}) | ||
|
||
deleteModal.addEventListener('hidden.bs.modal', event => { | ||
let message = document.getElementById('delete-document-message'); | ||
let message = document.getElementById('error-message-container'); | ||
message.classList.add("visually-hidden"); | ||
}) | ||
|
||
function remove(errorMessage) { | ||
deleteForm.addEventListener('submit', event => { | ||
event.preventDefault(); | ||
form = document.getElementById("delete-form"); | ||
fetch('/document', { | ||
fetch(deleteForm.getAttribute("action"), { | ||
method: "DELETE", | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
body: new URLSearchParams({ | ||
'slug': form.elements['slug'].value, | ||
'id': deleteForm.elements['id'].value, | ||
}) | ||
}) | ||
.then((response) => { | ||
if (response.ok) { | ||
location.reload(); | ||
} else { | ||
message = document.getElementById("delete-document-message") | ||
message = document.getElementById("error-message-container") | ||
message.classList.remove("visually-hidden"); | ||
message.innerHTML = errorMessage; | ||
message.innerHTML = deleteForm.getAttribute("data-error-message"); | ||
} | ||
}) | ||
.catch(function (error) { | ||
// Catch errors | ||
console.log(error); | ||
}); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters