Explorar o código

refactor(ui): replace native confirm with customConfirm dialog

Replace all native JavaScript confirm() calls with customConfirm() utility across multiple views including schedule, orders, areas, districts, users, reclamations, pricing codes, and year-data management pages. This provides a consistent, customizable confirmation dialog UI throughout the application.

- Add optional title parameter to deletion confirmations
- Ensure proper callback binding for async operations
- Maintain existing deletion logic and form submissions
Alexander Musikhin hai 3 semanas
pai
achega
752b80459b

+ 2 - 2
resources/views/admin/areas/edit.blade.php

@@ -69,9 +69,9 @@
     <script type="module">
         $('.undelete').on('click', function (e) {
             e.preventDefault();
-            if (confirm('Восстановить район?')) {
+            customConfirm('Восстановить район?', function () {
                 $('#undelete-area').submit();
-            }
+            });
         });
     </script>
 @endpush

+ 2 - 2
resources/views/admin/districts/edit.blade.php

@@ -68,9 +68,9 @@
     <script type="module">
         $('.undelete').on('click', function (e) {
             e.preventDefault();
-            if (confirm('Восстановить округ?')) {
+            customConfirm('Восстановить округ?', function () {
                 $('#undelete-district').submit();
-            }
+            });
         });
     </script>
 @endpush

+ 1 - 1
resources/views/clear-data/index.blade.php

@@ -136,7 +136,7 @@
                     $('#statsBlock').show();
                 },
                 error: function(xhr) {
-                    alert('Ошибка получения статистики: ' + (xhr.responseJSON?.error || 'Неизвестная ошибка'));
+                    customAlert('Ошибка получения статистики: ' + (xhr.responseJSON?.error || 'Неизвестная ошибка'));
                 },
                 complete: function() {
                     btn.prop('disabled', false).text('Показать статистику');

+ 28 - 0
resources/views/layouts/app.blade.php

@@ -137,6 +137,7 @@
         // Глобальные настройки (без jQuery)
         var user = {{ auth()->user()?->id ?? 0}};
         var socketAddress = '{{ config('app.ws_addr') }}';
+        var customConfirmCallback = null;
         localStorage.setItem('user', user);
         localStorage.setItem('socketAddress', socketAddress);
 
@@ -147,6 +148,33 @@
             myModal.show();
         }
 
