From 16b1be8c763562b7cac877d5243b6e54cf67200f Mon Sep 17 00:00:00 2001 From: SilverFire - Dima Naumenko Date: Fri, 8 May 2015 18:26:12 +0300 Subject: [PATCH] In the middle of nowhere. Playing with SwitchAction --- controllers/DbController.php | 98 ++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/controllers/DbController.php b/controllers/DbController.php index 15f25f6e..18676f2d 100644 --- a/controllers/DbController.php +++ b/controllers/DbController.php @@ -13,7 +13,8 @@ class DBController extends CrudController { - public function behaviors () { + public function behaviors() + { return [ 'verbs' => [ 'class' => VerbFilter::className(), @@ -24,7 +25,91 @@ public function behaviors () { ]; } - public function actionCreate () { + public function actions() + { + return [ + 'delete' => [ + 'class' => 'hipanel\actions\SwitchAction', + 'addFlash' => true, + 'success' => Yii::t('app', 'DB delete task has been created successfully'), + 'error' => Yii::t('app', 'Error while deleting DB'), + 'POST html' => [ + 'perform' => true, + 'success' => [ + 'class' => 'hipanel\actions\RedirectAction', + 'url' => ['index'], + ], + 'error' => [ + 'class' => 'hipanel\actions\RedirectAction', + 'url' => [ + 'view', + function ($model) { + return ['id' => $model->id]; + } + ], + ] + ], + ], + 'create' => [ + 'class' => 'hipanel\actions\SwitchAction', + 'addFlash' => true, + 'success' => Yii::t('app', 'DB delete task has been created successfully'), + 'error' => Yii::t('app', 'Error while deleting DB'), + 'GET html | GET pjax' => [ + 'class' => 'hipanel\actions\RenderAction', + 'view' => 'create', + 'params' => $this->newModel(['scenario' => 'create']) + ], + 'POST html' => [ + 'perform' => true, + 'success' => [ + 'class' => 'hipanel\actions\RedirectAction', + 'url' => [ + 'view', + function ($model) { + return ['id' => $model->id]; + } + ], + ], + 'error' => [ + 'class' => 'hipanel\actions\RenderAction', + 'url' => [ + 'create', + function ($model) { + return compact('model'); + } + ], + ], + ], + 'POST pjax' => [ + 'perform' => true, + 'success' => [ + 'class' => 'hipanel\actions\RedirectAction', + 'url' => [ + 'view', + function ($model) { + return ['id' => $model->id]; + } + ], + 'pjaxLocationHeader' => true, + ], + 'error' => [ + 'class' => 'hipanel\actions\RenderAction', + 'url' => [ + 'create', + function ($model) { + return [$model->model]; + } + ], + 'pjaxLocationHeader' => true, + ], + ], + ], + ]; + } + + public function actionCreate() + { $model = $this->newModel(['scenario' => 'create']); return $this->perform([ @@ -46,7 +131,8 @@ public function actionCreate () { } - public function actionDelete () { + public function actionDelete() + { return $this->perform([ 'success' => [ 'message' => Yii::t('app', 'DB deleting task has been created successfully'), @@ -70,7 +156,8 @@ public function actionDelete () { ]); } - public function actionSetPassword () { + public function actionSetPassword() + { return $this->perform([ 'result' => [ /// 'POST pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }], 'addFlash' => true] @@ -78,7 +165,8 @@ public function actionSetPassword () { ]); } - public function actionTruncate () { + public function actionTruncate() + { return $this->perform([ 'success' => [ 'message' => Yii::t('app', 'DB truncate task has been created successfully'),