HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbSwitch.php
Go to the documentation of this file.
1 <?php
14 class TbSwitch extends CInputWidget {
15 
20  public $form;
21 
36  public $events = array();
37 
43  public $options = array();
44 
48  public function run() {
49 
50  list($name, $id) = $this->resolveNameID();
51 
52  if ($this->hasModel()) {
53  if ($this->form) {
54  echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions);
55  } else {
56  echo CHtml::activeCheckBox($this->model, $this->attribute, $this->htmlOptions);
57  }
58  } else {
59  echo CHtml::checkBox($name, $this->value, $this->htmlOptions);
60  }
61 
62  $this->registerClientScript($id);
63  }
64 
70  protected function registerClientScript($id) {
71 
72  $booster = Booster::getBooster();
73  $booster->registerPackage('switch');
74 
75  $config = CJavaScript::encode($this->options);
76 
77  ob_start();
78  echo "$('#$id').bootstrapSwitch({$config})";
79  foreach ($this->events as $event => $handler) {
80  $event = $event.'.bootstrapSwitch';
81  if (!$handler instanceof CJavaScriptExpression && strpos($handler, 'js:') === 0)
82  $handler = new CJavaScriptExpression($handler);
83  echo ".on('{$event}', " . $handler . ")";
84  }
85 
86  Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
87  }
88 
89 }