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);
|
|
|
|
|
2023-03-10 03:21:02 +00:00
|
|
|
xhr.onload = function() {
|
2022-09-07 01:22:40 +00:00
|
|
|
let data
|
|
|
|
try {data = JSON.parse(xhr.response)}
|
2023-03-12 09:54:14 +00:00
|
|
|
catch(e) {console.error(e)}
|
2022-10-14 10:15:06 +00:00
|
|
|
success = xhr.status >= 200 && xhr.status < 300;
|
|
|
|
showToast(success, getMessageFromJsonData(success, data));
|
2022-07-16 21:00:02 +00:00
|
|
|
};
|
|
|
|
|
2023-03-10 03:21: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
|
|
|
}
|
2023-01-28 14:27:52 +00:00
|
|
|
};
|