1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*## TbButtonGroup class file. |
4
|
|
|
* |
5
|
|
|
* @author Christoffer Niska <[email protected]> |
6
|
|
|
* @copyright Copyright © Christoffer Niska 2011- |
7
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
8
|
|
|
* @since 0.9.10 |
9
|
|
|
* |
10
|
|
|
* @author Amr Bedair <[email protected]> |
11
|
|
|
* @since v4.0.0 - upgraded to bootstrap 3.1.1 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
Yii::import('booster.widgets.TbButton'); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
*## Bootstrap button group widget. |
18
|
|
|
* |
19
|
|
|
* @see <http://twitter.github.com/bootstrap/components.html#buttonGroups> |
20
|
|
|
* |
21
|
|
|
* @package booster.widgets.forms.buttons |
22
|
|
|
*/ |
23
|
|
|
class TbButtonGroup extends CWidget { |
24
|
|
|
|
25
|
|
|
// Toggle options. |
26
|
|
|
const TOGGLE_CHECKBOX = 'checkbox'; |
27
|
|
|
const TOGGLE_RADIO = 'radio'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string the button callback type. |
31
|
|
|
* @see BootButton::buttonType |
32
|
|
|
*/ |
33
|
|
|
public $buttonType = TbButton::BUTTON_BUTTON; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string the button type. |
37
|
|
|
* @see BootButton::type |
38
|
|
|
*/ |
39
|
|
|
public $context = TbButton::CTX_DEFAULT; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var boolean indicates whether to use justified button groups |
43
|
|
|
*/ |
44
|
|
|
public $justified = false; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string the button size. |
48
|
|
|
* @see BootButton::size |
49
|
|
|
*/ |
50
|
|
|
public $size; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var boolean indicates whether to encode the button labels. |
54
|
|
|
*/ |
55
|
|
|
public $encodeLabel = true; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array the HTML attributes for the widget container. |
59
|
|
|
*/ |
60
|
|
|
public $htmlOptions = array(); |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var array the button configuration. |
64
|
|
|
*/ |
65
|
|
|
public $buttons = array(); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var boolean indicates whether to enable button toggling. |
69
|
|
|
*/ |
70
|
|
|
public $toggle; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var boolean indicates whether the button group appears vertically stacked. Defaults to 'false'. |
74
|
|
|
*/ |
75
|
|
|
public $stacked = false; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var boolean indicates whether dropdowns should be dropups instead. Defaults to 'false'. |
79
|
|
|
*/ |
80
|
|
|
public $dropup = false; |
81
|
|
|
/** |
82
|
|
|
* @var boolean indicates whether button is disabled or not. Defaults to 'false'. |
83
|
|
|
*/ |
84
|
|
|
public $disabled = false; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
*### .init() |
88
|
|
|
* |
89
|
|
|
* Initializes the widget. |
90
|
|
|
*/ |
91
|
|
|
public function init() { |
92
|
|
|
|
93
|
|
|
$classes = array(); |
94
|
|
|
|
95
|
|
|
if ($this->stacked === true) { |
96
|
|
|
$classes[] = 'btn-group-vertical'; |
97
|
|
|
} else { |
98
|
|
|
$classes[] = 'btn-group'; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ($this->dropup === true) { |
102
|
|
|
$classes[] = 'dropup'; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if ($this->justified === true) { |
106
|
|
|
$classes[] = 'btn-group-justified'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if (!empty($classes)) { |
110
|
|
|
$classes = implode(' ', $classes); |
111
|
|
|
if (isset($this->htmlOptions['class'])) { |
112
|
|
|
$this->htmlOptions['class'] .= ' ' . $classes; |
113
|
|
|
} else { |
114
|
|
|
$this->htmlOptions['class'] = $classes; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$validToggles = array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO); |
119
|
|
|
|
120
|
|
|
if (isset($this->toggle) && in_array($this->toggle, $validToggles)) { |
121
|
|
|
$this->htmlOptions['data-toggle'] = 'buttons'; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
*### .run() |
127
|
|
|
* |
128
|
|
|
* Runs the widget. |
129
|
|
|
*/ |
130
|
|
|
public function run() { |
131
|
|
|
|
132
|
|
|
echo CHtml::openTag('div', $this->htmlOptions); |
133
|
|
|
|
134
|
|
|
foreach ($this->buttons as $button) { |
135
|
|
|
if (isset($button['visible']) && $button['visible'] === false) { |
136
|
|
|
continue; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$validToggles = array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO); |
140
|
|
|
if (isset($this->toggle) && in_array($this->toggle, $validToggles)) { |
141
|
|
|
$this->buttonType = $this->toggle; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$justifiedNotLink = $this->justified && $this->buttonType !== TbButton::BUTTON_LINK; |
145
|
|
|
if($justifiedNotLink) |
146
|
|
|
echo '<div class="btn-group">'; |
147
|
|
|
|
148
|
|
|
$this->controller->widget( |
149
|
|
|
'booster.widgets.TbButton', |
150
|
|
|
array( |
151
|
|
|
'buttonType' => isset($button['buttonType']) ? $button['buttonType'] : $this->buttonType, |
152
|
|
|
'context' => isset($button['context']) ? $button['context'] : $this->context, |
153
|
|
|
'size' => $this->size, // all buttons in a group cannot vary in size |
154
|
|
|
'icon' => isset($button['icon']) ? $button['icon'] : null, |
155
|
|
|
'label' => isset($button['label']) ? $button['label'] : null, |
156
|
|
|
'url' => isset($button['url']) ? $button['url'] : null, |
157
|
|
|
'active' => isset($button['active']) ? $button['active'] : false, |
158
|
|
|
'disabled' => isset($button['disabled']) ? $button['disabled'] : false, |
159
|
|
|
'items' => isset($button['items']) ? $button['items'] : array(), |
160
|
|
|
'ajaxOptions' => isset($button['ajaxOptions']) ? $button['ajaxOptions'] : array(), |
161
|
|
|
'htmlOptions' => isset($button['htmlOptions']) ? $button['htmlOptions'] : array(), |
162
|
|
|
'dropdownOptions' => isset($button['dropdownOptions']) ? $button['dropdownOptions'] : array(), |
163
|
|
|
'encodeLabel' => isset($button['encodeLabel']) ? $button['encodeLabel'] : $this->encodeLabel, |
164
|
|
|
'tooltip' => isset($button['tooltip']) ? $button['tooltip'] : false, |
165
|
|
|
'tooltipOptions' => isset($button['tooltipOptions']) ? $button['tooltipOptions'] : array(), |
166
|
|
|
) |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
if($justifiedNotLink) |
170
|
|
|
echo '</div>'; |
171
|
|
|
} |
172
|
|
|
echo '</div>'; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.