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(postUuid, reportReason, reportText) {
$.ajax({
url: '/posts/reportPost',
data: {
uuid: postUuid,
reason: reportReason,
explanation: reportText
},
method: 'POST',
success: (data) => {
setTimeout(() => {
$('#postReportBody').find('.fa').fadeOut();
}, 500);
console.log(data);
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 () {
$('#postDeleteModal').remove();
});
loadDeletePostModal(uuid);
}
function loadDeletePostModal(uuid) {
$.ajax({
url: '/posts/getDeleteModal',
data: {
uuid
},
method: 'post',
success: data => {
$('#postReportTitle').text(data.title);
$('#postDeleteBody').removeClass('text-center').html(data.body);
}
});
}
function deletePost(uuid) {
$.ajax({
url: '/posts/deletePost',
method: 'post',
data: { uuid },
beforeSend: () => {
$('#postDeleteBody').addClass('text-center').html('
');
},
success: data => {
if(data.success) {
$('#postDeleteBody').html('
');
} else {
$('#postDeleteBody').html('
');
}
$('#postDeleteBody').removeClass('text-center').find('.alert').text(data.message);
setTimeout(() => {
$('#postDeleteModal').modal('hide');
$(`.post-item[data-uuid=${uuid}]`).slideUp();
setTimeout(() => {
$('#postDeleteModal').modal('dispose').remove();
$(`.post-item[data-uuid=${uuid}]`).remove();
}, 500);
}, 2000);
}
})
}