MarseyWorld/files/assets/js/report_post_modal.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-07-16 21:00:02 +00:00
const reason_post = document.getElementById("reason_post")
const reportPostButton = document.getElementById("reportPostButton");
reason_post.addEventListener('keydown', (e) => {
if(!((e.ctrlKey || e.metaKey) && e.key === "Enter")) return;
const targetDOM = document.activeElement;
if(!(targetDOM instanceof HTMLInputElement)) return;
reportPostButton.click()
bootstrap.Modal.getOrCreateInstance(document.getElementById('reportPostModal')).hide()
});
function report_postModal(id) {
reportPostButton.disabled = false;
reportPostButton.classList.remove('disabled');
reportPostButton.innerHTML='Report post';
reason_post.value = ""
setTimeout(() => {
reason_post.focus()
}, 500);
2023-04-27 17:24:07 +00:00
reportPostButton.onclick = function() {
2022-07-16 21:00:02 +00:00
this.innerHTML='Reporting post';
this.disabled = true;
this.classList.add('disabled');
const xhr = new XMLHttpRequest();
xhr.open("POST", '/report/post/'+id);
xhr.setRequestHeader('xhr', 'xhr');
2022-07-23 08:57:53 +00:00
const form = new FormData()
2022-07-16 21:00:02 +00:00
form.append("formkey", formkey());
form.append("reason", reason_post.value);
xhr.onload = function() {
2022-09-07 01:22:40 +00:00
let data
try {data = JSON.parse(xhr.response)}
catch(e) {console.error(e)}
success = xhr.status >= 200 && xhr.status < 300;
showToast(success, getMessageFromJsonData(success, data));
2022-07-16 21:00:02 +00:00
};
xhr.onerror=function(){alert(errortext)};
2022-07-16 21:00:02 +00:00
xhr.send(form);
2023-04-27 17:24:07 +00:00
}
};