1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Server module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
6
|
|
|
* @package hipanel-module-server |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\server\widgets; |
12
|
|
|
|
13
|
|
|
use hipanel\modules\server\models\Server; |
14
|
|
|
use hipanel\widgets\ModalButton; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\base\Widget; |
17
|
|
|
use yii\bootstrap\Modal; |
18
|
|
|
use yii\helpers\Html; |
19
|
|
|
|
20
|
|
|
class Wizzard extends Widget |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Server |
24
|
|
|
*/ |
25
|
|
|
public $model; |
26
|
|
|
|
27
|
|
|
/** @var bool */ |
28
|
|
|
public $wizzarded = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array|Modal stores options for [[ModalButton]] |
32
|
|
|
* After Modal creating, stores the object |
33
|
|
|
*/ |
34
|
|
|
protected $modal; |
35
|
|
|
|
36
|
|
|
public function init() |
37
|
|
|
{ |
38
|
|
|
parent::init(); |
39
|
|
|
if ($this->wizzarded === null) { |
40
|
|
|
$this->wizzarded = $this->model->wizzarded; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function run() |
45
|
|
|
{ |
46
|
|
|
$this->modalBegin(); |
47
|
|
|
echo $this->wizzarded ? $this->renderUnWizzardForm() : $this->renderWizzardForm(); |
48
|
|
|
$this->modalEnd(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function modalBegin() |
52
|
|
|
{ |
53
|
|
|
$this->modal = Yii::createObject([ |
54
|
|
|
'class' => ModalButton::class, |
55
|
|
|
'model' => $this->model, |
56
|
|
|
'scenario' => $this->wizzarded ? 'disable-wizzard' : 'enable-wizzard', |
57
|
|
|
'button' => [ |
58
|
|
|
'label' => $this->wizzarded ? Yii::t('hipanel:server', 'UnWizzard') : Yii::t('hipanel:server', 'Wizzard'), |
59
|
|
|
'class' => 'btn btn-default btn-block', |
60
|
|
|
'disabled' => !$this->model->isOperable(), |
61
|
|
|
], |
62
|
|
|
'form' => [ |
63
|
|
|
'enableAjaxValidation' => false, |
64
|
|
|
], |
65
|
|
|
'modal' => [ |
66
|
|
|
'size' => Modal::SIZE_LARGE, |
67
|
|
|
'header' => Html::tag('h4', $this->wizzarded ? Yii::t('hipanel:server', 'Confirm server unwizzard') : Yii::t('hipanel:server', 'Confirm server wizzard')), |
68
|
|
|
'headerOptions' => ['class' => 'label-warning'], |
69
|
|
|
'footer' => [ |
70
|
|
|
'label' => $this->wizzarded ? Yii::t('hipanel:server', 'UnWizzard') : Yii::t('hipanel:server', 'Wizzard'), |
71
|
|
|
'data-loading-text' => $this->wizzarded ? Yii::t('hipanel:server', 'UnWizzarding...') : Yii::t('hipanel:server', 'Wizzarding...'), |
72
|
|
|
'class' => $this->wizzarded ? 'btn btn-warning' : 'btn btn-success', |
73
|
|
|
], |
74
|
|
|
], |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function renderUnWizzardForm() |
79
|
|
|
{ |
80
|
|
|
return Html::tag('span', Yii::t('hipanel', 'Are you sure?'), ['class' => 'text-danger']); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function renderWizzardForm() |
84
|
|
|
{ |
85
|
|
|
return $this->render('enable-wizzard', [ |
86
|
|
|
'model' => $this->model, |
87
|
|
|
'form' => $this->modal->form, |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function modalEnd() |
92
|
|
|
{ |
93
|
|
|
$this->modal->run(); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|