HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbButtonGroup.php
Go to the documentation of this file.
1 <?php
14 Yii::import('booster.widgets.TbButton');
15 
23 class TbButtonGroup extends CWidget {
24 
25  // Toggle options.
26  const TOGGLE_CHECKBOX = 'checkbox';
27  const TOGGLE_RADIO = 'radio';
28 
34 
40 
44  public $justified = false;
45 
50  public $size;
51 
55  public $encodeLabel = true;
56 
60  public $htmlOptions = array();
61 
65  public $buttons = array();
66 
70  public $toggle;
71 
75  public $stacked = false;
76 
80  public $dropup = false;
84  public $disabled = false;
85 
91  public function init() {
92 
93  $classes = [];
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 
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 }