]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-417
authormarina <m.zozirova@gmail.com>
Tue, 3 Jun 2025 06:45:10 +0000 (09:45 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 3 Jun 2025 06:45:10 +0000 (09:45 +0300)
erp24/web/js/validate/validateForm.js

index 70bf779ca234e9f660941b59eee32be53e138400..0350ff771ff1ebea225007c0b4158664eec9f4d0 100755 (executable)
@@ -1,6 +1,5 @@
 $(".form-validate button").click(function (e) {
     e.preventDefault();
-
     var form = $(this).closest('form')[0];
     var yiiform = $("#" + form.id);
 
@@ -26,52 +25,46 @@ $(".form-validate button").click(function (e) {
 
             let errors = data.errors || {};
 
-            // Получаем группу и имя пользователя
-            let group = $('.group-name').text().trim();
-            let currentUser = $('.admin-name').text().trim();
-            let selectedStoreId = $('#writeoffserp-store_id').val();
-            let commentValue = $('#writeoffserp-comment').val().trim();
+            const rows = $('.multiple-input-list__item');
+
+            let allRowsHaveImage = true;
+            rows.each(function () {
+                let row = $(this);
+                let hasImageInRow = row.find('.list-cell__images_row img').length > 0;
+                let fileInput = row.find('.list-cell__imageFiles input[type="file"]');
+                let hasFilesSelected = fileInput.length && fileInput[0].files.length > 0;
+                if (!hasImageInRow && !hasFilesSelected) {
+                    allRowsHaveImage = false;
+                    return false;
+                }
+            });
 
-            const specialStoreIds = ['1', '9', '28']; // Ванеева, Народная, Революции
-            const allowedCommentUsers = [
-                'Емельянова Ольга',
-                'Яшенкова Алена',
-                'Цветкова Ольга'
-            ];
+            if (!allRowsHaveImage) {
+                if (!errors['__common']) errors['__common'] = [];
+                errors['__common'].push('Пожалуйста, добавьте хотя бы одно фото к каждому списанию перед сохранением.');
+            }
 
-            if (group === 'IT' && specialStoreIds.includes(selectedStoreId)) {
-                // Проверка фото или файлов
-                let allRowsHaveImage = true;
-
-                $('.multiple-input-list__item').each(function () {
-                    const row = $(this);
-                    const hasImage = row.find('.list-cell__images_row img').length > 0;
-                    const fileInput = row.find('.list-cell__imageFiles input[type="file"]');
-                    const hasFile = fileInput.length > 0 && fileInput[0].files.length > 0;
-
-                    if (!hasImage && !hasFile) {
-                        allRowsHaveImage = false;
-                        return false; // break .each
-                    }
-                });
+            // Добавляем проверку комментария только для группы IT и спец магазинов
+            const group = $('.group-name').text().trim();
+            const currentUser = $('.admin-name').text().trim();
+            const selectedStoreId = $('#writeoffserp-store_id').val();
+            const commentValue = $('#writeoffserp-comment').val().trim();
 
-                if (!allRowsHaveImage) {
-                    if (!errors['__common']) errors['__common'] = [];
-                    errors['__common'].push('Пожалуйста, добавьте хотя бы одно фото к каждой строке.');
-                }
+            const specialStoreIds = ['1', '9', '28'];
+            const allowedCommentUsers = ['Емельянова Ольга', 'Яшенкова Алена', 'Цветкова Ольга'];
 
-                // Запрет комментария
+            if (group === 'IT' && specialStoreIds.includes(selectedStoreId)) {
                 if (commentValue.length > 0 && !allowedCommentUsers.includes(currentUser)) {
                     errors['WriteOffsErp[comment]'] = [
-                        'Ð\9aомменÑ\82аÑ\80ий Ð¼Ð¾Ð³Ñ\83Ñ\82 Ð¿Ð¸Ñ\81аÑ\82Ñ\8c Ñ\82олÑ\8cко: ' + allowedCommentUsers.join(', ')
+                        'Ð\9aомменÑ\82аÑ\80ий Ð¼Ð¾Ð³Ñ\83Ñ\82 Ð·Ð°Ð¿Ð¾Ð»Ð½Ñ\8fÑ\82Ñ\8c Ñ\82олÑ\8cко: ' + allowedCommentUsers.join(', ') + '.'
                     ];
                 }
             }
 
-            // Обработка ошибок
+            console.log('Ошибки перед alert:', errors);
+
             if (Object.keys(errors).length > 0) {
                 renderErrors(errors);
-
                 let allErrors = [];
                 for (const key in errors) {
                     if (Array.isArray(errors[key])) {
@@ -81,6 +74,8 @@ $(".form-validate button").click(function (e) {
                     }
                 }
 
+                console.log('Собранные ошибки для alert:', allErrors);
+
                 alert(allErrors.join('\n'));
             } else {
                 yiiform.off('submit');
@@ -88,7 +83,7 @@ $(".form-validate button").click(function (e) {
             }
         })
         .fail(function () {
-            console.log("Ð\9dе удалось выполнить запрос к серверу");
+            console.log("не удалось выполнить запрос к серверу");
         });
 
     return false;
@@ -112,6 +107,7 @@ $(".form-validate button").click(function (e) {
             }
         });
 
-        $('.messages').html(messages.join(', <br>'));
+        var strOut2 = messages.join(', <br>');
+        $('.messages').html(strOut2);
     }
 });
\ No newline at end of file