|
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 the button |
|
27
|
|
|
*/ |
|
28
|
|
|
public $_tag_icon_panel = 'i'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string the tag to use to render the button |
|
32
|
|
|
*/ |
|
33
|
|
|
public $_label_icon_panel = ''; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var array the tag to use to render the button |
|
37
|
|
|
*/ |
|
38
|
|
|
public $_options_icon_panel = ['class' => 'fas fa-th']; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string the button label |
|
42
|
|
|
*/ |
|
43
|
|
|
public $_title_panel = ''; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string the tag to use to render the button |
|
47
|
|
|
*/ |
|
48
|
|
|
public $_tag_container_panel_header = 'div'; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var array the tag to use to render the button |
|
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 the button |
|
57
|
|
|
*/ |
|
58
|
|
|
public $_tag_left_panel_header = 'div'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array the tag to use to render the button |
|
62
|
|
|
*/ |
|
63
|
|
|
public $_options_left_panel_header = ['class' => 'float-left']; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var string the tag to use to render the button |
|
67
|
|
|
*/ |
|
68
|
|
|
public $_tag_rigth_panel_header = 'div'; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var array the tag to use to render the button |
|
72
|
|
|
*/ |
|
73
|
|
|
public $_options_rigth_panel_header = ['class' => 'float-right ml-auto']; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var string the tag to use to render the button |
|
77
|
|
|
*/ |
|
78
|
|
|
public $_tag_container_panel_button = 'div'; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var array the tag to use to render the button |
|
82
|
|
|
*/ |
|
83
|
|
|
public $_options_container_panel_button = ['class' => 'peers bd p-15']; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var string the tag to use to render the button |
|
87
|
|
|
*/ |
|
88
|
|
|
public $_tag_left_panel_button = 'div'; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var array the tag to use to render the button |
|
92
|
|
|
*/ |
|
93
|
|
|
public $_options_left_panel_button = ['class' => 'float-left']; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var string the tag to use to render the button |
|
97
|
|
|
*/ |
|
98
|
|
|
public $_tag_rigth_panel_button = 'div'; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @var array the tag to use to render the button |
|
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 the tag to use to render the button |
|
112
|
|
|
*/ |
|
113
|
|
|
public $_panel_header_title = ''; |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Initializes the widget. |
|
117
|
|
|
* If you override this method, make sure you call the parent implementation first. |
|
118
|
|
|
*/ |
|
119
|
|
|
public function init() |
|
120
|
|
|
{ |
|
121
|
|
|
parent::init(); |
|
122
|
|
|
|
|
123
|
|
|
$iconpanel = $this->renderIcon(); |
|
124
|
|
|
$titlepanel = $this->renderTitlePanel(); |
|
125
|
|
|
$this->_panel_header_title = $iconpanel . ' ' . '<b>' . $titlepanel . '</b>'; |
|
126
|
|
|
|
|
127
|
|
|
echo $this->renderPanelHeader() . $this->renderPanelBar(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
private function renderIcon() |
|
131
|
|
|
{ |
|
132
|
|
|
return Html::tag($this->_tag_icon_panel, $this->_label_icon_panel, $this->_options_icon_panel); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
private function renderTitlePanel() |
|
136
|
|
|
{ |
|
137
|
|
|
if (empty($this->_title_panel)) { |
|
138
|
|
|
$this->_title_panel = \yii::t('toolbar', 'Gridview ToolBar'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $this->_title_panel; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
private function renderPanelHeader() |
|
145
|
|
|
{ |
|
146
|
|
|
$panel_header = Html::begintag($this->_tag_container_panel_header, $this->_options_container_panel_header) . |
|
147
|
|
|
Html::begintag($this->_tag_left_panel_header, $this->_options_left_panel_header) . |
|
148
|
|
|
$this->_panel_header_title . |
|
149
|
|
|
Html::endTag($this->_tag_left_panel_header) . |
|
150
|
|
|
Html::begintag($this->_tag_rigth_panel_header, $this->_options_rigth_panel_header) . |
|
151
|
|
|
'{summary}' . |
|
152
|
|
|
Html::endTag($this->_tag_rigth_panel_header) . |
|
153
|
|
|
Html::endTag($this->_tag_container_panel_header); |
|
154
|
|
|
return $panel_header; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
private function renderPanelBar() |
|
158
|
|
|
{ |
|
159
|
|
|
$panel_button = Html::begintag($this->_tag_container_panel_button, $this->_options_container_panel_button) . |
|
160
|
|
|
Html::begintag($this->_tag_left_panel_button, $this->_options_left_panel_button) . |
|
161
|
|
|
$this->renderButtonPages() . |
|
162
|
|
|
Html::endTag($this->_tag_left_panel_button) . |
|
163
|
|
|
Html::begintag($this->_tag_rigth_panel_button, $this->_options_rigth_panel_button) . |
|
164
|
|
|
$this->renderButtonCreate() . |
|
165
|
|
|
$this->renderButtonFilter() . |
|
166
|
|
|
$this->renderButtonReset() . |
|
167
|
|
|
Html::endTag($this->_tag_rigth_panel_button) . |
|
168
|
|
|
Html::endTag($this->_tag_container_panel_button); |
|
169
|
|
|
return $panel_button; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
private function renderButtonPages() |
|
173
|
|
|
{ |
|
174
|
|
|
$button_pages = ButtonDropdown::widget([ |
|
175
|
|
|
'buttonOptions' => ['class' => 'btn-sm btn-primary ai-c'], |
|
176
|
|
|
'label' => \yii::t('toolbar', 'Page Size'), |
|
177
|
|
|
'options' => ['class' => 'float-right'], |
|
178
|
|
|
'dropdown' => [ |
|
179
|
|
|
'items' => [ |
|
180
|
|
|
['label' => '1', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '1'])], |
|
181
|
|
|
['label' => '5', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '5'])], |
|
182
|
|
|
['label' => '10', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '10'])], |
|
183
|
|
|
['label' => '20', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '20'])], |
|
184
|
|
|
['label' => '25', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '25'])], |
|
185
|
|
|
['label' => '50', 'url' => Url::current(['index', 'page' => 1, 'pageSize' => '50'])], |
|
186
|
|
|
], |
|
187
|
|
|
], |
|
188
|
|
|
]); |
|
189
|
|
|
return $button_pages; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
private function renderButtonCreate() |
|
193
|
|
|
{ |
|
194
|
|
|
$button_create = Html::a( |
|
195
|
|
|
Html::tag('i', '', ['class' => 'fas fa-plus']), |
|
196
|
|
|
['create'], |
|
197
|
|
|
['class' => 'btn btn-lg bgc-green-500 c-white', 'title' => \yii::t('toolbar', 'Add')] |
|
198
|
|
|
); |
|
199
|
|
|
|
|
200
|
|
|
return $button_create; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
private function renderButtonFilter() |
|
204
|
|
|
{ |
|
205
|
|
|
$button_filter = Html::a( |
|
206
|
|
|
Html::tag('i', '', ['class' => 'fas fa-filter']), |
|
207
|
|
|
Url::current(), |
|
208
|
|
|
['id' => 'filter-checked-btn', 'class' => 'simple btn btn-lg bgc-blue-500 mL-2 c-white', 'title' => \yii::t('toolbar', 'Filter')] |
|
209
|
|
|
); |
|
210
|
|
|
|
|
211
|
|
|
return $button_filter; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
private function renderButtonReset() |
|
215
|
|
|
{ |
|
216
|
|
|
$button_reset = Html::a( |
|
217
|
|
|
Html::tag('i', '', ['class' => 'fas fa-sync-alt']), |
|
218
|
|
|
['index', [], []], |
|
219
|
|
|
['class' => 'btn btn-lg bgc-indigo-500 mL-2 c-white', 'title' => \yii::t('toolbar', 'Reset')] |
|
220
|
|
|
); |
|
221
|
|
|
|
|
222
|
|
|
return $button_reset; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|