HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbModal.php
Go to the documentation of this file.
1 <?php
18 class TbModal extends CWidget {
19 
23  public $autoOpen = false;
24 
28  public $fade = true;
29 
33  public $options = array();
34 
38  public $events = array();
39 
43  public $htmlOptions = array();
44 
50  public function init() {
51 
52  if (!isset($this->htmlOptions['id'])) {
53  $this->htmlOptions['id'] = $this->getId();
54  }
55 
56  if ($this->autoOpen === false && !isset($this->options['show'])) {
57  $this->options['show'] = false;
58  }
59 
60  $classes = array('modal');
61 
62  if ($this->fade === true) {
63  $classes[] = 'fade';
64  }
65 
66  if (!empty($classes)) {
67  $classes = implode(' ', $classes);
68  if (isset($this->htmlOptions['class'])) {
69  $this->htmlOptions['class'] .= ' ' . $classes;
70  } else {
71  $this->htmlOptions['class'] = $classes;
72  }
73  }
74  echo CHtml::openTag('div', $this->htmlOptions);
75  echo '<div class="modal-dialog"><div class="modal-content">';
76  }
77 
83  public function run() {
84 
85  $id = $this->htmlOptions['id'];
86 
87  echo '</div></div></div>';
88 
90  $cs = Yii::app()->getClientScript();
91 
92  $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
93  $cs->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').modal({$options});");
94 
95  foreach ($this->events as $name => $handler) {
96  $handler = CJavaScript::encode($handler);
97  $cs->registerScript(__CLASS__ . '#' . $id . '_' . $name, "jQuery('#{$id}').on('{$name}', {$handler});");
98  }
99  }
100 }