From a1cb2762b747e48ce18adfe5f7b92524e4cccec6 Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 15 Jan 2025 17:42:49 +0300 Subject: [PATCH] =?utf8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=20=D1=80=D0=B5?= =?utf8?q?=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?utf8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD?= =?utf8?q?=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../controllers/StoresTypeListController.php | 38 +++++++- erp24/views/stores-type-list/index.php | 93 +++++++++++++++++-- 2 files changed, 121 insertions(+), 10 deletions(-) diff --git a/erp24/controllers/StoresTypeListController.php b/erp24/controllers/StoresTypeListController.php index aaf8a04d..923faec6 100644 --- a/erp24/controllers/StoresTypeListController.php +++ b/erp24/controllers/StoresTypeListController.php @@ -40,15 +40,36 @@ class StoresTypeListController extends Controller public function actionIndex() { $model = new StoresTypeList(); - if ($this->request->isPost) { - if ($model->load($this->request->post()) && $model->validate()) { + $editId = $this->request->post('editId'); // Получаем ID для редактирования + + if ($model->load($this->request->post())) { + if ($editId) { + $existingModel = StoresTypeList::findOne($editId); + if ($existingModel) { + $existingModel->type_name = $model->type_name; + $existingModel->type_alias = strtolower(preg_replace('/[\s-]+/', '_', $model->type_name)); + if ($existingModel->save()) { + Yii::$app->session->setFlash('success', 'Запись успешно обновлена.'); + return $this->redirect(['index']); + } + } + } else { $model->type_alias = strtolower(preg_replace('/[\s-]+/', '_', $model->type_name)); - if ($model->save()) { - Yii::$app->session->setFlash('success', 'Тип магазина успешно сохранен.'); + Yii::$app->session->setFlash('success', 'Новая запись успешно создана.'); return $this->redirect(['index']); } } + Yii::$app->session->setFlash('error', 'Ошибка сохранения.'); + } + + $deleteId = $this->request->post('deleteId'); + if ($deleteId) { + $deleteModel = StoresTypeList::findOne($deleteId); + if ($deleteModel && $deleteModel->delete()) { + Yii::$app->session->setFlash('success', 'Запись успешно удалена.'); + return $this->redirect(['index']); + } } $dataProvider = new ActiveDataProvider([ @@ -61,6 +82,15 @@ class StoresTypeListController extends Controller ]); } + public function actionGetRecord($id) + { + $model = StoresTypeList::findOne($id); + if ($model) { + return $this->asJson(['type_name' => $model->type_name]); + } + return $this->asJson(['error' => 'Запись не найдена']); + } + /** * Displays a single StoresTypeList model. * @param int $id ID diff --git a/erp24/views/stores-type-list/index.php b/erp24/views/stores-type-list/index.php index a7de5094..7d689fde 100644 --- a/erp24/views/stores-type-list/index.php +++ b/erp24/views/stores-type-list/index.php @@ -2,7 +2,6 @@ use yii\widgets\ActiveForm; use yii\widgets\Pjax; -use yii_app\records\StoresTypeList; use yii\helpers\Html; use yii\helpers\Url; use yii\grid\ActionColumn; @@ -32,17 +31,32 @@ $this->params['breadcrumbs'][] = $this->title;
- ['data-pjax' => true], - ]); ?> + ['data-pjax' => true]]); ?> - field($model, 'type_name')->textInput(['maxlength' => true])->label('Название типа') ?> + field($model, 'type_name')->textInput(['id' => 'type-name-field', 'maxlength' => true])->label('Название') ?> - 'btn btn-success']) ?> + 'edit-id']) ?> + 'delete-id']) ?> + + 'btn btn-success', 'id' => 'save-btn']) ?> + 'btn btn-secondary', 'id' => 'cancel-btn']) ?> +
+
    + getModels() as $item): ?> +
  • + type_name) ?> +
  • + +
+
+ 'btn btn-danger d-none', 'id' => 'delete-btn']) ?> + 'btn btn-primary d-none', 'id' => 'edit-btn']) ?>
+ + $dataProvider, 'columns' => [ @@ -64,3 +78,70 @@ $this->params['breadcrumbs'][] = $this->title; + + \ No newline at end of file -- 2.39.5