1 | <?php |
||
16 | class Alert extends Widget |
||
17 | { |
||
18 | //modal type |
||
19 | const TYPE_INFO = 'info'; |
||
20 | const TYPE_ERROR = 'error'; |
||
21 | const TYPE_SUCCESS = 'success'; |
||
22 | const TYPE_WARNING = 'warning'; |
||
23 | const TYPE_QUESTION = 'question'; |
||
24 | //input type |
||
25 | const INPUT_TYPE_TEXT = 'text'; |
||
26 | const INPUT_TYPE_EMAIL = 'email'; |
||
27 | const INPUT_TYPE_PASSWORD = 'password'; |
||
28 | const INPUT_TYPE_NUMBER = 'number'; |
||
29 | const INPUT_TYPE_RANGE = 'range'; |
||
30 | const INPUT_TYPE_TEXTAREA = 'textarea'; |
||
31 | const INPUT_TYPE_SELECT = 'select'; |
||
32 | const INPUT_TYPE_RADIO = 'radio'; |
||
33 | const INPUT_TYPE_CHECKBOX = 'checkbox'; |
||
34 | const INPUT_TYPE_FILE = 'file'; |
||
35 | |||
36 | /** |
||
37 | * All the flash messages stored for the session are displayed and removed from the session |
||
38 | * Defaults to false. |
||
39 | * @var bool |
||
40 | */ |
||
41 | public $useSessionFlash = false; |
||
42 | |||
43 | /** |
||
44 | * @var string alert callback |
||
45 | */ |
||
46 | public $callback = 'function() {}'; |
||
47 | |||
48 | /** |
||
49 | * Initializes the widget |
||
50 | */ |
||
51 | 4 | public function init() |
|
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | 3 | public function run() |
|
75 | |||
76 | 1 | /** |
|
77 | 1 | * @param $session bool|mixed|\yii\web\Session |
|
78 | 1 | * @return array |
|
79 | 1 | */ |
|
80 | public function processFlash($session) |
||
93 | |||
94 | /** |
||
95 | * Get widget options |
||
96 | * |
||
97 | 3 | * @return string |
|
98 | */ |
||
99 | 3 | public function getOptions() |
|
100 | 2 | { |
|
101 | if (isset($this->options['id'])) |
||
102 | 3 | unset($this->options['id']); |
|
103 | 1 | ||
104 | 1 | if (ArrayHelper::isIndexed($this->options)) { |
|
105 | 1 | $str = ''; |
|
106 | foreach ($this->options as $value) { |
||
107 | 1 | $str .= '"' . $value . '",'; |
|
108 | } |
||
109 | 2 | return chop($str, ' ,'); |
|
110 | } |
||
111 | return Json::encode($this->options); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | 1 | * @param array $steps |
|
116 | */ |
||
117 | 1 | public function initFlashWidget($steps = []) |
|
118 | 1 | { |
|
119 | 1 | $steps[0]['text']['type'] = isset($steps[0]['text']['type']) ? $steps[0]['text']['type'] : $steps[0]['type']; |
|
120 | 1 | if (isset($steps[0]['text']['animation']) && $steps[0]['text']['animation'] === false) { |
|
121 | if (isset($steps[0]['text']['customClass'])) { |
||
122 | $this->registerAnimate(); |
||
123 | } |
||
124 | } |
||
125 | $this->options = $steps[0]['text']; |
||
126 | 2 | $this->callback = isset($steps[1]['text']['callback']) ? $steps[1]['text']['callback'] : $this->callback; |
|
127 | $this->initSwal($this->getOptions(), $this->callback); |
||
128 | 2 | } |
|
129 | 2 | ||
130 | 2 | /** |
|
131 | 2 | * @param array $steps |
|
132 | */ |
||
133 | public function initSwalQueue($steps = []) |
||
139 | 2 | ||
140 | /** |
||
141 | * @param string $options |
||
142 | * @param string $callback |
||
143 | */ |
||
144 | 4 | public function initSwal($options = '', $callback = '') |
|
150 | |||
151 | /** |
||
152 | 4 | * Register Animate Assets |
|
153 | */ |
||
154 | public function registerAnimate() |
||
158 | |||
159 | 3 | /** |
|
160 | * Register client assets |
||
161 | */ |
||
162 | public function registerAssets() |
||
171 | |||
172 | /** |
||
173 | * @return bool|mixed|\yii\web\Session |
||
174 | */ |
||
175 | private function getSession() |
||
179 | } |
||
180 |