1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: execut |
5
|
|
|
* Date: 12/26/17 |
6
|
|
|
* Time: 4:15 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace execut\actions\widgets; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use execut\yii\jui\Widget; |
13
|
|
|
use yii\bootstrap\Modal; |
14
|
|
|
use yii\helpers\ArrayHelper; |
15
|
|
|
use yii\helpers\Html; |
16
|
|
|
|
17
|
|
|
class EditDialog extends Widget |
18
|
|
|
{ |
19
|
|
|
public $model; |
20
|
|
|
public $uniqueId; |
21
|
|
|
public $alertId; |
22
|
|
|
public $toggleButtonOptions = false; |
23
|
|
|
public $modalOptions = []; |
24
|
|
|
public function run() |
25
|
|
|
{ |
26
|
|
|
$this->clientOptions['alertId'] = $this->alertId; |
27
|
|
|
$this->registerWidget(); |
28
|
|
|
|
29
|
|
|
echo $this->renderToggleButton(); |
30
|
|
|
if (!\yii::$app->request->isPjax) { |
31
|
|
|
$this->view->beginBlock('modalContainer'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
echo $this->_beginContainer(); |
35
|
|
|
Modal::begin(ArrayHelper::merge([ |
36
|
|
|
'id' => $this->id . '-modal', |
37
|
|
|
'header' => $this->getHeader(), |
38
|
|
|
'options' => [ |
39
|
|
|
'class' => 'pull-left' |
40
|
|
|
], |
41
|
|
|
], $this->modalOptions)); |
42
|
|
|
echo \execut\actions\widgets\DetailView::widget([ |
43
|
|
|
'id' => $this->id . '-detail-view', |
44
|
|
|
'mode' => 'edit', |
45
|
|
|
'buttonsTemplate' => '{save}', |
46
|
|
|
'uniqueId' => $this->uniqueId, |
47
|
|
|
'model' => $this->model, |
48
|
|
|
'formOptions' => [ |
49
|
|
|
'enableAjaxValidation' => true, |
50
|
|
|
'validateOnSubmit' => true, |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
Modal::end(); |
55
|
|
|
echo $this->_endContainer(); |
56
|
|
|
|
57
|
|
|
if (!\yii::$app->request->isPjax) { |
58
|
|
|
$this->view->endBlock('modalContainer'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public $header = null; |
63
|
|
|
public function getHeader() { |
64
|
|
|
return $this->header; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Renders the toggle button. |
69
|
|
|
* @return string the rendering result |
70
|
|
|
*/ |
71
|
|
|
protected function renderToggleButton() |
72
|
|
|
{ |
73
|
|
|
if (($toggleButton = $this->getToggleButton()) === false) { |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$tag = ArrayHelper::remove($toggleButton, 'tag', 'button'); |
78
|
|
|
$label = ArrayHelper::remove($toggleButton, 'label', 'Show'); |
79
|
|
|
if ($tag === 'button' && !isset($toggleButton['type'])) { |
80
|
|
|
$toggleButton['type'] = 'button'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return Html::tag($tag, $label, $toggleButton); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getToggleButton() { |
87
|
|
|
if ($this->toggleButtonOptions === false) { |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return ArrayHelper::merge([ |
92
|
|
|
'id' => $this->id . '-add-button', |
93
|
|
|
'label' => $this->getHeader(), |
94
|
|
|
'class' => 'btn btn-default', |
95
|
|
|
], $this->toggleButtonOptions); |
96
|
|
|
} |
97
|
|
|
} |