From: fomichev Date: Tue, 21 Apr 2026 10:19:41 +0000 (+0300) Subject: фикс появления после создания X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f15d0bbe1dfda4054f71ae1bb2ed9efca649090b;p=erp24_rep%2Fyii-erp24%2F.git фикс появления после создания --- diff --git a/erp24/views/supplier/index.php b/erp24/views/supplier/index.php index f3a8efdf..f21b57b8 100644 --- a/erp24/views/supplier/index.php +++ b/erp24/views/supplier/index.php @@ -138,119 +138,17 @@ use yii_app\records\Supplier; '; - - // Создание - $('#btn-supplier-create').on('click', function() { - var \$btn = $(this); - if (\$btn.prop('disabled')) return; - \$btn.prop('disabled', true); - editingId = null; - $('#supplier-modal-title').text('Добавить поставщика'); - $('#supplier-modal-body').html(loaderHtml); - supplierModal.show(); - $.get('{$createFormUrl}', function(html) { - $('#supplier-modal-body').html(html); - }).always(function() { - \$btn.prop('disabled', false); - }); - }); - - // Редактирование - $(document).on('click', '.btn-supplier-edit', function(e) { - e.preventDefault(); - var \$btn = $(this); - if (\$btn.prop('disabled')) return; - \$btn.prop('disabled', true); - editingId = \$btn.data('id'); - $('#supplier-modal-title').text('Редактировать поставщика'); - $('#supplier-modal-body').html(loaderHtml); - supplierModal.show(); - $.get('{$updateFormUrl}', {id: editingId}, function(html) { - $('#supplier-modal-body').html(html); - }).always(function() { - \$btn.prop('disabled', false); - }); - }); - - // Сохранение - $(document).on('click', '#btn-supplier-save', function() { - var \$form = $('#supplier-form'); - var url = editingId ? '{$updateUrl}?id=' + editingId : '{$createUrl}'; - - // Сбросить ошибки - \$form.find('.is-invalid').removeClass('is-invalid'); - \$form.find('.invalid-feedback').remove(); - - $.ajax({ - url: url, - type: 'POST', - data: \$form.serialize(), - dataType: 'json', - success: function(resp) { - if (resp.success) { - supplierModal.hide(); - $.pjax.reload({container: '#supplier-pjax'}); - } else if (resp.errors) { - $.each(resp.errors, function(field, messages) { - var \$input = \$form.find('[name="Supplier[' + field + ']"]'); - \$input.addClass('is-invalid'); - \$input.after('
' + messages[0] + '
'); - }); - } - }, - error: function() { - alert('Ошибка сервера'); - } - }); - }); - - // Деактивация - $(document).on('click', '.btn-supplier-delete', function(e) { - e.preventDefault(); - var id = $(this).data('id'); - var name = $(this).data('name'); - - if (!confirm('Деактивировать поставщика "' + name + '"?\\nСвязанные маркировки и маппинги также будут деактивированы.')) { - return; - } - - $.ajax({ - url: '{$deleteUrl}?id=' + id, - type: 'POST', - data: {_csrf: yii.getCsrfToken()}, - dataType: 'json', - success: function(resp) { - if (resp.success) { - $.pjax.reload({container: '#supplier-pjax'}); - } else { - alert(resp.message || 'Ошибка деактивации'); - } - }, - error: function() { - alert('Ошибка сервера'); - } - }); - }); - - // Очистка ошибок при вводе - $(document).on('input change', '#supplier-form input, #supplier-form select', function() { - $(this).removeClass('is-invalid'); - $(this).next('.invalid-feedback').remove(); - }); -})(); -JS; +$config = [ + 'urls' => [ + 'index' => Url::to(['/supplier/index']), + 'createForm' => Url::to(['/supplier/create-form']), + 'updateForm' => Url::to(['/supplier/update-form']), + 'create' => Url::to(['/supplier/create']), + 'update' => Url::to(['/supplier/update']), + 'delete' => Url::to(['/supplier/delete']), + ], +]; -$this->registerJs($js); +$this->registerJs('window.supplierConfig = ' . \yii\helpers\Json::encode($config) . ';'); +$this->registerJsFile('/js/supplier/index.js', ['position' => \yii\web\View::POS_END]); ?> diff --git a/erp24/web/js/supplier/index.js b/erp24/web/js/supplier/index.js new file mode 100644 index 00000000..b96db249 --- /dev/null +++ b/erp24/web/js/supplier/index.js @@ -0,0 +1,120 @@ +(function () { + var cfg = window.supplierConfig || {}; + var urls = cfg.urls || {}; + + var supplierModal = new bootstrap.Modal(document.getElementById('supplier-modal')); + var editingId = null; + + var loaderHtml = '
'; + + function reloadGrid() { + $.ajax({ + url: urls.index, + type: 'GET', + success: function (html) { + var $grid = $('
').html(html).find('#supplier-pjax'); + if ($grid.length) { + $('#supplier-pjax').replaceWith($grid); + } + } + }); + } + + // Создание + $('#btn-supplier-create').on('click', function () { + var $btn = $(this); + if ($btn.prop('disabled')) return; + $btn.prop('disabled', true); + editingId = null; + $('#supplier-modal-title').text('Добавить поставщика'); + $('#supplier-modal-body').html(loaderHtml); + supplierModal.show(); + $.get(urls.createForm, function (html) { + $('#supplier-modal-body').html(html); + }).always(function () { + $btn.prop('disabled', false); + }); + }); + + // Редактирование + $(document).on('click', '.btn-supplier-edit', function (e) { + e.preventDefault(); + var $btn = $(this); + if ($btn.prop('disabled')) return; + $btn.prop('disabled', true); + editingId = $btn.data('id'); + $('#supplier-modal-title').text('Редактировать поставщика'); + $('#supplier-modal-body').html(loaderHtml); + supplierModal.show(); + $.get(urls.updateForm, {id: editingId}, function (html) { + $('#supplier-modal-body').html(html); + }).always(function () { + $btn.prop('disabled', false); + }); + }); + + // Сохранение + $(document).on('click', '#btn-supplier-save', function () { + var $form = $('#supplier-form'); + var url = editingId ? urls.update + '?id=' + editingId : urls.create; + + $form.find('.is-invalid').removeClass('is-invalid'); + $form.find('.invalid-feedback').remove(); + + $.ajax({ + url: url, + type: 'POST', + data: $form.serialize(), + dataType: 'json', + success: function (resp) { + if (resp.success) { + supplierModal.hide(); + reloadGrid(); + } else if (resp.errors) { + $.each(resp.errors, function (field, messages) { + var $input = $form.find('[name="Supplier[' + field + ']"]'); + $input.addClass('is-invalid'); + $input.after('
' + messages[0] + '
'); + }); + } + }, + error: function () { + alert('Ошибка сервера'); + } + }); + }); + + // Деактивация + $(document).on('click', '.btn-supplier-delete', function (e) { + e.preventDefault(); + var id = $(this).data('id'); + var name = $(this).data('name'); + + if (!confirm('Деактивировать поставщика "' + name + '"?\nСвязанные маркировки и маппинги также будут деактивированы.')) { + return; + } + + $.ajax({ + url: urls.delete + '?id=' + id, + type: 'POST', + data: {_csrf: yii.getCsrfToken()}, + dataType: 'json', + success: function (resp) { + if (resp.success) { + reloadGrid(); + } else { + alert(resp.message || 'Ошибка деактивации'); + } + }, + error: function () { + alert('Ошибка сервера'); + } + }); + }); + + // Очистка ошибок при вводе + $(document).on('input change', '#supplier-form input, #supplier-form select', function () { + $(this).removeClass('is-invalid'); + $(this).next('.invalid-feedback').remove(); + }); +})();