From fcd74198e933aa987a98f3bcb618b03067c3198a Mon Sep 17 00:00:00 2001 From: fomichev Date: Mon, 25 Nov 2024 17:46:07 +0300 Subject: [PATCH] =?utf8?q?=D0=97=D0=B0=D0=B4=D0=B2=D0=BE=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9=20?= =?utf8?q?=D0=B8=20=D0=BF=D1=80=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?utf8?q?=D0=B5=D0=B9=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20=D0=BF?= =?utf8?q?=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=B8?= =?utf8?q?=D0=BD=D0=B4=D0=B5=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../crud/Product1cReplacementController.php | 20 +++++++++++++++++-- .../crud/product1cReplacement/multy-form.js | 14 ++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/erp24/controllers/crud/Product1cReplacementController.php b/erp24/controllers/crud/Product1cReplacementController.php index 727a00be..204851df 100644 --- a/erp24/controllers/crud/Product1cReplacementController.php +++ b/erp24/controllers/crud/Product1cReplacementController.php @@ -356,20 +356,36 @@ class Product1cReplacementController extends Controller Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $model = $this->findModel($id); + if ($model) { + + $guid = $model->guid; + + + $remainingRecords = Product1cReplacement::find() + ->where(['guid' => $guid]) + ->andWhere(['deleted_at' => null]) + ->count(); + $stateBefore = $model->guid_replacement; $this->logReplacementAction( $model->id, $stateBefore, 'Запись удалена' ); - if ($model->softDelete()) { - return ['success' => true]; + if ($model->softDelete()) { + return [ + 'success' => true, + 'message' => 'Запись успешно удалена', + 'redirect' => $remainingRecords <= 1, + ]; } } return ['success' => false, 'message' => 'Ошибка при удалении записи.']; } + + /** * Finds the Product1CReplacement model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/erp24/web/js/crud/product1cReplacement/multy-form.js b/erp24/web/js/crud/product1cReplacement/multy-form.js index 37a2849f..ac52caa5 100644 --- a/erp24/web/js/crud/product1cReplacement/multy-form.js +++ b/erp24/web/js/crud/product1cReplacement/multy-form.js @@ -1,7 +1,7 @@ function initReplacementHandlers() { let counter = $('.guid-replacement-select').length; - $('#add-guid-replacement').on('click', function () { + $('#add-guid-replacement').off('click').on('click', function () { counter++; let newField = `
@@ -46,12 +46,12 @@ function initReplacementHandlers() { }); }); - $(document).on('click', '.remove-guid-replacement', function () { + $(document).off('click', '.remove-guid-replacement').on('click', '.remove-guid-replacement', function () { let target = $(this).data('target'); $(target).remove(); }); - $(document).on('click', '.delete-guid-replacement', function (e) { + $(document).off('click', '.delete-guid-replacement').on('click', '.delete-guid-replacement', function (e) { e.preventDefault(); if (!confirm('Вы уверены, что хотите удалить эту запись?')) { return; @@ -64,8 +64,12 @@ function initReplacementHandlers() { success: function(data) { console.log(data); if (data.success) { - - $.pjax.reload({container: '#pjax-container', async: false}); + alert(data.message); + if (data.redirect) { + window.location.href = '/crud/product1c-replacement/index'; + } else { + $.pjax.reload({container: '#pjax-container', async: false}); + } } else { alert(data.message || 'Ошибка при удалении записи.'); } -- 2.39.5