HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbModalManager.php
Go to the documentation of this file.
1 <?php
18 class TbModalManager 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 
48  public function init()
49  {
50  if (!isset($this->htmlOptions['id'])) {
51  $this->htmlOptions['id'] = $this->getId();
52  }
53 
54  if ($this->autoOpen === false && !isset($this->options['show'])) {
55  $this->options['show'] = false;
56  }
57 
58  $classes = array('modal');
59 
60  if ($this->fade === true) {
61  $classes[] = 'fade';
62  }
63 
64  if (!empty($classes)) {
65  $classes = implode(' ', $classes);
66  if (isset($this->htmlOptions['class'])) {
67  $this->htmlOptions['class'] .= ' ' . $classes;
68  } else {
69  $this->htmlOptions['class'] = $classes;
70  }
71  }
72  echo CHtml::openTag('div', $this->htmlOptions);
73  }
74 
78  public function run()
79  {
80  echo CHtml::closeTag('div');
81  $this->registerClientScript($this->htmlOptions['id']);
82  }
83 
89  public function registerClientScript($id)
90  {
91  $booster = Booster::getBooster();
92  $booster->registerAssetJs('bootstrap-modalmanager.js', CClientScript::POS_HEAD);
93  $booster->registerAssetCss('bootstrap-modalmanager.css');
94 
95  $options = !empty($this->format) ? CJavaScript::encode(array('format' => $this->format)) : '';
96 
97  ob_start();
98  echo "jQuery('#{$id}').modalmanager({$options})";
99  foreach ($this->events as $event => $handler) {
100  echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
101  }
102 
103  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
104 
105  foreach ($this->events as $name => $handler) {
106  $handler = CJavaScript::encode($handler);
107  Yii::app()->getClientScript()->registerScript(
108  __CLASS__ . '#' . $id . '_' . $name,
109  "jQuery('#{$id}').on('{$name}', {$handler});"
110  );
111  }
112  }
113 }