From 32f079ed204d3b3450b7ea12a8c6212068bd1128 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 3 Nov 2022 17:38:46 +0200 Subject: [PATCH] make post approval and removal effects only happen when response code is between 200 and 300 --- files/assets/js/submission_admin.js | 69 ++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/files/assets/js/submission_admin.js b/files/assets/js/submission_admin.js index 544f6c8e7..fba6794bc 100644 --- a/files/assets/js/submission_admin.js +++ b/files/assets/js/submission_admin.js @@ -1,31 +1,56 @@ function removePost(t,post_id,button1,button2,cls) { url="/remove_post/"+post_id - postToast(t,url,button1,button2,cls) + t.disabled = true; + t.classList.add("disabled"); + postToast_callback(url, + { + }, + (xhr) => { + if (xhr.status >= 200 && xhr.status < 300) { + if (window.location.pathname == '/admin/reported/posts') + { + document.getElementById("flaggers-"+post_id).remove() + document.getElementById("post-"+post_id).remove() + } + else + { + document.getElementById("post-"+post_id).classList.add("banned"); + document.getElementById(button1).classList.toggle(cls); + document.getElementById(button2).classList.toggle(cls); + } + } + t.disabled = false; + t.classList.remove("disabled"); + } + ); +} - if (window.location.pathname == '/admin/reported/posts') - { - document.getElementById("flaggers-"+post_id).remove() - document.getElementById("post-"+post_id).remove() - } - else - { - document.getElementById("post-"+post_id).classList.add("banned"); - } -}; function approvePost(t,post_id,button1,button2,cls) { url="/approve_post/"+post_id - postToast(t,url,button1,button2,cls) - - if (window.location.pathname == '/admin/reported/posts') - { - document.getElementById("flaggers-"+post_id).remove() - document.getElementById("post-"+post_id).remove() - } - else - { - document.getElementById("post-"+post_id).classList.remove("banned"); - } + t.disabled = true; + t.classList.add("disabled"); + postToast_callback(url, + { + }, + (xhr) => { + if (xhr.status >= 200 && xhr.status < 300) { + if (window.location.pathname == '/admin/reported/posts') + { + document.getElementById("flaggers-"+post_id).remove() + document.getElementById("post-"+post_id).remove() + } + else + { + document.getElementById("post-"+post_id).classList.remove("banned"); + document.getElementById(button1).classList.toggle(cls); + document.getElementById(button2).classList.toggle(cls); + } + } + t.disabled = false; + t.classList.remove("disabled"); + } + ); }