From c92878dee5b883238ccf3952067c3798a87b0591 Mon Sep 17 00:00:00 2001 From: Repellent Date: Tue, 30 Dec 2025 12:18:39 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D1=8B=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/comment.js | 112 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 40 deletions(-) diff --git a/js/comment.js b/js/comment.js index 02449d3..6eda360 100644 --- a/js/comment.js +++ b/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(` -
+
NEW +
`); }; 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) {