/** * 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); }
/** * Widget's initialization method */ public function init() { $this->attachBehavior('TbWidget', new TbWidget()); $this->copyId(); $this->htmlOptions = TbHtml::defaultOption('placement', $this->placement, $this->htmlOptions); $this->initEvents(); }
/** * 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); } } }
/** * Initializes the widget. */ public function init() { $this->htmlOptions = TbHtml::defaultOption('id', $this->getId(), $this->htmlOptions); if (isset($this->size)) { $this->htmlOptions = TbHtml::defaultOption('size', $this->size, $this->htmlOptions); } }
/** * Initializes the widget. */ public function init() { $this->attachBehavior('TbWidget', new TbWidget()); $this->copyId(); if (isset($this->size)) { $this->htmlOptions = TbHtml::defaultOption('size', $this->size, $this->htmlOptions); } }
/** * Initializes the widget. */ public function init() { $this->htmlOptions['data-spy'] = 'affix'; if (isset($this->offset)) { if (is_string($this->offset)) { $this->offset = array('top', $this->offset); } if (is_array($this->offset) && count($this->offset) === 2) { list($position, $offset) = $this->offset; if (in_array($position, TbHtml::$navbarPositions)) { $this->options = TbHtml::defaultOption('data-offset-' . $position, $offset, $this->options); } } } echo CHtml::openTag($this->tagName, $this->htmlOptions); }
/** * Initializes the widget. */ public function init() { $this->htmlOptions = TbHtml::defaultOption('id', $this->getId(), $this->htmlOptions); $this->htmlOptions = TbHtml::addClassName('collapse', $this->htmlOptions); $this->htmlOptions['data-toggle'] = 'collapse'; if (isset($this->parent)) { $this->htmlOptions = TbHtml::defaultOption('data-parent', $this->parent, $this->htmlOptions); } if (isset($this->toggle) && $this->toggle) { $this->htmlOptions = TbHtml::addClassName('in', $this->htmlOptions); } $controller = $this->getController(); if (isset($controller) && $controller->getViewFile($this->content) !== false) { $this->content = $this->controller->renderPartial($this->content, $this->viewData, true); } echo CHtml::tag($this->tagName, $this->htmlOptions, $this->content); }
/** * Initializes the widget. */ public function init() { if ($this->brandLabel !== false) { if (!isset($this->brandLabel)) { $this->brandLabel = CHtml::encode(Yii::app()->name); } if (!isset($this->brandUrl)) { $this->brandUrl = Yii::app()->homeUrl; } } if (isset($this->color)) { $this->htmlOptions = TbHtml::defaultOption('color', $this->color, $this->htmlOptions); } if (isset($this->display) && $this->display !== TbHtml::NAVBAR_DISPLAY_NONE) { $this->htmlOptions = TbHtml::defaultOption('display', $this->display, $this->htmlOptions); } }
/** * Initializes the widget. */ public function init() { $this->attachBehavior('TbWidget', new TbWidget()); $this->copyId(); $this->htmlOptions['data-spy'] = 'affix'; if (isset($this->offset)) { if (is_string($this->offset)) { $this->offset = array('top', $this->offset); } if (is_array($this->offset) && count($this->offset) === 2) { list($position, $offset) = $this->offset; if (!empty($position)) { $this->options = TbHtml::defaultOption('data-offset-' . $position, $offset, $this->options); } } } echo TbHtml::openTag($this->tagName, $this->htmlOptions); }
/** * Initializes the widget. */ public function init() { $this->attachBehavior('TbWidget', new TbWidget()); $this->copyId(); $this->htmlOptions = TbHtml::addClassName('collapse', $this->htmlOptions); if (isset($this->parent)) { $this->htmlOptions = TbHtml::defaultOption('data-parent', $this->parent, $this->htmlOptions); } if (isset($this->toggle) && $this->toggle) { $this->htmlOptions = TbHtml::addClassName('in', $this->htmlOptions); } if (isset($this->view)) { $controller = $this->getController(); if (isset($controller) && $controller->getViewFile($this->view) !== false) { $this->content = $this->controller->renderPartial($this->view, $this->viewData, true); } } echo TbHtml::openTag($this->tagName, $this->htmlOptions); echo $this->content; }
/** * Initializes the widget. */ public function init() { if ($this->brandLabel !== false) { if (!isset($this->brandLabel)) { $this->brandLabel = CHtml::encode(Yii::app()->name); } if (!isset($this->brandUrl)) { $this->brandUrl = Yii::app()->homeUrl; } } // todo: somehow the style attribute in htmlOptions is ignored completely, fix. if (isset($this->style)) { $this->htmlOptions = TbHtml::defaultOption('style', $this->style, $this->htmlOptions); } if ($this->position !== false) { $this->htmlOptions = TbHtml::defaultOption('position', $this->position, $this->htmlOptions); } if ($this->static) { $this->htmlOptions = TbHtml::defaultOption('static', $this->static, $this->htmlOptions); } }
/** * Normalizes the menu items. * @param array $items the items to be normalized. * @param string $route the route of the current request. * @param boolean $active whether there is an active child menu item. * @return array the normalized menu items. */ protected function normalizeItems($items, $route, &$active) { foreach ($items as $i => $item) { // skip dividers if (is_string($item)) { continue; } if (isset($item['visible']) && !$item['visible']) { unset($items[$i]); continue; } $item = TbHtml::defaultOption('label', '', $item); if ($this->encodeLabel) { $items[$i]['label'] = CHtml::encode($item['label']); } if (!isset($item['url']) && !isset($item['items'])) { $items[$i]['header'] = true; } $hasActiveChild = false; if (isset($item['items']) && !empty($item['items'])) { $items[$i]['items'] = $this->normalizeItems($item['items'], $route, $hasActiveChild); if (empty($items[$i]['items']) && $this->hideEmptyItems) { unset($items[$i]['items']); if (!isset($item['url'])) { unset($items[$i]); continue; } } } if (!isset($item['active'])) { if ($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item, $route)) { $active = $items[$i]['active'] = true; } else { $items[$i]['active'] = false; } } else { if ($item['active']) { $active = true; } } } return array_values($items); }
/** * 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; }
/** * Initializes the widget. */ public function init() { $this->htmlOptions = TbHtml::defaultOption('divider', $this->divider, $this->htmlOptions); }
/** * 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(); }
/** * Renders field */ public function renderField() { list($name, $id) = $this->resolveNameID(); $this->htmlOptions = TbHtml::defaultOption('id', $id, $this->htmlOptions); $this->htmlOptions = TbHtml::defaultOption('name', $name, $this->htmlOptions); // by using TbHtml we support all bootstrap options if ($this->hasModel()) { echo TbHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions); } else { echo TbHtml::textField($name, $this->value, $this->htmlOptions); } }
/** * Displays a summary of validation errors for one or several models. * @param mixed $models the models whose input errors are to be displayed. * @param string $header a piece of HTML code that appears in front of the errors * @param string $footer a piece of HTML code that appears at the end of the errors * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag. * @return string the error summary. Empty if no errors are found. */ public function errorSummary($models, $header = null, $footer = null, $htmlOptions = array()) { if (!$this->enableAjaxValidation && !$this->enableClientValidation) { return TbHtml::errorSummary($models, $header, $footer, $htmlOptions); } $htmlOptions = TbHtml::defaultOption('id', $this->id . '_es_', $htmlOptions); $html = TbHtml::errorSummary($models, $header, $footer, $htmlOptions); if ($html === '') { if ($header === null) { $header = '<p>' . Yii::t('yii', 'Please fix the following input errors:') . '</p>'; } $htmlOptions = TbHtml::addClassName(TbHtml::$errorSummaryCss, $htmlOptions); $htmlOptions = TbHtml::addStyles('display:none', $htmlOptions); $html = CHtml::tag('div', $htmlOptions, $header . '<ul><li>dummy</li></ul>' . $footer); } $this->summaryID = $htmlOptions['id']; return $html; }