/** * Runs the widget. */ public function run() { /* @var $user CWebUser */ $user = Yii::app()->getUser(); echo CHtml::openTag('div', $this->htmlOptions); foreach ($this->alerts as $style => $alert) { if (isset($alert['visible']) && !$alert['visible']) { continue; } if ($user->hasFlash($style)) { $htmlOptions = TbHtml::popOption('htmlOptions', $alert, array()); $htmlOptions = TbHtml::defaultOption('closeText', $this->closeText, $htmlOptions); $htmlOptions = TbHtml::defaultOption('block', $this->block, $htmlOptions); $htmlOptions = TbHtml::defaultOption('fade', $this->fade, $htmlOptions); echo TbHtml::alert($style, $user->getFlash($style), $htmlOptions); } } echo '</div>'; $this->registerEvents("#{$this->htmlOptions['id']} > .alert", $this->events); }
/** * Renders a link button. * @param string $id the ID of the button * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements. * @param integer $row the row number (zero-based) * @param mixed $data the data object associated with the row */ protected function renderButton($id, $button, $row, $data) { if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row' => $row, 'data' => $data))) { return; } $url = TbHtml::popOption('url', $button, '#'); if (strcmp($url, '#') !== 0) { $url = $this->evaluateExpression($url, array('data' => $data, 'row' => $row)); } $imageUrl = TbHtml::popOption('imageUrl', $button, false); $label = TbHtml::popOption('label', $button, $id); $options = TbHtml::popOption('options', $button, array()); $options = TbHtml::defaultOption('title', $label, $options); $options = TbHtml::defaultOption('rel', 'tooltip', $options); if ($icon = TbHtml::popOption('icon', $button, false)) { /* todo: not sure if we require this anymore */ if (strpos($icon, 'icon') === false) { $icon = 'icon-' . implode(' icon-', explode(' ', $icon)); } echo CHtml::link('<i class="' . $icon . '"></i>', $url, $options); } else { if ($imageUrl && is_string($imageUrl)) { echo CHtml::link(CHtml::image($imageUrl, $label), $url, $options); } else { echo CHtml::link($label, $url, $options); } } }
/** * Normalizes the tab configuration. * @param array $tabs a reference to the tabs tab configuration. */ protected function normalizeTabs($tabs) { $controller = $this->getController(); if (isset($controller)) { foreach ($tabs as &$tabOptions) { $items = TbHtml::getOption('items', $tabOptions, array()); if (!empty($items)) { $tabOptions['items'] = $this->normalizeTabs($items); } else { if (isset($tabOptions['view'])) { $view = TbHtml::popOption('view', $tabOptions); if ($controller->getViewFile($view) !== false) { $tabOptions['content'] = $controller->renderPartial($view, $this->viewData, true); } } } } } return $tabs; }
/** * Renders the button */ public function renderButton() { if (!empty($this->buttonOptions) && is_array($this->buttonOptions)) { $this->buttonOptions = TbHtml::defaultOption('data-toggle', 'modal', $this->buttonOptions); if ($this->remote !== null) { $this->buttonOptions = TbHtml::defaultOption('data-remote', CHtml::normalizeUrl($this->remote), $this->buttonOptions); } $selector = '#' . $this->htmlOptions['id']; $label = TbHtml::popOption('label', $this->buttonOptions, 'button'); $attr = isset($this->buttonOptions['data-remote']) ? 'data-target' : 'href'; $this->buttonOptions = TbHtml::defaultOption($attr, $selector, $this->buttonOptions); echo TbHtml::button($label, $this->buttonOptions); } }
/** * Normalizes the tab configuration. * @param array $tabs the tab configuration * @param array $panes a reference to the panes array * @param integer $i the current index * @return array the items */ protected function normalizeTabs($tabs, &$panes, &$i = 0) { $id = TbHtml::getOption('id', $this->htmlOptions, $this->getId()); $items = array(); //Check if has an active item $hasActiveItem = false; foreach ($tabs as $tab) { if ($hasActiveItem = TbHtml::getOption('active', $tab, false) === true) { break; } } foreach ($tabs as $tab) { $item = $tab; if (isset($item['visible']) && $item['visible'] === false) { continue; } // if no tab should be active, activate first if (!$hasActiveItem && $i == 0) { $item['active'] = true; } // set the label to the title if any if (isset($item['title'])) { $item['label'] = TbHtml::defaultOption('label', TbHtml::popOption('title', $item), $item); } $item = TbHtml::defaultOption('itemOptions', array(), $item); if (isset($tab['items'])) { $item['linkOptions']['data-toggle'] = 'dropdown'; $item['items'] = $this->normalizeTabs($item['items'], $panes, $i); } else { $item['linkOptions']['data-toggle'] = 'tab'; $item = TbHtml::defaultOption('id', $id . '_tab_' . ($i + 1), $item); $item['url'] = '#' . $item['id']; // no content and we have a view? if (!isset($item['content']) && isset($item['view'])) { $view = TbHtml::popOption('view', $item, ''); $data = TbHtml::popOption('data', $item, array()); if (is_array($this->viewData)) { $data = TbHtml::mergeOptions($this->viewData, $data); } $process = TbHtml::popOption('processOutput', $item, false); $item['content'] = !empty($view) ? $this->getController()->renderPartial($view, $data, true, $process) : ''; } $content = TbHtml::popOption('content', $item, ''); $paneOptions = TbHtml::popOption('paneOptions', $item, array()); $paneOptions['id'] = TbHtml::popOption('id', $item); $classes = array('tab-pane fade'); if (isset($item['active']) && $item['active']) { $classes[] = 'active in'; } $paneOptions = TbHtml::addClassName(implode(' ', $classes), $paneOptions); $panes[] = CHtml::tag('div', $paneOptions, $content); $i++; // increment the tab-index } $items[] = $item; } return $items; }
/** * Processes the options for a input row. * @param CModel $model the data model. * @param string $attribute the attribute name. * @param array $htmlOptions the options. * @return array the processed options. */ protected function processRowOptions($model, $attribute, $options) { $errorOptions = TbHtml::popOption('errorOptions', $options, array()); $errorOptions['type'] = $this->helpType; $error = $this->error($model, $attribute, $errorOptions); // kind of a hack for ajax forms but this works for now. if (!empty($error) && strpos($error, 'display:none') === false) { $options['color'] = TbHtml::INPUT_COLOR_ERROR; } if (!$this->hideInlineErrors) { $options['error'] = $error; } $helpOptions = TbHtml::popOption('helpOptions', $options, array()); $helpOptions['type'] = $this->helpType; $options['helpOptions'] = $helpOptions; return $options; }
/** * Helper method to display different input types for the different complain bootstrap forms wrapped with their * labels, help and error messages. This method is a replacement of the old 'typeRow' methods from Yii-Bootstrap * extension. Example: * <pre> * $form->row(TbHtml::INPUT_TEXT, $model, 'attribute', array('style'=>'width:125px')); * $form->row(TbHtml::INPUT_DROPDOWN, $model, 'attribute', array('a'=>'A','b'=>'B'), array()); * </pre> * @param $type * @param $model * @param $attribute * @param $data * @param array $htmlOptions * @return string * @throws CException */ public function row($type, $model, $attribute, $data = array(), $htmlOptions = array()) { if (!in_array($type, TbHtml::$inputs)) { throw new CException(Yii::t('tb', 'Unrecognized input type')); } $labelOptions = TbHtml::popOption('labelOptions', $htmlOptions, array()); $errorOptions = TbHtml::popOption('errorOptions', $htmlOptions, array()); $containerOptions = TbHtml::popOption('containerOptions', $htmlOptions, array()); $labelOptions = TbHtml::defaultOption('formType', $this->type, $labelOptions); ob_start(); // make sure it holds the class control-label if ($this->type === TbHtml::FORM_HORIZONTAL) { echo CHtml::openTag('div', TbHtml::addClassName('control-group', $containerOptions)); } // form's inline do not render labels and radio|checkbox input types render label's differently if ($this->type !== TbHtml::FORM_INLINE && !preg_match('/radio|checkbox/i', $type) && TbHtml::popOption('label', $htmlOptions, true)) { echo TbHtml::activeLabel($model, $attribute, $labelOptions); } elseif (preg_match('/radio|checkbox/i', $type)) { $htmlOptions['labelOptions'] = $labelOptions; } if (TbHtml::popOption('block', $htmlOptions, false)) { $htmlOptions = TbHtml::addClassName('input-block-level', $htmlOptions); } $params = in_array($type, TbHtml::$dataInputs) ? array($model, $attribute, $data, $htmlOptions) : array($model, $attribute, $htmlOptions); $errorSpan = $this->error($model, $attribute, $errorOptions); echo $this->wrapControl(call_user_func_array('TbHtml::active' . ucfirst($type), $params), $errorSpan); /* since PHP 5.3 */ if ($this->type === TbHtml::FORM_VERTICAL && TbHtml::popOption('error', $htmlOptions, true)) { echo $errorSpan; } if ($this->type == TbHtml::FORM_HORIZONTAL) { echo '</div>'; } return ob_get_clean(); }
/** * Runs the widget. */ public function run() { $brand = $this->brandLabel !== false ? TbHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions) : ''; ob_start(); foreach ($this->items as $item) { if (is_string($item)) { echo $item; } else { $widgetClassName = TbHtml::popOption('class', $item); if ($widgetClassName !== null) { $this->controller->widget($widgetClassName, $item); } } } $items = ob_get_clean(); ob_start(); if ($this->collapse !== false) { $this->collapseOptions = TbHtml::addClassName('nav-collapse', $this->collapseOptions); // todo: fix collapse, currently it cannot be clicked when within a navbar ob_start(); /* @var TbCollapse $collapseWidget */ $collapseWidget = $this->controller->widget('bootstrap.widgets.TbCollapse', array('toggle' => false, 'content' => $items, 'htmlOptions' => $this->collapseOptions)); $collapseContent = ob_get_clean(); echo TbHtml::collapseIcon('#' . $collapseWidget->getId()); echo $brand . $collapseContent; } else { echo $brand . $items; } $containerContent = ob_get_clean(); $containerOptions = TbHtml::popOption('containerOptions', $this->htmlOptions, array()); $containerOptions = TbHtml::addClassName($this->fluid ? 'container-fluid' : 'container', $containerOptions); ob_start(); echo TbHtml::openTag('div', $containerOptions); echo $containerContent; echo '</div>'; $content = ob_get_clean(); echo TbHtml::navbar($content, $this->htmlOptions); }
/** * Runs the widget. */ public function run() { $brand = $this->brandLabel !== false ? TbHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions) : ''; ob_start(); foreach ($this->items as $item) { if (is_string($item)) { echo $item; } else { $widgetClassName = TbHtml::popOption('class', $item); if ($widgetClassName !== null) { $this->controller->widget($widgetClassName, $item); } } } $items = ob_get_clean(); ob_start(); echo CHtml::openTag('div', array('class' => $this->fluid ? 'container-fluid' : 'container')); if ($this->collapse !== false) { $collapseId = TbHtml::getNextId(); $this->collapseOptions = TbHtml::addClassName('nav-collapse', $this->collapseOptions); echo TbHtml::collapseIcon('#' . $collapseId) . PHP_EOL; echo $brand . PHP_EOL; $this->controller->beginWidget('bootstrap.widgets.TbCollapse', array('id' => $collapseId, 'toggle' => false, 'htmlOptions' => $this->collapseOptions)); echo $items; $this->controller->endWidget(); } else { echo $brand . PHP_EOL; echo $items . PHP_EOL; } echo '</div>'; $content = ob_get_clean(); echo TbHtml::navbar($content, $this->htmlOptions); }