Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/comment-item.js

92 lines
2.3 KiB
JavaScript

function openCommentReportModal(ID) {
openAsyncModal(
'/blog/getReportModal',
'Kommentar melden',
{ID},
() => {
$('#commentReportForm').on('submit', function(event) {
event.preventDefault();
const reason = $('#commentReportReason').val();
const text = $('#commentReportText').val();
reportComment(ID, reason, text);
});
},
'commentReportModal'
);
}
function reportComment(ID, reason, text) {
const modal = $('#commentReportModal');
$.ajax({
url: '/blog/reportComment',
data: {
ID, reason, text
},
method: 'POST',
success: (result) => {
console.log(result);
modal.modal('hide');
if(result.success) {
addSnackbar('success', result.message);
} else {
addSnackbar('danger', result.message);
}
},
error: (result) => {
console.log(result);
}
});
}
function openCommentDeleteModal(ID) {
openAsyncModal(
'/blog/getDeleteModal',
'Kommentar löschen',
{ID},
() => {
console.log('tetst');
},
'commentDeleteModal',
'lg'
)
}
function deleteComment(ID) {
const modal = $('#commentDeleteModal');
modal.find('.modal-body').empty().append('<div class="loadingSpinner"></div>');
$.ajax({
url: '/blog/deleteComment',
data: {
ID
},
method: 'POST',
success: (result) => {
modal.modal('hide');
console.log(result);
if(result.success) {
addSnackbar('success', result.message);
$('#comment-' + ID).slideUp();
let commentCount = $('.comment-count').text();
if(commentCount !== '') {
commentCount = parseInt(commentCount) - 1;
$('.comment-count').text(commentCount);
}
setTimeout(() => {
$('#comment-' + ID).remove();
}, 500)
} else {
addSnackbar('danger', result.message);
}
},
error: console.log
});
}