From 601832b506d99238f9d1ce4d2dd21fdc149833e5 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Thu, 4 Sep 2025 11:07:04 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D0=BA=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...ducts1cNomenclatureActualityController.php | 9 ++- .../products1cNomenclatureActuality/index.js | 64 ++++++++++++------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index e6efb5fe..58540640 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -4,6 +4,7 @@ namespace app\controllers; use Yii; use yii\db\Query; +use yii\web\BadRequestHttpException; use yii\web\Response; use yii_app\api3\modules\v1\models\Sales; use yii_app\records\Products1cAdditionalCharacteristics; @@ -539,10 +540,16 @@ class Products1cNomenclatureActualityController extends Controller return $this->redirect(['index']); } - public function actionAjaxDelete($id) + public function actionAjaxDelete() { Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $id = $id ?? $request->post('id') ?? $request->get('id'); + Yii::error(json_encode($id), JSON_UNESCAPED_UNICODE); + if (empty($id)) { + throw new BadRequestHttpException('Missing parameter: id'); + } try { $model = $this->findModel($id); $model->delete(); diff --git a/erp24/web/js/products1cNomenclatureActuality/index.js b/erp24/web/js/products1cNomenclatureActuality/index.js index ee376eb1..361ce16a 100644 --- a/erp24/web/js/products1cNomenclatureActuality/index.js +++ b/erp24/web/js/products1cNomenclatureActuality/index.js @@ -260,33 +260,49 @@ document.addEventListener("DOMContentLoaded", () => { } } - $(document).on('click', '.clear-interval-btn', function () { - let btn = $(this); - let id = btn.data('id'); +}); - if (!confirm('Удалить запись?')) { - return; - } - $.ajax({ - url: '/products1c-nomenclature-actuality/ajax-delete', - type: 'POST', - data: {id: id, _csrf: yii.getCsrfToken()}, - success: function (response) { - if (response.success) { - btn.closest('tr, .item-row').fadeOut(300, function () { - $(this).remove(); - }); - } else { - alert('Ошибка: ' + response.message); - } - }, - error: function () { - alert('Произошла ошибка при удалении'); - } - }); - }); +$(document).on('click', '.clear-interval-btn', function () { + let btn = $(this); + let id = btn.data('id'); + + if (!confirm('Удалить запись?')) { + return; + } + $.ajax({ + url: '/products1c-nomenclature-actuality/ajax-delete', + type: 'POST', + data: {id: id, _csrf: yii.getCsrfToken()}, + success: function (response) { + if (response.success) { + btn.closest('tr, .table-success').removeClass('table-success'); + const scope = btn.closest('td'); + const selects = scope.find('select.from-month, select.to-month'); + selects.each(function () { + const s = $(this); + + s.prop('selectedIndex', 0).val(''); + + if (s.hasClass('select2-hidden-accessible')) { + s.val(null).trigger('change.select2'); + } else { + s.trigger('change'); + } + }); + // btn.closest('tr, .table-success').fadeOut(300, function () { + // $(this).remove(); + // }); + alert(response.message); + } else { + alert('Ошибка: ' + response.message); + } + }, + error: function () { + alert('Произошла ошибка при удалении'); + } + }); }); -- 2.39.5