From 9193ab8e6d9b4c65c5e41a5d668b0ba13e01c782 Mon Sep 17 00:00:00 2001 From: b1ek Date: Tue, 20 Aug 2024 16:53:14 +1000 Subject: [PATCH] feat: add delete button --- controllers/ListController.php | 20 +++++++++++++++++++- views/list/index.php | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/controllers/ListController.php b/controllers/ListController.php index f573bf8..8031cba 100644 --- a/controllers/ListController.php +++ b/controllers/ListController.php @@ -30,7 +30,7 @@ class ListController extends \yii\web\Controller $id = $request->getQueryParam('id'); $parameter = Parameter::findOne($id); - if ($id !== null && $parameter !== null) { + if ($parameter === null && $id !== null) { throw new NotFoundHttpException(); } @@ -59,4 +59,22 @@ class ListController extends \yii\web\Controller ] ); } + + public function actionDelicon(Request $request) + { + $id = $request->getQueryParam('id'); + $type = $request->getQueryParam('type'); + if ($id === null || !($type == 'normal' || $type == 'gray')) { + return $this->redirect('/list'); + } + + $param = Parameter::find()->where([ 'id' => $id ])->one(); + if ($param === null) { + return $this->redirect('/list'); + } + + $param->setAttribute($type == 'normal' ? 'icon' : 'icon_gray', null); + $param->save(); + return $this->redirect('/list?ParameterSearch[id]='. $id); + } } diff --git a/views/list/index.php b/views/list/index.php index 2bb890e..b7441ef 100644 --- a/views/list/index.php +++ b/views/list/index.php @@ -37,6 +37,15 @@ $this->title = 'params list'; }, 'format' => 'raw', ], + [ + 'label' => 'Delete icon', + 'value' => function (Parameter $model) { + if ($model->icon) { + return Html::a('Delete icon', '/list/delicon?type=normal&id=' . $model->id, [ 'class' => 'btn btn-sx btn-danger' ]); + } + }, + 'format' => 'raw', + ], [ 'label' => 'Gray Icon', 'value' => function (Parameter $model) { @@ -47,10 +56,19 @@ $this->title = 'params list'; }, 'format' => 'raw', ], + [ + 'label' => 'Delete gray icon', + 'value' => function (Parameter $model) { + if ($model->iconGray) { + return Html::a('Delete gray icon', '/list/delicon?type=gray&id=' . $model->id, [ 'class' => 'btn btn-sx btn-danger' ]); + } + }, + 'format' => 'raw', + ], [ 'label' => 'Edit', 'value' => function (Parameter $model) { - return Html::a('Edit', '/list/edit?id=' . $model->id); + return Html::a('Edit', '/list/edit?id=' . $model->id, [ 'class' => 'btn btn-sx btn-secondary' ]); }, 'format' => 'raw', ],