From: fomichev Date: Mon, 25 Nov 2024 14:46:07 +0000 (+0300) Subject: Задвоение удалений и при удалении последней записи переход на индекс X-Git-Tag: 1.7~221^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=fcd74198e933aa987a98f3bcb618b03067c3198a;p=erp24_rep%2Fyii-erp24%2F.git Задвоение удалений и при удалении последней записи переход на индекс --- 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 || 'Ошибка при удалении записи.'); }