[post editing] hide upload progress when error

master
Aevann 2024-11-14 01:23:49 +02:00
parent 6872f7760b
commit c34df79b7c
3 changed files with 9 additions and 16 deletions

View File

@ -312,7 +312,7 @@ function reload() {
location.reload(); location.reload();
} }
function setupFormXhr(form, extraActionsOnSuccess) { function sendFormXHR(form, extraActionsOnSuccess, upload_prog) {
if (typeof close_inline_emoji_modal === "function") { if (typeof close_inline_emoji_modal === "function") {
close_inline_emoji_modal(); close_inline_emoji_modal();
} }
@ -323,6 +323,9 @@ function setupFormXhr(form, extraActionsOnSuccess) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
upload_prog = document.getElementById(upload_prog);
xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
formData = new FormData(form); formData = new FormData(form);
formData.append("formkey", formkey()); formData.append("formkey", formkey());
@ -332,6 +335,8 @@ function setupFormXhr(form, extraActionsOnSuccess) {
xhr.setRequestHeader('xhr', 'xhr'); xhr.setRequestHeader('xhr', 'xhr');
xhr.onload = function() { xhr.onload = function() {
upload_prog.classList.add("d-none")
const success = xhr.status >= 200 && xhr.status < 300; const success = xhr.status >= 200 && xhr.status < 300;
if (!(extraActionsOnSuccess == reload && success)) { if (!(extraActionsOnSuccess == reload && success)) {
@ -354,11 +359,6 @@ function setupFormXhr(form, extraActionsOnSuccess) {
form.classList.remove('is-submitting'); form.classList.remove('is-submitting');
}; };
return xhr
}
function sendFormXHR(form, extraActionsOnSuccess) {
const xhr = setupFormXhr(form, extraActionsOnSuccess);
xhr.send(formData); xhr.send(formData);
} }
@ -373,8 +373,8 @@ function sendFormXHRSwitch(form) {
) )
} }
function sendFormXHRReload(form) { function sendFormXHRReload(form, upload_prog) {
sendFormXHR(form, reload) sendFormXHR(form, reload, upload_prog)
} }
let sortAscending = {}; let sortAscending = {};

View File

@ -47,10 +47,3 @@ if (fake_textarea) {
location.href = fake_textarea.dataset.href; location.href = fake_textarea.dataset.href;
}); });
} }
function edit_post(form) {
const xhr = setupFormXhr(form, reload);
const upload_prog = document.getElementById('upload-prog-edit-post');
xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
xhr.send(formData);
}

View File

@ -215,7 +215,7 @@
{% if v and v.can_edit(p) %} {% if v and v.can_edit(p) %}
<div id="edit-post-body-{{p.id}}" class="d-none comment-write collapsed child"> <div id="edit-post-body-{{p.id}}" class="d-none comment-write collapsed child">
<form id="post-edit-form-{{p.id}}" action="/edit_post/{{p.id}}" method="post" enctype="multipart/form-data" data-nonce="{{g.nonce}}" data-onsubmit="edit_post(this)"> <form id="post-edit-form-{{p.id}}" action="/edit_post/{{p.id}}" method="post" enctype="multipart/form-data" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRReload(this, 'upload-prog-edit-post')">
<input hidden name="formkey" value="{{v|formkey}}" class="notranslate" translate="no"> <input hidden name="formkey" value="{{v|formkey}}" class="notranslate" translate="no">
<input hidden name="current_page" value="{{request.path}}"> <input hidden name="current_page" value="{{request.path}}">