Merge branch 'loader' into devNachCSRF
This commit is contained in:
+38
-1
@@ -11,7 +11,19 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
const parentCommentInput = document.getElementById("parent-comment-id");
|
||||
const replyInfo = document.getElementById("reply-info");
|
||||
|
||||
if (!form || !commentsList || !commentContent || !parentCommentInput) {
|
||||
const submitButton = form
|
||||
? form.querySelector('button[type="submit"]')
|
||||
: null;
|
||||
|
||||
const loadingMessage = document.getElementById("comment-loading");
|
||||
|
||||
if (
|
||||
!form
|
||||
|| !commentsList
|
||||
|| !commentContent
|
||||
|| !parentCommentInput
|
||||
|| !submitButton
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,6 +65,23 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
/*
|
||||
* Verhindert einen erneuten Submit, während der vorherige
|
||||
* Kommentar noch gespeichert wird.
|
||||
*/
|
||||
if (submitButton.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const originalButtonText = submitButton.textContent;
|
||||
|
||||
submitButton.disabled = true;
|
||||
submitButton.textContent = "Wird gesendet …";
|
||||
|
||||
if (loadingMessage) {
|
||||
loadingMessage.hidden = false;
|
||||
}
|
||||
|
||||
const formData = new FormData(form);
|
||||
const parentCommentId = parentCommentInput.value;
|
||||
|
||||
@@ -293,6 +322,14 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
.catch(function (error) {
|
||||
console.error(error);
|
||||
alert("Kommentar konnte nicht gesendet werden.");
|
||||
})
|
||||
.finally(function () {
|
||||
submitButton.disabled = false;
|
||||
submitButton.textContent = originalButtonText;
|
||||
|
||||
if (loadingMessage) {
|
||||
loadingMessage.hidden = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user