1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\server\controllers; |
4
|
|
|
|
5
|
|
|
use hipanel\actions\IndexAction; |
6
|
|
|
use hipanel\actions\SmartCreateAction; |
7
|
|
|
use hipanel\actions\SmartDeleteAction; |
8
|
|
|
use hipanel\actions\SmartPerformAction; |
9
|
|
|
use hipanel\actions\SmartUpdateAction; |
10
|
|
|
use hipanel\actions\ValidateFormAction; |
11
|
|
|
use hipanel\actions\ViewAction; |
12
|
|
|
use hipanel\base\CrudController; |
13
|
|
|
use Yii; |
14
|
|
|
|
15
|
|
|
class ConfigController extends CrudController |
16
|
|
|
{ |
17
|
|
|
public function actions() |
18
|
|
|
{ |
19
|
|
|
return array_merge(parent::actions(), [ |
20
|
|
|
'index' => [ |
21
|
|
|
'class' => IndexAction::class, |
22
|
|
|
], |
23
|
|
|
'view' => [ |
24
|
|
|
'class' => ViewAction::class, |
25
|
|
|
], |
26
|
|
|
'create' => [ |
27
|
|
|
'class' => SmartCreateAction::class, |
28
|
|
|
'scenario' => 'create', |
29
|
|
|
'success' => Yii::t( |
30
|
|
|
'hipanel:server:config', |
31
|
|
|
'The configuration has been successfully created' |
32
|
|
|
), |
33
|
|
|
], |
34
|
|
|
'update' => [ |
35
|
|
|
'class' => SmartUpdateAction::class, |
36
|
|
|
'scenario' => 'update', |
37
|
|
|
'success' => Yii::t( |
38
|
|
|
'hipanel:server:config', |
39
|
|
|
'The configuration has been successfully updated' |
40
|
|
|
), |
41
|
|
|
], |
42
|
|
|
'delete' => [ |
43
|
|
|
'class' => SmartDeleteAction::class, |
44
|
|
|
'success' => Yii::t( |
45
|
|
|
'hipanel:server:config', |
46
|
|
|
'The configuration has been deleted' |
47
|
|
|
), |
48
|
|
|
'error' => Yii::t( |
49
|
|
|
'hipanel:server:config', |
50
|
|
|
'Failed to delete the configuration' |
51
|
|
|
), |
52
|
|
|
], |
53
|
|
|
'enable' => [ |
54
|
|
|
'class' => SmartPerformAction::class, |
55
|
|
|
'success' => Yii::t( |
56
|
|
|
'hipanel:server:config', |
57
|
|
|
'The configuration has been enabled' |
58
|
|
|
), |
59
|
|
|
'on beforeSave' => function ($event) { |
60
|
|
|
$action = $event->sender; |
61
|
|
|
foreach ($action->collection->models as $model) { |
62
|
|
|
if ($id = Yii::$app->request->get('id')) { |
63
|
|
|
$model->id = $id; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
}, |
67
|
|
|
], |
68
|
|
|
'disable' => [ |
69
|
|
|
'class' => SmartPerformAction::class, |
70
|
|
|
'success' => Yii::t( |
71
|
|
|
'hipanel:server:config', |
72
|
|
|
'The configuration has been disabled' |
73
|
|
|
), |
74
|
|
|
'on beforeSave' => function ($event) { |
75
|
|
|
$action = $event->sender; |
76
|
|
|
foreach ($action->collection->models as $model) { |
77
|
|
|
if ($id = Yii::$app->request->get('id')) { |
78
|
|
|
$model->id = $id; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
}, |
82
|
|
|
], |
83
|
|
|
'validate-form' => [ |
84
|
|
|
'class' => ValidateFormAction::class, |
85
|
|
|
], |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|