2024-10-09 20:13:10 +03:00
|
|
|
|
function createModal(id, type, value, modalid) {
|
2024-10-05 14:16:39 +03:00
|
|
|
|
if (type === 'EDIT_COMMENT') {
|
|
|
|
|
var modal = `
|
2024-10-09 20:13:10 +03:00
|
|
|
|
<div id="`+modalid+`" class="modal" style="display: block;">
|
2024-10-05 14:16:39 +03:00
|
|
|
|
<div class="modal-content">
|
2024-10-09 20:13:10 +03:00
|
|
|
|
<span data-close-modal-id="`+modalid+`" class="close">×</span>
|
2024-10-05 14:16:39 +03:00
|
|
|
|
<h3><b>Отредактировать комментарий</b></h3>
|
|
|
|
|
<div style="padding:0 11px 11px">
|
2024-10-06 16:03:11 +03:00
|
|
|
|
<textarea style=" width: 100%;
|
|
|
|
|
height: 200px;" name="wtext" id="bodypost__commedit`+id+`">`+value+`</textarea><br>
|
2024-10-05 14:16:39 +03:00
|
|
|
|
<div class="cmt-submit">
|
2024-10-10 18:38:14 +03:00
|
|
|
|
<button type="submit" onclick="editComment('` + id + `', document.getElementById('bodypost__commedit` + id + `').value, '`+modalid+`')" id="sbmt">Отредактировать</button>  Ctrl + Enter
|
2024-10-05 14:16:39 +03:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
}
|
2024-10-08 21:42:55 +03:00
|
|
|
|
if (type === 'DELETE_COMMENT') {
|
|
|
|
|
var modal = `
|
2024-10-09 20:13:10 +03:00
|
|
|
|
<div id="`+modalid+`" class="modal" style="display: block;">
|
2024-10-08 21:42:55 +03:00
|
|
|
|
<div class="modal-content">
|
2024-10-09 20:13:10 +03:00
|
|
|
|
<span data-close-modal-id="`+modalid+`" class="close">×</span>
|
2024-10-08 21:42:55 +03:00
|
|
|
|
<h3><b>Удалить комментарий</b></h3>
|
|
|
|
|
Вы действительно хотите удалить комментарий? Действие необратимо.
|
|
|
|
|
<div style="margin-top: 35px;">
|
|
|
|
|
|
|
|
|
|
<div class="cmt-submit">
|
2024-10-09 20:13:10 +03:00
|
|
|
|
<button type="submit" onclick="deleteComment('` + id + `', '`+modalid+`')" id="sbmt">Удалить</button>
|
|
|
|
|
<button data-close-modal-id="`+modalid+`" type="submit" id="sbmt">Отмена</button>
|
2024-10-08 21:42:55 +03:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
}
|
2024-10-05 14:16:39 +03:00
|
|
|
|
document.body.innerHTML += modal;
|
2024-10-01 06:31:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-10-05 14:16:39 +03:00
|
|
|
|
document.addEventListener("click", function(event) {
|
2024-10-09 20:13:10 +03:00
|
|
|
|
// Получаем ID модального окна, которое нужно закрыть
|
2024-10-08 21:42:55 +03:00
|
|
|
|
var modalId = event.target.getAttribute("data-close-modal-id");
|
2024-10-09 20:13:10 +03:00
|
|
|
|
|
|
|
|
|
// Удаляем модальное окно по его ID
|
|
|
|
|
if (modalId) {
|
|
|
|
|
var modalToClose = document.getElementById(modalId);
|
|
|
|
|
if (modalToClose) {
|
|
|
|
|
modalToClose.remove(); // Удаляем модальное окно из DOM
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Проверяем, кликнули ли мы на само модальное окно
|
|
|
|
|
var modals = document.querySelectorAll(".modal");
|
|
|
|
|
modals.forEach(function(modal) {
|
|
|
|
|
if (event.target === modal) {
|
|
|
|
|
modal.remove(); // Удаляем модальное окно из DOM
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-10-05 14:16:39 +03:00
|
|
|
|
});
|
2024-10-01 06:31:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-05 14:16:39 +03:00
|
|
|
|
|
2024-10-09 20:13:10 +03:00
|
|
|
|
const editComment = (postId, body, modalid) => {
|
2024-10-05 14:16:39 +03:00
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: '/api/photo/comment/'+postId+'/edit',
|
|
|
|
|
data: JSON.stringify({ "value": body }),
|
|
|
|
|
success: function(response) {
|
|
|
|
|
var jsonData = JSON.parse(response);
|
|
|
|
|
|
|
|
|
|
console.log(response);
|
|
|
|
|
if (jsonData.errorcode == "1") {
|
|
|
|
|
Notify.noty('danger', JSON.stringify(response));
|
|
|
|
|
} else {
|
2024-10-09 20:13:10 +03:00
|
|
|
|
document.getElementById(modalid).style.display = "none";
|
2024-10-05 14:16:39 +03:00
|
|
|
|
|
|
|
|
|
Notify.noty('success', 'Успешно отредактировано!');
|
|
|
|
|
const url = window.location.pathname;
|
|
|
|
|
const segments = url.split('/');
|
|
|
|
|
const id = segments[segments.length - 1];
|
|
|
|
|
$.ajax({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: "/api/photo/getcomments/"+id,
|
|
|
|
|
processData: false,
|
|
|
|
|
async: true,
|
|
|
|
|
success: function(r) {
|
|
|
|
|
$('#posts').html(r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error: function(r) {
|
|
|
|
|
console.log(r)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-08 21:42:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-09 20:13:10 +03:00
|
|
|
|
const deleteComment = (postId, modalid) => {
|
2024-10-08 21:42:55 +03:00
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: '/api/photo/comment/'+postId+'/delete',
|
|
|
|
|
success: function(response) {
|
|
|
|
|
var jsonData = JSON.parse(response);
|
|
|
|
|
|
|
|
|
|
console.log(response);
|
|
|
|
|
if (jsonData.errorcode == "1") {
|
|
|
|
|
Notify.noty('danger', JSON.stringify(response));
|
|
|
|
|
} else {
|
2024-10-09 20:13:10 +03:00
|
|
|
|
document.getElementById(modalid).style.display = "none";
|
2024-10-08 21:42:55 +03:00
|
|
|
|
|
|
|
|
|
Notify.noty('success', 'Успешно удалено!');
|
|
|
|
|
const url = window.location.pathname;
|
|
|
|
|
const segments = url.split('/');
|
|
|
|
|
const id = segments[segments.length - 1];
|
|
|
|
|
const commcountElem = document.getElementById('commcount');
|
|
|
|
|
let innerHTML = commcountElem.innerHTML;
|
|
|
|
|
let match = innerHTML.match(/>(\d+)</);
|
|
|
|
|
console.log(match);
|
|
|
|
|
if (match) {
|
|
|
|
|
let count = parseInt(match[1], 10) - 1;
|
|
|
|
|
console.log(count);
|
|
|
|
|
let newHTML = innerHTML.replace(match[1], count);
|
|
|
|
|
commcountElem.innerHTML = newHTML;
|
|
|
|
|
}
|
|
|
|
|
$.ajax({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: "/api/photo/getcomments/"+id,
|
|
|
|
|
processData: false,
|
|
|
|
|
async: true,
|
|
|
|
|
success: function(r) {
|
|
|
|
|
$('#posts').html(r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error: function(r) {
|
|
|
|
|
console.log(r)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|