Skip to content

Commit

Permalink
Actions redone with SwitchAction
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed May 20, 2015
1 parent 6d37d84 commit bd8f2a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 83 deletions.
111 changes: 30 additions & 81 deletions controllers/DbController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function behaviors()
public function actions()
{
return [
'delete' => [
'delete' => [
'class' => 'hipanel\actions\SwitchAction',
'addFlash' => true,
'success' => Yii::t('app', 'DB delete task has been created successfully'),
Expand All @@ -50,7 +50,7 @@ function ($model) {
]
],
],
'create' => [
'create' => [
'class' => 'hipanel\actions\SwitchAction',
'success' => Yii::t('app', 'DB create task has been created successfully'),
'error' => Yii::t('app', 'Error while creating DB'),
Expand Down Expand Up @@ -83,87 +83,36 @@ function ($model) {
],
],
],
];
}

public function actionCreate()
{
$model = $this->newModel(['scenario' => 'create']);

return $this->perform([
'success' => [
'result' => [
'POST html' => ['redirect', function ($m) { return $m->id; }, 'addFlash' => true],
'POST pjax' => [
'action',
['view', function ($m) { return $m->id; }],
'setUrl' => function ($m) { return ['view', 'id' => $m->id]; },
'addFlash' => true
]
]
],
'result' => [
'GET html' => ['render', ['create', ['model' => $model]]]
],
]);

}

public function actionDelete()
{
return $this->perform([
'success' => [
'message' => Yii::t('app', 'DB deleting task has been created successfully'),
'result' => [
'POST pjax' => [
'action',
['index'],
'addFlash' => true,
'changeUrl' => function ($model) {
return ['index'];
}
'set-password' => [
'class' => 'hipanel\actions\SwitchAction',
'success' => Yii::t('app', 'DB password change task has been created successfully'),
'error' => Yii::t('app', 'Error while DB password changing'),
'POST' => [
'save' => true,
'success' => [
'class' => 'hipanel\actions\ProxyAction',
'action' => 'view',
'params' => function ($action, $model) {
return ['id' => $model->id];
},
]
],
],
'error' => [
'message' => Yii::t('app', 'Error while deleting DB'),
'result' => [
'POST pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }], 'addFlash' => true]
],
],
]);
}

public function actionSetPassword()
{
return $this->perform([
'result' => [ ///
'POST pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }], 'addFlash' => true]
],
]);
}

public function actionTruncate()
{
return $this->perform([
'success' => [
'message' => Yii::t('app', 'DB truncate task has been created successfully'),
],
'error' => [
'message' => Yii::t('app', 'Error while truncating DB'),
],
'result' => [
'pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }]],
'html' => ['render', ['create', function ($model) { return ['id' => $model->id]; }]],
'html2' => ['render', ['create', ['id']]],
'POST html' => ['redirect', ['create']],
'POST html1' => ['redirect', function ($model) { return ['view', 'id' => $model->id]; }],
'POST html2' => ['redirect', ['view', ['id']]],
'POST html3' => ['return'],
'POST html4' => ['renderJson'],
'POST html5' => ['custom',],
],
'addFlash' => true
]);
'truncate' => [
'class' => 'hipanel\actions\SwitchAction',
'success' => Yii::t('app', 'DB truncate task has been created successfully'),
'error' => Yii::t('app', 'Error while truncating DB'),
'POST' => [
'save' => true,
'success' => [
'class' => 'hipanel\actions\ProxyAction',
'action' => 'view',
'params' => function ($action, $model) {
return ['id' => $model->id];
}
],
]
]
];
}
}
4 changes: 2 additions & 2 deletions views/db/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
?>

<?php
echo Html::beginForm(['truncate'], "POST", ['data' => ['pjax' => 1, 'pjax-push' => 0], 'class' => 'inline']);
echo Html::hiddenInput('id', $model->id);
echo Html::beginForm(['truncate'], "POST", ['data' => ['pjax' => 1, 'pjax-push' => 0], 'class' => 'inline']); echo Html::activeHiddenInput($model, 'id');
echo Html::activeHiddenInput($model, 'id');
Modal::begin([
'options' => [
'data-backdrop' => 0
Expand Down

0 comments on commit bd8f2a0

Please sign in to comment.