|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) CJT TERABYTE INC |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @link: https://gitlab.com/cjtterabytesoft/tadweb |
|
9
|
|
|
* @author: Wilmer Arámbula <[email protected]> |
|
10
|
|
|
* @copyright: (c) CJT TERABYTE INC |
|
11
|
|
|
* @widgets: [ToolBar] |
|
12
|
|
|
* @since: 1.0 |
|
13
|
|
|
* @yii: 3.0 |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace cjtterabytesoft\widgets; |
|
17
|
|
|
|
|
18
|
|
|
use yii\base\Widget; |
|
19
|
|
|
use yii\bootstrap4\ButtonDropdown; |
|
20
|
|
|
use yii\helpers\Html; |
|
21
|
|
|
use yii\helpers\Url; |
|
22
|
|
|
|
|
23
|
|
|
class ToolBar extends Widget |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string the tag to use to render panel title icon |
|
27
|
|
|
*/ |
|
28
|
|
|
public $_tag_icon_panel = 'i'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string the label to use to render panel title icon |
|
32
|
|
|
*/ |
|
33
|
|
|
public $_label_icon_panel = ''; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var array the options to use to render panel title icons |
|
37
|
|
|
*/ |
|
38
|
|
|
public $_options_icon_panel = ['class' => 'fas fa-th']; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string the label panel title |
|
42
|
|
|
*/ |
|
43
|
|
|
public $_title_panel = ''; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string the tag to use to render panel title |
|
47
|
|
|
*/ |
|
48
|
|
|
public $_tag_container_panel_header = 'div'; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var array the options to use to render panel title |
|
52
|
|
|
*/ |
|
53
|
|
|
public $_options_container_panel_header = ['class' => 'peers bg-primary text-white align-content-center p-15']; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string the tag to use to render panel title left |
|
57
|
|
|
*/ |
|
58
|
|
|
public $_tag_left_panel_header = 'div'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array the options to use to render panel title left |
|
62
|
|
|
*/ |
|
63
|
|
|
public $_options_left_panel_header = ['class' => 'float-left']; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var string the tag to use to render panel title rigth |
|
67
|
|
|
*/ |
|
68
|
|
|
public $_tag_rigth_panel_header = 'div'; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var array the options to use to render panel title rigth |
|
72
|
|
|
*/ |
|
73
|
|
|
public $_options_rigth_panel_header = ['class' => 'float-right ml-auto']; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var string the tag to use to render container panel button |
|
77
|
|
|
*/ |
|
78
|
|
|
public $_tag_container_panel_button = 'div'; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var array the options to use to render container panel button |
|
82
|
|
|
*/ |
|
83
|
|
|
public $_options_container_panel_button = ['class' => 'peers bd p-15']; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var string the tag to use to render panel button left |
|
87
|
|
|
*/ |
|
88
|
|
|
public $_tag_left_panel_button = 'div'; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var array the options to use to render panel button left |
|
92
|
|
|
*/ |
|
93
|
|
|
public $_options_left_panel_button = ['class' => 'float-left']; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var string the tag to use to render panel button rigth |
|
97
|
|
|
*/ |
|
98
|
|
|
public $_tag_rigth_panel_button = 'div'; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @var array the options to use to render panel button rigth |
|
102
|
|
|
*/ |
|
103
|
|
|
public $_options_rigth_panel_button = ['class' => 'float-right ml-auto']; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @var bool whether the label should be HTML-encoded. |
|
107
|
|
|
*/ |
|
108
|
|
|
public $_encodeLabel = true; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @var string use to panel header title |
|
112
|
|
|
*/ |
|
113
|
|
|
public $_panel_header_title = ''; |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @var boolean show/hidden panel button create |
|
117
|
|
|
*/ |
|
118
|
|
|
public $_button_create = true; |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @var boolean show/hidden panel button delete |
|
122
|
|
|
*/ |
|
123
|
|
|
public $_button_delete = false; |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @var boolean show/hidden panel button filter |
|
127
|
|
|
*/ |
|
128
|
|
|
public $_button_filter = true; |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @var boolean show/hidden panel button pages |
|
132
|
|
|
*/ |
|
133
|
|
|
public $_button_pages = true; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @var boolean show/hidden panel button reset |
|
137
|
|
|
*/ |
|
138
|
|
|
public $_button_reset = true; |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @var boolean show/hidden panel button update |
|
142
|
|
|
*/ |
|
143
|
|
|
public $_button_update = false; |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @var array ModelClass |
|
147
|
|
|
*/ |
|
148
|
|
|
public $_model = []; |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Initializes the widget. |
|
152
|
|
|
* If you override this method, make sure you call the parent implementation first. |
|
153
|
|
|
*/ |
|
154
|
|
|
public function init() |
|
155
|
|
|
{ |
|
156
|
|
|
parent::init(); |
|
157
|
|
|
|
|
158
|
|
|
$iconpanel = $this->renderIcon(); |
|
159
|
|
|
$titlepanel = $this->renderTitlePanel(); |
|
160
|
|
|
$this->_panel_header_title = $iconpanel . ' ' . '<b>' . $titlepanel . '</b>'; |
|
161
|
|
|
|
|
162
|
|
|
echo $this->renderPanelHeader() . $this->renderPanelBar(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
private function renderButtonCreate() |
|
166
|
|
|
{ |
|
167
|
|
|
$button_create = ''; |
|
168
|
|
|
|
|
169
|
|
|
if ($this->_button_create) { |
|
170
|
|
|
$button_create = Html::a( |
|
171
|
|
|
Html::tag('i', '', ['class' => 'fas fa-plus']), |
|
172
|
|
|
['create'], |
|
173
|
|
|
['class' => 'btn btn-lg bgc-green-500 c-white', 'title' => \yii::t('toolbar', 'Add')] |
|
174
|
|
|
); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
return $button_create; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
private function renderButtonDelete() |
|
|
|
|
|
|
181
|
|
|
{ |
|
182
|
|
|
$button_delete = ''; |
|
183
|
|
|
|
|
184
|
|
|
if ($this->_button_delete) { |
|
185
|
|
|
$button_create = Html::a( |
|
|
|
|
|
|
186
|
|
|
Html::tag('i', '', ['class' => 'fas fa-trash']), |
|
187
|
|
|
['delete', 'id' => $this->_model->tableSchema->primaryKey], |
|
188
|
|
|
[ |
|
189
|
|
|
'class' => 'btn btn-lg btn-danger c-white', |
|
190
|
|
|
'title' => \yii::t('toolbar', 'Delete'), |
|
191
|
|
|
'data' => [ |
|
192
|
|
|
'confirm' => \yii::t('toolbar', 'Are you sure you want to delete this item?'), |
|
193
|
|
|
'method' => 'post', |
|
194
|
|
|
], |
|
195
|
|
|
] |
|
196
|
|
|
); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
return $button_delete; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
private function renderButtonFilter() |
|
203
|
|
|
{ |
|
204
|
|
|
$button_filter = ''; |
|
205
|
|
|
|
|
206
|
|
|
if ($this->_button_filter) { |
|
207
|
|
|
$button_filter = Html::a( |
|
208
|
|
|
Html::tag('i', '', ['class' => 'fas fa-filter']), |
|
209
|
|
|
Url::current(), |
|
210
|
|
|
['id' => 'filter-checked-btn', 'class' => 'simple btn btn-lg bgc-blue-500 mL-2 c-white', 'title' => \yii::t('toolbar', 'Filter')] |
|
211
|
|
|
); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
return $button_filter; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
private function renderButtonPages() |
|
218
|
|
|
{ |
|
219
|
|
|
$button_pages = ''; |
|
220
|
|
|
|
|
221
|
|
|
if ($this->_button_pages) { |
|
222
|
|
|
$button_pages = ButtonDropdown::widget([ |
|
223
|
|
|
'buttonOptions' => ['class' => 'btn-sm btn-primary ai-c'], |
|
224
|
|
|
'label' => \yii::t('toolbar', 'Page Size'), |
|
225
|
|
|
'options' => ['class' => 'float-right'], |
|
226
|
|
|
'dropdown' => [ |
|
227
|
|
|
'items' => [ |
|
228
|
|
|
['label' => '1', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '1'])], |
|
229
|
|
|
['label' => '5', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '5'])], |
|
230
|
|
|
['label' => '10', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '10'])], |
|
231
|
|
|
['label' => '20', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '20'])], |
|
232
|
|
|
['label' => '25', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '25'])], |
|
233
|
|
|
['label' => '50', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '50'])], |
|
234
|
|
|
], |
|
235
|
|
|
], |
|
236
|
|
|
]); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
return $button_pages; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
private function renderButtonReset() |
|
243
|
|
|
{ |
|
244
|
|
|
$button_reset = ''; |
|
245
|
|
|
|
|
246
|
|
|
if ($this->_button_reset) { |
|
247
|
|
|
$button_reset = Html::a( |
|
248
|
|
|
Html::tag('i', '', ['class' => 'fas fa-sync-alt']), |
|
249
|
|
|
['index', [], []], |
|
250
|
|
|
['class' => 'btn btn-lg bgc-indigo-500 mL-2 c-white', 'title' => \yii::t('toolbar', 'Reset')] |
|
251
|
|
|
); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
return $button_reset; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
private function renderButtonUpdate($model) |
|
|
|
|
|
|
258
|
|
|
{ |
|
259
|
|
|
$button_update = ''; |
|
260
|
|
|
|
|
261
|
|
|
if ($this->_button_update) { |
|
262
|
|
|
$button_update = Html::a( |
|
263
|
|
|
Html::tag('i', '', ['class' => 'fas fa-edit']), |
|
264
|
|
|
['update', 'id' => $this->_model->tableSchema->primaryKey], |
|
265
|
|
|
['class' => 'btn btn-lg btn-info mL-2 c-white', 'title' => \yii::t('toolbar', 'Update')] |
|
266
|
|
|
); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
return $button_update; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
private function renderIcon() |
|
273
|
|
|
{ |
|
274
|
|
|
return Html::tag($this->_tag_icon_panel, $this->_label_icon_panel, $this->_options_icon_panel); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
private function renderPanelBar() |
|
278
|
|
|
{ |
|
279
|
|
|
$panel_button = Html::begintag($this->_tag_container_panel_button, $this->_options_container_panel_button) . |
|
280
|
|
|
Html::begintag($this->_tag_left_panel_button, $this->_options_left_panel_button) . |
|
281
|
|
|
$this->renderButtonPages() . |
|
282
|
|
|
Html::endTag($this->_tag_left_panel_button) . |
|
283
|
|
|
Html::begintag($this->_tag_rigth_panel_button, $this->_options_rigth_panel_button) . |
|
284
|
|
|
$this->renderButtonCreate() . |
|
285
|
|
|
$this->renderButtonFilter() . |
|
286
|
|
|
$this->renderButtonReset() . |
|
287
|
|
|
Html::endTag($this->_tag_rigth_panel_button) . |
|
288
|
|
|
Html::endTag($this->_tag_container_panel_button); |
|
289
|
|
|
return $panel_button; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
private function renderPanelHeader() |
|
293
|
|
|
{ |
|
294
|
|
|
$pageSize = \yii::$app->params['defaultPageSize']; |
|
295
|
|
|
|
|
296
|
|
|
if (!is_null(\yii::$app->session->get('pageSize'))) { |
|
|
|
|
|
|
297
|
|
|
$pageSize = \yii::$app->session->get('pageSize'); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
$panel_header = Html::begintag($this->_tag_container_panel_header, $this->_options_container_panel_header) . |
|
301
|
|
|
Html::begintag($this->_tag_left_panel_header, $this->_options_left_panel_header) . |
|
302
|
|
|
$this->_panel_header_title . |
|
303
|
|
|
Html::endTag($this->_tag_left_panel_header) . |
|
304
|
|
|
Html::begintag($this->_tag_rigth_panel_header, $this->_options_rigth_panel_header) . |
|
305
|
|
|
'{summary}' . ' ' . 'Records per pages: ' . '<b>' . $pageSize . '</b>' . |
|
306
|
|
|
Html::endTag($this->_tag_rigth_panel_header) . |
|
307
|
|
|
Html::endTag($this->_tag_container_panel_header); |
|
308
|
|
|
return $panel_header; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
private function renderTitlePanel() |
|
312
|
|
|
{ |
|
313
|
|
|
if (empty($this->_title_panel)) { |
|
314
|
|
|
$this->_title_panel = \yii::t('toolbar', 'Gridview ToolBar'); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
return $this->_title_panel; |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.