HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbCollapse.php
Go to the documentation of this file.
1 <?php
19 class TbCollapse extends CWidget {
20 
21  const CONTAINER_PREFIX = 'yii_bootstrap_collapse_';
22 
26  public $tagName = 'div';
27 
31  public $parent = false;
32 
36  public $toggle = true;
37 
41  public $options = array();
42 
46  public $events = array();
47 
51  public $htmlOptions = array();
52 
53  private static $_containerId = 0;
54 
60  public function init() {
61 
62  if (!isset($this->htmlOptions['id'])) {
63  $this->htmlOptions['id'] = $this->getId();
64  }
65 
66  if (isset($this->parent) && !isset($this->options['parent'])) {
67  $this->options['parent'] = $this->parent;
68  }
69 
70  if (isset($this->toggle) && !isset($this->options['toggle'])) {
71  $this->options['toggle'] = $this->toggle;
72  }
73 
74  // NOTE: we depend on the htmlOptions being initialized to empty array already.
75  if (empty($this->htmlOptions['class'])) {
76  $this->htmlOptions['class'] = 'collapse';
77  } else {
78  $this->htmlOptions['class'] .= ' collapse';
79  }
80  echo CHtml::openTag($this->tagName, $this->htmlOptions);
81  }
82 
88  public function run() {
89 
90  $id = $this->htmlOptions['id'];
91 
92  echo CHtml::closeTag($this->tagName);
93 
95  $cs = Yii::app()->getClientScript();
96  $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
97  $cs->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').collapse({$options});");
98 
99  foreach ($this->events as $name => $handler) {
100  $handler = CJavaScript::encode($handler);
101  $cs->registerScript(__CLASS__ . '#' . $id . '_' . $name, "jQuery('#{$id}').on('{$name}', {$handler});");
102  }
103  }
104 
112  public static function getNextContainerId() {
113 
114  return self::CONTAINER_PREFIX . self::$_containerId++;
115  }
116 }