HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbPanel.php
Go to the documentation of this file.
1 <?php
10 Yii::import('booster.widgets.TbWidget');
11 
19 class TbPanel extends TbWidget {
20 
26  public $title = '';
27 
33  public $headerIcon;
34 
40  public $content = '';
41 
42  public $padContent = true;
43 
48  public $htmlOptions = array();
49 
54  public $headerHtmlOptions = array();
55 
60  public $contentHtmlOptions = array();
61 
82  public $headerButtons = array();
83 
89  public function init() {
90 
91  $this->addCssClass($this->htmlOptions, 'panel');
92 
93  if($this->isValidContext())
94  self::addCssClass($this->htmlOptions, 'panel-'.$this->getContextClass());
95 
96  if ($this->padContent)
97  self::addCssClass($this->contentHtmlOptions, 'panel-body');
98 
99  if (!isset($this->contentHtmlOptions['id'])) {
100  $this->contentHtmlOptions['id'] = $this->getId();
101  }
102 
103  if (isset($this->headerHtmlOptions['class'])) {
104  $this->headerHtmlOptions['class'] = 'panel-heading ' . $this->headerHtmlOptions['class'];
105  } else {
106  $this->headerHtmlOptions['class'] = 'panel-heading';
107  }
108 
109  echo CHtml::openTag('div', $this->htmlOptions);
110 
111  // $this->registerClientScript();
112  $this->renderHeader();
113  $this->renderContentBegin();
114  }
115 
121  public function run() {
122 
123  $this->renderContentEnd();
124  echo CHtml::closeTag('div') . "\n";
125  }
126 
132  public function renderHeader() {
133 
134  if ($this->title !== false) {
135  echo CHtml::openTag('div', $this->headerHtmlOptions);
136  if ($this->title) {
137  $this->title = '<h3 class="panel-title" style="display: inline;">' . $this->title . '</h3>';
138 
139  if ($this->headerIcon) {
140  if (strpos($this->headerIcon, 'icon') === false && strpos($this->headerIcon, 'fa') === false)
141  $this->title = '<span class="glyphicon glyphicon-' . $this->headerIcon . '"></span> ' . $this->title;
142  else
143  $this->title = '<i class="' . $this->headerIcon . '"></i> ' . $this->title;
144  }
145 
146  $this->renderButtons();
147  echo $this->title;
148  }
149  echo '<div class="clearfix"></div>';
150  echo CHtml::closeTag('div');
151  }
152  }
153 
159  public function renderButtons() {
160 
161  if (empty($this->headerButtons))
162  return;
163 
164  echo '<div class="pull-right">';
165 
166  if (!empty($this->headerButtons) && is_array($this->headerButtons)) {
167 
168  foreach ($this->headerButtons as $options) {
169 
170  $class = $options['class'];
171  unset($options['class']);
172 
173  if (strpos($class, 'TbButton') === false)
174  throw new CException('Button must be either TbButton, or TbButtonGroup');
175 
176  if (!isset($options['htmlOptions']))
177  $options['htmlOptions'] = array();
178 
179  self::addCssClass($options['htmlOptions'], 'pull-right');
180 
181  $this->controller->widget($class, $options);
182  }
183  }
184  echo '</div>';
185  }
186 
187  /*
188  *### .renderContentBegin()
189  *
190  * Renders the opening of the content element and the optional content
191  */
192  public function renderContentBegin() {
193 
194  echo CHtml::openTag('div', $this->contentHtmlOptions);
195  if (!empty($this->content)) {
196  echo $this->content;
197  }
198  }
199 
200  /*
201  *### .renderContentEnd()
202  *
203  * Closes the content element
204  */
205  public function renderContentEnd() {
206 
207  echo CHtml::closeTag('div');
208  }
209 
215  public function registerClientScript() {
216 
217  // Booster::getBooster()->registerAssetCss('bootstrap-panel.css');
218  }
219 }