+        function customConfirm(message, onConfirm, title = 'Подтверждение') {
+            document.getElementById('customConfirmModalLabel').textContent = title;
+            document.getElementById('customConfirmModalBody').textContent = message;
+            customConfirmCallback = typeof onConfirm === 'function' ? onConfirm : null;
+            var confirmModal = bootstrap.Modal.getOrCreateInstance(document.getElementById('customConfirmModal'));
+            confirmModal.show();
+        }
+
+        document.getElementById('customConfirmModalOk').addEventListener('click', function () {
+            var modalElement = document.getElementById('customConfirmModal');
+            var confirmModal = bootstrap.Modal.getInstance(modalElement);
+
+            if (confirmModal) {
+                confirmModal.hide();
+            }
+
+            if (typeof customConfirmCallback === 'function') {
+                var callback = customConfirmCallback;
+                customConfirmCallback = null;
+                callback();
+            }
+        });
+
+        document.getElementById('customConfirmModal').addEventListener('hidden.bs.modal', function () {
+            customConfirmCallback = null;
+        });
+
         // Ждём загрузки jQuery через Vite
         function waitForJQuery(callback) {
             if (typeof $ !== 'undefined') {

+ 8 - 8
resources/views/orders/show.blade.php

@@ -24,7 +24,7 @@
                     </form>
                 @endif
                 @if(hasRole('admin') && ($order->order_status_id == Order::STATUS_NEW))
-                    <a href="#" onclick="if(confirm('Удалить площадку?')) $('form#destroy').submit();"
+                    <a href="#" onclick="customConfirm('Удалить площадку?', function () { $('form#destroy').submit(); }, 'Подтверждение удаления'); return false;"
                        class="btn btn-sm mb-1 btn-danger">Удалить</a>
                     <form action="{{ route('order.destroy', $order) }}" method="post" class="d-none" id="destroy">
                         @csrf
@@ -93,7 +93,7 @@
                                    name="document[]" class="form-control form-control-sm">
                         </form>
                         @if(hasRole('admin'))
-                            <button class="btn btn-sm text-danger" onclick="if(confirm('Удалить все документы?')) { $('#delete-all-documents').submit(); }"><i
+                            <button class="btn btn-sm text-danger" onclick="customConfirm('Удалить все документы?', function () { $('#delete-all-documents').submit(); }, 'Подтверждение удаления'); return false;"><i
                                         class="bi bi-file-minus-fill"></i> Удалить все
                             </button>
                             <form action="{{ route('order.delete-all-documents', $order) }}" enctype="multipart/form-data" id="delete-all-documents"
@@ -110,7 +110,7 @@
                                     </a>
                                     @if(hasRole('admin'))
                                         <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer ms-2"
-                                           onclick="if(confirm('Удалить?')) $('#document-{{ $document->id }}').submit()"
+                                           onclick="customConfirm('Удалить?', function () { $('#document-{{ $document->id }}').submit(); }, 'Подтверждение удаления')"
                                            title="Удалить"></i>
                                     @endif
                                     <form action="{{ route('order.delete-document', [$order, $document]) }}" method="POST"
@@ -135,7 +135,7 @@
                                    name="statement[]" class="form-control form-control-sm">
                         </form>
                         @if(hasRole('admin'))
-                            <button class="btn btn-sm text-danger" onclick="if(confirm('Удалить все ведомости?')) { $('#delete-all-statements').submit(); }"><i
+                            <button class="btn btn-sm text-danger" onclick="customConfirm('Удалить все ведомости?', function () { $('#delete-all-statements').submit(); }, 'Подтверждение удаления'); return false;"><i
                                         class="bi bi-file-minus-fill"></i> Удалить все
                             </button>
                             <form action="{{ route('order.delete-all-statements', $order) }}" enctype="multipart/form-data" id="delete-all-statements"
@@ -152,7 +152,7 @@
                                     </a>
                                     @if(hasRole('admin'))
                                         <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer ms-2"
-                                           onclick="if(confirm('Удалить?')) $('#statement-{{ $statement->id }}').submit()"
+                                           onclick="customConfirm('Удалить?', function () { $('#statement-{{ $statement->id }}').submit(); }, 'Подтверждение удаления')"
                                            title="Удалить"></i>
                                     @endif
                                     <form action="{{ route('order.delete-statement', [$order, $statement]) }}" method="POST"
@@ -186,7 +186,7 @@
                                name="photo[]" class="form-control form-control-sm" accept=".jpg,.jpeg,.png">
                     </form>
                     @if(hasRole('admin'))
-                        <button class="btn btn-sm text-danger" onclick="if(confirm('Удалить все фотографии?')) { $('#delete-all-photos').submit(); }"><i
+                        <button class="btn btn-sm text-danger" onclick="customConfirm('Удалить все фотографии?', function () { $('#delete-all-photos').submit(); }, 'Подтверждение удаления'); return false;"><i
                                     class="bi bi-file-minus-fill"></i> Удалить все
                         </button>
                         <form action="{{ route('order.delete-all-photos', $order) }}" enctype="multipart/form-data" id="delete-all-photos"
@@ -204,7 +204,7 @@
                                 </a>
                                 @if(hasRole('admin'))
                                     <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer rm-but"
-                                       onclick="if(confirm('Удалить фото?')) $('#photo-{{ $photo->id }}').submit()"
+                                       onclick="customConfirm('Удалить фото?', function () { $('#photo-{{ $photo->id }}').submit(); }, 'Подтверждение удаления')"
                                        title="Удалить"></i>
                                 @endif
                                 <form action="{{ route('order.delete-photo', [$order, $photo]) }}" method="POST"
@@ -549,4 +549,4 @@
         });
 
     </script>
-@endpush
+@endpush

+ 16 - 0
resources/views/partials/customAlert.blade.php

