function showFullPost(uuid, username) {
let defaultUrl = window.location.pathname;
if(window.location.pathname.indexOf('user') === -1)
defaultUrl += window.location.search;
$.ajax({
url: "/user/single_post_data/" + username + "/" + uuid,
beforeSend: () => {
const origin = encodeURI(btoa(window.location.href.split('/post')[0]));
window.history.pushState('', '', '/user/' + username + '/post/' + uuid + '?o=' + origin);
$('body').append(`
Dialog couldn\'t be loaded.');
}
});
}
function submitReportForm(hashID, reportReason, reportText) {
$.ajax({
url: '/posts/reportPost',
data: {
hashID,
reason: reportReason,
explanation: reportText
},
method: 'POST',
success: (data) => {
setTimeout(() => {
$('#postReportBody').find('.fa').fadeOut();
}, 500);
if(data.success) {
$('#postReportBody').append(`
${data.message}
`);
} else {
$('#postReportBody').append(`
${data.message}
`);
setTimeout(() => {
$('#postReportForm').slideDown();
$('#postReportBody').find('.alert').slideUp();
setTimeout(() => {
$('#postReportBody').find('.alert').remove();
}, 500);
}, 2500);
}
setTimeout(() => {
$('#postReportBody').find('.alert').slideDown();
}, 1000);
},
});
}
function openDeletePostModal(uuid) {
$('body').append(`
`);
$('#postDeleteModal').modal('show');
$('#postDeleteModal').on('hidden.bs.modal', function () {
$(this).remove();
});
loadDeletePostModal(uuid);
}
function loadDeletePostModal(hashID) {
$.ajax({
url: '/posts/getDeleteModal',
data: {
hashID
},
method: 'post',
success: data => {
$('#postReportTitle').text(data.title);
$('#postDeleteBody').removeClass('text-center').html(data.body);
},
error: console.log
});
}
function deletePost(hashID) {
$.ajax({
url: '/posts/deletePost',
method: 'post',
data: { hashID },
beforeSend: () => {
$('#postDeleteBody').addClass('text-center').html('
');
},
success: data => {
let timeout = 2000;
if(data.success) {
addSnackbar('success', data.message);
timeout = 0;
} else {
$('#postDeleteBody').html(`
${data.message}
`);
}
setTimeout(() => {
$('#postDeleteModal').modal('hide');
$(`.post-item[data-uuid=${hashID}]`).slideUp();
setTimeout(() => {
$('#postDeleteModal').modal('dispose').remove();
$(`.post-item[data-uuid=${hashID}]`).remove();
}, 500);
}, timeout);
}
})
}