еще правки для формы редактирования
This commit is contained in:
112
js/comment.js
112
js/comment.js
@@ -557,7 +557,11 @@ if ($foundImgs.length > 0) {
|
||||
|
||||
$textBlock.after(editHtml);
|
||||
|
||||
// --- ПРЕВЬЮ НОВЫХ ФАЙЛОВ ПРИ РЕДАКТИРОВАНИИ ---
|
||||
// --- НАКОПИТЕЛЬНОЕ ПРЕВЬЮ НОВЫХ ФАЙЛОВ ---
|
||||
var pendingFiles = []; // Массив для хранения всех выбранных файлов
|
||||
|
||||
$wrapper.find('.edit-form-container').data('pendingFiles', pendingFiles);
|
||||
|
||||
$('#new_file_' + cid).on('change', function() {
|
||||
var files = this.files;
|
||||
var $previewContainer = $('#new_files_preview_' + cid);
|
||||
@@ -567,21 +571,41 @@ if ($foundImgs.length > 0) {
|
||||
$previewContainer = $('#new_files_preview_' + cid);
|
||||
}
|
||||
|
||||
$previewContainer.empty();
|
||||
// Мы НЕ удаляем старые превью ($previewContainer.empty() убрали),
|
||||
// а просто добавляем новые в массив и в контейнер
|
||||
if (files) {
|
||||
$.each(files, function(i, file) {
|
||||
if (!file.type.match('image.*')) return;
|
||||
|
||||
// Добавляем файл в наш список
|
||||
pendingFiles.push(file);
|
||||
var currentIndex = pendingFiles.length - 1;
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
$previewContainer.append(`
|
||||
<div class="position-relative">
|
||||
<div class="position-relative new-file-item" data-index="${currentIndex}">
|
||||
<img src="${e.target.result}" class="img-thumbnail" style="width: 80px; height: 80px; object-fit: cover; border: 2px solid #0d6efd;">
|
||||
<span class="badge bg-primary position-absolute top-0 start-0 m-1" style="font-size: 0.6rem;">NEW</span>
|
||||
<button type="button" class="btn btn-danger btn-sm position-absolute top-0 end-0 remove-new-file"
|
||||
style="padding: 0 5px; margin: 2px; line-height: 1; z-index: 10;">
|
||||
<i class="bi bi-x-lg" style="font-size: 0.7rem;"></i>
|
||||
</button>
|
||||
</div>`);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
// Очищаем инпут, чтобы браузер позволил выбрать те же файлы снова
|
||||
$(this).val('');
|
||||
});
|
||||
|
||||
// Обработчик удаления НОВОГО файла из превью (до сохранения)
|
||||
$doc.off('click', '.remove-new-file').on('click', '.remove-new-file', function() {
|
||||
var $item = $(this).closest('.new-file-item');
|
||||
var index = $item.data('index');
|
||||
pendingFiles[index] = null; // Помечаем как удаленный
|
||||
$item.remove();
|
||||
});
|
||||
// --- КОНЕЦ ВСТАВКИ ---
|
||||
|
||||
@@ -677,46 +701,54 @@ $doc.on('click', '.cancelButton', function() {
|
||||
});
|
||||
|
||||
$doc.on('click', '.saveButton', function() {
|
||||
var $btn = $(this);
|
||||
var cid = $btn.data('id');
|
||||
var fd = new FormData();
|
||||
fd.append('module', 'comment'); fd.append('action', 'edit'); fd.append('Id', cid);
|
||||
fd.append('text', $('#ta_' + cid).val());
|
||||
var $btn = $(this);
|
||||
var cid = $btn.data('id');
|
||||
var $container = $btn.closest('.edit-form-container');
|
||||
|
||||
// Достаем наш накопительный массив файлов
|
||||
var pendingFiles = $container.data('pendingFiles') || [];
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('module', 'comment');
|
||||
fd.append('action', 'edit');
|
||||
fd.append('Id', cid);
|
||||
fd.append('text', $('#ta_' + cid).val());
|
||||
|
||||
|
||||
var rInput = $('#rating_input_' + cid);
|
||||
if (rInput.length) fd.append('user_rating', rInput.val());
|
||||
var rInput = $('#rating_input_' + cid);
|
||||
if (rInput.length) fd.append('user_rating', rInput.val());
|
||||
|
||||
fd.append('delete_files', $('#delete_files_' + cid).val());
|
||||
|
||||
// --- ИЗМЕНЕННЫЙ БЛОК ДЛЯ MULTIPLE ---
|
||||
var fileInput = $('#new_file_' + cid);
|
||||
if (fileInput.length && fileInput[0].files.length > 0) {
|
||||
for (var i = 0; i < fileInput[0].files.length; i++) {
|
||||
// Добавляем каждый файл в массив comment_image[]
|
||||
fd.append('comment_image[]', fileInput[0].files[i]);
|
||||
}
|
||||
}
|
||||
// ------------------------------------
|
||||
fd.append('delete_files', $('#delete_files_' + cid).val());
|
||||
|
||||
// --- ОБНОВЛЕННЫЙ БЛОК: берем файлы из массива, а не из инпута ---
|
||||
pendingFiles.forEach(function(file) {
|
||||
if (file !== null) { // Проверяем, что файл не был удален крестиком
|
||||
fd.append('comment_image[]', file);
|
||||
}
|
||||
});
|
||||
// ------------------------------------
|
||||
|
||||
$.ajax({
|
||||
url: aveabspath + 'index.php?ajax=1',
|
||||
type: 'POST', data: fd, processData: false, contentType: false,
|
||||
xhr: function() {
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.upload.addEventListener("progress", function(evt) {
|
||||
if (evt.lengthComputable) {
|
||||
var pct = Math.round((evt.loaded / evt.total) * 100);
|
||||
$('#edit_progress_container_' + cid).removeClass('d-none');
|
||||
$('#edit_progress_bar_' + cid).css('width', pct + '%');
|
||||
}
|
||||
}, false);
|
||||
return xhr;
|
||||
},
|
||||
beforeSend: function() { $btn.prop('disabled', true).text('...'); },
|
||||
success: function() { location.reload(); }
|
||||
});
|
||||
});
|
||||
$.ajax({
|
||||
url: aveabspath + 'index.php?ajax=1',
|
||||
type: 'POST',
|
||||
data: fd,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
xhr: function() {
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.upload.addEventListener("progress", function(evt) {
|
||||
if (evt.lengthComputable) {
|
||||
var pct = Math.round((evt.loaded / evt.total) * 100);
|
||||
// Проверь, есть ли у тебя эти ID в HTML, если нет - прогресс-бар просто не покажется
|
||||
$('#edit_progress_container_' + cid).removeClass('d-none');
|
||||
$('#edit_progress_bar_' + cid).css('width', pct + '%');
|
||||
}
|
||||
}, false);
|
||||
return xhr;
|
||||
},
|
||||
beforeSend: function() { $btn.prop('disabled', true).text('...'); },
|
||||
success: function() { location.reload(); }
|
||||
});
|
||||
});
|
||||
|
||||
// Отправка новой формы (или ответа)
|
||||
$doc.on('submit', '#mod_comment_new form', function(e) {
|
||||
|
||||
Reference in New Issue
Block a user