@@ -14,3 +14,19 @@
         </div>
     </div>
 </div>
+
+<div class="modal fade" id="customConfirmModal" tabindex="-1" aria-labelledby="customConfirmModalLabel" aria-hidden="true">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title" id="customConfirmModalLabel">Подтверждение</h5>
+                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
+            </div>
+            <div class="modal-body" id="customConfirmModalBody"></div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
+                <button type="button" class="btn btn-danger" id="customConfirmModalOk">Подтвердить</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 4 - 3
resources/views/partials/submit.blade.php

@@ -13,10 +13,11 @@
 @push('scripts')
     <script type="module">
 
-        $('a.delete').on('click', function (){
-            if(confirm('{{ $delete['question']  ?? 'Удалить запись?' }}')) {
+        $('a.delete').on('click', function (e){
+            e.preventDefault();
+            customConfirm('{{ $delete['question']  ?? 'Удалить запись?' }}', function () {
                 $('#{{ $delete['form_id'] ?? 'destroy_form'}}').submit();
-            }
+            }, 'Подтверждение удаления');
         });
 
         $('.buttons .btn').on('click', function (){

+ 12 - 2
resources/views/pricing_codes/index.blade.php

@@ -99,8 +99,8 @@
                                         </form>
                                     </td>
                                     <td>
-                                        <form action="{{ route('pricing_codes.destroy', $code) }}" method="POST" class="d-inline"
-                                              onsubmit="return confirm('Удалить код {{ $code->code }}?')">
+                                        <form action="{{ route('pricing_codes.destroy', $code) }}" method="POST" class="d-inline js-confirm-submit"
+                                              data-confirm-message="Удалить код {{ $code->code }}?">
                                             @csrf
                                             @method('DELETE')
                                             <button type="submit" class="btn btn-sm btn-danger">Удалить</button>
@@ -184,6 +184,16 @@
             $('.description-text-' + id).show();
             $('.edit-description[data-id="' + id + '"]').show();
         });
+
+        $('.js-confirm-submit').on('submit', function(e) {
+            e.preventDefault();
+            const form = this;
+            const message = $(form).data('confirm-message') || 'Подтвердите действие';
+
+            customConfirm(message, function () {
+                form.submit();
+            }, 'Подтверждение удаления');
+        });
     });
 </script>
 @endpush

+ 5 - 5
resources/views/reclamations/edit.blade.php

@@ -18,7 +18,7 @@
                        class="btn btn-primary btn-sm">Пакет документов на оплату</a>
                 @endif
                 @if(hasRole('admin'))
-                    <a href="#" onclick="if(confirm('Удалить рекламацию?')) $('form#destroy').submit();"
+                    <a href="#" onclick="customConfirm('Удалить рекламацию?', function () { $('form#destroy').submit(); }, 'Подтверждение удаления'); return false;"
                        class="btn btn-sm btn-danger">Удалить</a>
                     <form action="{{ route('reclamations.delete', $reclamation) }}" method="post" class="d-none" id="destroy">
                         @csrf
@@ -438,7 +438,7 @@
                                 </a>
                                 @if(hasRole('admin'))
                                     <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer ms-2"
-                                       onclick="if(confirm('Удалить?')) $('#document-{{ $document->id }}').submit()"
+                                       onclick="customConfirm('Удалить?', function () { $('#document-{{ $document->id }}').submit(); }, 'Подтверждение удаления')"
                                        title="Удалить"></i>
                                 @endif
                                 <form action="{{ route('reclamations.delete-document', [$reclamation, $document]) }}"
@@ -472,7 +472,7 @@
                                 </a>
                                 @if(hasRole('admin'))
                                     <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer ms-2"
-                                       onclick="if(confirm('Удалить?')) $('#act-{{ $act->id }}').submit()"
+                                       onclick="customConfirm('Удалить?', function () { $('#act-{{ $act->id }}').submit(); }, 'Подтверждение удаления')"
                                        title="Удалить"></i>
                                     <form action="{{ route('reclamations.delete-act', [$reclamation, $act]) }}"
                                           method="POST"
