]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
fix marking
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 22 Apr 2026 07:13:27 +0000 (10:13 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 22 Apr 2026 07:13:27 +0000 (10:13 +0300)
erp24/views/marking/index.php

index 103f376f1df66ee7ba15fd76f1ce749a62a64ac8..ee9bbe8403f23a01826156399b49d1c4bf8c1edf 100644 (file)
@@ -108,9 +108,13 @@ if (!empty($markings)) {
                     <?= $marking->getStatusBadge() ?>
                 </td>
                 <td style="text-align:center;white-space:nowrap;">
-                    <a href="#" class="btn-marking-edit" data-id="<?= (int)$marking->id ?>" title="Редактировать">
-                        <i class="fa fa-pencil text-secondary"></i>
-                    </a>
+                    <?php if ($marking->is_active): ?>
+                        <a href="#" class="btn-marking-edit" data-id="<?= (int)$marking->id ?>" title="Редактировать">
+                            <i class="fa fa-pencil text-secondary"></i>
+                        </a>
+                    <?php else: ?>
+                        <i class="fa fa-pencil text-secondary" style="opacity:0.3;cursor:default;" title="Недоступно для деактивированной записи"></i>
+                    <?php endif; ?>
                     <?php if ($marking->is_active): ?>
                         <a href="#" class="btn-marking-delete ms-1"
                            data-id="<?= (int)$marking->id ?>"
@@ -155,87 +159,119 @@ $deleteUrl = Url::to(['/marking/delete']);
 
 $js = <<<JS
 (function() {
-    var markingModal = new bootstrap.Modal(document.getElementById('marking-modal'));
+    $(document).off('.markingtab');
+
+    var _bsModal = null;
+    var shouldReload = false;
     var editingId = null;
     var loaderHtml = '<div class="text-center p-4"><i class="fa fa-spinner fa-spin fa-2x text-secondary"></i></div>';
 
+    var modalEl = document.getElementById('marking-modal');
+
+    function getModal() {
+        if (!_bsModal) {
+            _bsModal = new bootstrap.Modal(modalEl);
+        }
+        return _bsModal;
+    }
+
+    if (modalEl) {
+        modalEl.addEventListener('hidden.bs.modal', function() {
+            if (shouldReload) {
+                shouldReload = false;
+                reloadMarkingTab();
+            }
+        });
+    }
+
     function reloadMarkingTab() {
         $.get('{$reloadUrl}', function(html) {
-            $('#tab-markings').html(html);
+            \$('#tab-markings').html(html);
         }).fail(function(xhr) {
             alert('Ошибка обновления списка маркировок (' + (xhr.status || '?') + '). Обновите страницу вручную.');
         });
     }
 
-    $('#btn-marking-create').on('click', function() {
-        var \$btn = $(this);
+    \$('#btn-marking-create').on('click', function() {
+        var \$btn = \$(this);
         if (\$btn.prop('disabled')) return;
         \$btn.prop('disabled', true);
         editingId = null;
-        $('#marking-modal-title').text('Добавить маркировку');
-        $('#marking-modal-body').html(loaderHtml);
-        markingModal.show();
-        $.get('{$createFormUrl}', function(html) {
-            $('#marking-modal-body').html(html);
+        \$('#marking-modal-title').text('Добавить маркировку');
+        \$('#marking-modal-body').html(loaderHtml);
+        getModal().show();
+        \$.get('{$createFormUrl}', function(html) {
+            \$('#marking-modal-body').html(html);
         }).always(function() {
             \$btn.prop('disabled', false);
         });
     });
 
-    $(document).on('click', '.btn-marking-edit', function(e) {
+    \$(document).on('click.markingtab', '.btn-marking-edit', function(e) {
         e.preventDefault();
-        var \$btn = $(this);
+        var \$btn = \$(this);
         if (\$btn.prop('disabled')) return;
         \$btn.prop('disabled', true);
         editingId = \$btn.data('id');
-        $('#marking-modal-title').text('Редактировать маркировку');
-        $('#marking-modal-body').html(loaderHtml);
-        markingModal.show();
-        $.get('{$updateFormUrl}', {id: editingId}, function(html) {
-            $('#marking-modal-body').html(html);
+        \$('#marking-modal-title').text('Редактировать маркировку');
+        \$('#marking-modal-body').html(loaderHtml);
+        getModal().show();
+        \$.get('{$updateFormUrl}', {id: editingId}, function(html) {
+            \$('#marking-modal-body').html(html);
         }).always(function() {
             \$btn.prop('disabled', false);
         });
     });
 
-    $(document).on('click', '#btn-marking-save', function() {
-        var \$form = $('#marking-form');
+    \$(document).on('click.markingtab', '#btn-marking-save', function() {
+        var \$saveBtn = \$(this);
+        if (\$saveBtn.prop('disabled')) return;
+        \$saveBtn.prop('disabled', true);
+
+        var \$form = \$('#marking-form');
         var url = editingId ? '{$updateUrl}?id=' + editingId : '{$createUrl}';
 
         \$form.find('.is-invalid').removeClass('is-invalid');
         \$form.find('.invalid-feedback').remove();
 
-        $.ajax({
+        \$.ajax({
             url: url,
             type: 'POST',
             data: \$form.serialize(),
             dataType: 'json',
             success: function(resp) {
                 if (resp.success) {
-                    markingModal.hide();
-                    reloadMarkingTab();
+                    shouldReload = true;
+                    getModal().hide();
                 } else if (resp.errors) {
-                    $.each(resp.errors, function(field, messages) {
+                    \$saveBtn.prop('disabled', false);
+                    \$.each(resp.errors, function(field, messages) {
                         var \$input = \$form.find('[name="Marking[' + field + ']"]');
                         \$input.addClass('is-invalid');
                         \$input.after('<div class="invalid-feedback">' + messages[0] + '</div>');
                     });
+                } else {
+                    \$saveBtn.prop('disabled', false);
+                    alert(resp.message || 'Ошибка сохранения');
                 }
             },
-            error: function() { alert('Ошибка сервера'); }
+            error: function() {
+                \$saveBtn.prop('disabled', false);
+                alert('Ошибка сервера');
+            }
         });
     });
 
-    $(document).on('click', '.btn-marking-delete', function(e) {
+    \$(document).on('click.markingtab', '.btn-marking-delete', function(e) {
         e.preventDefault();
-        var id = $(this).data('id');
-        var code = $(this).data('code');
+        var id = \$(this).data('id');
+        var code = \$(this).data('code');
 
         if (!confirm('Деактивировать маркировку "' + code + '"?')) {
             return;
         }
 
-        $.ajax({
+        \$.ajax({
             url: '{$deleteUrl}?id=' + id,
             type: 'POST',
             data: {_csrf: yii.getCsrfToken()},
@@ -251,10 +287,9 @@ $js = <<<JS
         });
     });
 
-    // Очистка ошибок при вводе
-    $(document).on('input change', '#marking-form input, #marking-form select', function() {
-        $(this).removeClass('is-invalid');
-        $(this).next('.invalid-feedback').remove();
+    \$(document).on('input.markingtab change.markingtab', '#marking-form input, #marking-form select', function() {
+        \$(this).removeClass('is-invalid');
+        \$(this).next('.invalid-feedback').remove();
     });
 })();
 JS;