feat: add delete button

This commit is contained in:
b1ek 2024-08-20 16:53:14 +10:00
parent b0b16b3d2e
commit 9193ab8e6d
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 38 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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',
],