@@ -513,7 +513,7 @@
                                 </a>
                                 @if(hasRole('admin'))
                                     <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer rm-but"
-                                       onclick="if(confirm('Удалить фото?')) $('#photo-{{ $photo->id }}').submit()"
+                                       onclick="customConfirm('Удалить фото?', function () { $('#photo-{{ $photo->id }}').submit(); }, 'Подтверждение удаления')"
                                        title="Удалить"></i>
                                 @endif
                                 <form action="{{ route('reclamations.delete-photo-before', [$reclamation, $photo]) }}"
@@ -554,7 +554,7 @@
                                 </a>
                                 @if(hasRole('admin'))
                                     <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer rm-but"
-                                       onclick="if(confirm('Удалить фото?')) $('#photo-{{ $photo->id }}').submit()"
+                                       onclick="customConfirm('Удалить фото?', function () { $('#photo-{{ $photo->id }}').submit(); }, 'Подтверждение удаления')"
                                        title="Удалить"></i>
                                 @endif
                                 <form action="{{ route('reclamations.delete-photo-after', [$reclamation, $photo]) }}"

+ 2 - 3
resources/views/schedule/index.blade.php

@@ -386,11 +386,10 @@
         });
 
         $('.deleteSchedule').on('click', function () {
-            if (confirm('Удалить запись?')) {
+            customConfirm('Удалить запись?', function () {
                 let scheduleId = $(this).attr('data-schedule-id');
                 $('.deleteForm-' + scheduleId).submit();
-            }
-
+            }.bind(this), 'Подтверждение удаления');
         });
 
         $('.createSchedule').on('click', function () {

+ 4 - 4
resources/views/users/edit.blade.php

@@ -59,15 +59,15 @@
 @push('scripts')
     <script type="module">
         $('.undelete').on('click', function (){
-            if(confirm('Восстановить пользователя?')) {
+            customConfirm('Восстановить пользователя?', function () {
                 $('#undelete-user').submit();
-            }
+            });
         });
 
         $('.impersonate-user').on('click', function (){
-            if(confirm('Войти от имени этого пользователя?')) {
+            customConfirm('Войти от имени этого пользователя?', function () {
                 $('#impersonate-user').submit();
-            }
+            });
         });
 
 

+ 13 - 6
resources/views/year-data/index.blade.php

@@ -186,7 +186,7 @@
                     $('#exportStatsBlock').show();
                 },
                 error: function(xhr) {
-                    alert('Ошибка получения статистики: ' + (xhr.responseJSON?.error || 'Неизвестная ошибка'));
+                    customAlert('Ошибка получения статистики: ' + (xhr.responseJSON?.error || 'Неизвестная ошибка'));
                 },
                 complete: function() {
                     btn.prop('disabled', false).text('Показать статистику');
@@ -196,20 +196,27 @@
 
         // Валидация формы импорта
         $('form[action="{{ route('year-data.import') }}"]').on('submit', function(e) {
+            const form = this;
             const file = $('#importFile').val();
             const clearExisting = $('#clearExisting').is(':checked');
 
             if (!file) {
                 e.preventDefault();
-                alert('Пожалуйста, выберите ZIP-архив для импорта');
+                customAlert('Пожалуйста, выберите ZIP-архив для импорта');
                 return false;
             }
 
             if (clearExisting) {
-                if (!confirm('Вы уверены, что хотите очистить существующие данные за этот год? Это действие необратимо!')) {
-                    e.preventDefault();
-                    return false;
-                }
+                e.preventDefault();
+                customConfirm(
+                    'Вы уверены, что хотите очистить существующие данные за этот год? Это действие необратимо!',
+                    function () {
+                        $('#btnImport').prop('disabled', true).html('<span class="spinner-border spinner-border-sm me-2"></span>Загрузка...');
+                        form.submit();
+                    },
+                    'Подтверждение удаления'
+                );
+                return false;
             }
 
             $('#btnImport').prop('disabled', true).html('<span class="spinner-border spinner-border-sm me-2"></span>Загрузка...');