forked from MarseyWorld/MarseyWorld
[post editing] hide upload progress when error
parent
6872f7760b
commit
c34df79b7c
|
@ -312,7 +312,7 @@ function reload() {
|
|||
location.reload();
|
||||
}
|
||||
|
||||
function setupFormXhr(form, extraActionsOnSuccess) {
|
||||
function sendFormXHR(form, extraActionsOnSuccess, upload_prog) {
|
||||
if (typeof close_inline_emoji_modal === "function") {
|
||||
close_inline_emoji_modal();
|
||||
}
|
||||
|
@ -323,6 +323,9 @@ function setupFormXhr(form, extraActionsOnSuccess) {
|
|||
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
upload_prog = document.getElementById(upload_prog);
|
||||
xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
|
||||
|
||||
formData = new FormData(form);
|
||||
|
||||
formData.append("formkey", formkey());
|
||||
|
@ -332,6 +335,8 @@ function setupFormXhr(form, extraActionsOnSuccess) {
|
|||
xhr.setRequestHeader('xhr', 'xhr');
|
||||
|
||||
xhr.onload = function() {
|
||||
upload_prog.classList.add("d-none")
|
||||
|
||||
const success = xhr.status >= 200 && xhr.status < 300;
|
||||
|
||||
if (!(extraActionsOnSuccess == reload && success)) {
|
||||
|
@ -354,11 +359,6 @@ function setupFormXhr(form, extraActionsOnSuccess) {
|
|||
form.classList.remove('is-submitting');
|
||||
};
|
||||
|
||||
return xhr
|
||||
}
|
||||
|
||||
function sendFormXHR(form, extraActionsOnSuccess) {
|
||||
const xhr = setupFormXhr(form, extraActionsOnSuccess);
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
|
@ -373,8 +373,8 @@ function sendFormXHRSwitch(form) {
|
|||
)
|
||||
}
|
||||
|
||||
function sendFormXHRReload(form) {
|
||||
sendFormXHR(form, reload)
|
||||
function sendFormXHRReload(form, upload_prog) {
|
||||
sendFormXHR(form, reload, upload_prog)
|
||||
}
|
||||
|
||||
let sortAscending = {};
|
||||
|
|
|
@ -46,11 +46,4 @@ if (fake_textarea) {
|
|||
fake_textarea.addEventListener('click', () => {
|
||||
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);
|
||||
}
|
|
@ -215,7 +215,7 @@
|
|||
|
||||
{% if v and v.can_edit(p) %}
|
||||
<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="current_page" value="{{request.path}}">
|
||||
|
||||
|
|
Loading…
Reference in New Issue