예제 #1
0
 /**
  * Initializes the widget
  */
 public function init()
 {
     parent::init();
     if (isset($this->itemsCssClass)) {
         $this->htmlOptions = TbHtml::addClassName($this->itemsCssClass, $this->htmlOptions);
     }
 }
예제 #2
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     $classes = array('table');
     if (isset($this->type) && !empty($this->type)) {
         if (is_string($this->type)) {
             $this->type = explode(' ', $this->type);
         }
         foreach ($this->type as $type) {
             $classes[] = 'table-' . $type;
         }
     }
     $this->htmlOptions = TbHtml::addClassName(implode(' ', $classes), $this->htmlOptions);
 }
예제 #3
0
파일: TbNav.php 프로젝트: yii-twbs/yiistrap
 /**
  * Initializes the widget.
  */
 public function init()
 {
     $this->htmlOptions = TbHtml::defaultOption('id', $this->getId(), $this->htmlOptions);
     $route = $this->controller->getRoute();
     if ($this->stacked) {
         $this->htmlOptions = TbHtml::addClassName('nav-stacked', $this->htmlOptions);
     }
     if (isset($this->scrollspy)) {
         if (is_string($this->scrollspy)) {
             $this->scrollspy = array('target' => $this->scrollspy);
         }
         $this->widget('bootstrap.widgets.TbScrollspy', $this->scrollspy);
     }
     $this->items = $this->normalizeItems($this->items, $route, $hasActiveChild);
 }
예제 #4
0
 /**
  * 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);
 }
예제 #5
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     $classes = array('table');
     if (isset($this->type) && !empty($this->type)) {
         if (is_string($this->type)) {
             $this->type = explode(' ', $this->type);
         }
         $validTypes = array(TbHtml::GRID_TYPE_BORDERED, TbHtml::GRID_TYPE_CONDENSED, TbHtml::GRID_TYPE_STRIPED, TbHtml::GRID_TYPE_HOVER);
         foreach ($this->type as $type) {
             if (in_array($type, $validTypes)) {
                 $classes[] = 'table-' . $type;
             }
         }
     }
     $this->htmlOptions = TbHtml::addClassName(implode(' ', $classes), $this->htmlOptions);
 }
예제 #6
0
 /**
  * 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;
 }
예제 #7
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     // Don't let Yii include its default stylesheet
     if ($this->cssFile === null) {
         $this->cssFile = false;
     }
     parent::init();
     if (is_string($this->type)) {
         $types = explode(' ', $this->type);
     } else {
         $types = $this->type;
     }
     $validTypes = array(TbHtml::DETAIL_TYPE_BORDERED, TbHtml::DETAIL_TYPE_CONDENSED, TbHtml::DETAIL_TYPE_HOVER, TbHtml::DETAIL_TYPE_STRIPED);
     // Set class names
     foreach ($types as $type) {
         if (in_array($type, $validTypes)) {
             $this->htmlOptions = TbHtml::addClassName('table-' . $type, $this->htmlOptions);
         }
     }
     $this->htmlOptions = TbHtml::addClassName('table', $this->htmlOptions);
 }
예제 #8
0
 /**
  * Widget's initialization method
  */
 public function init()
 {
     $this->attachBehavior('TbWidget', new TbWidget());
     $this->htmlOptions = TbHtml::defaultOption('id', $this->getId(), $this->htmlOptions);
     $this->htmlOptions = TbHtml::defaultOption('role', 'dialog', $this->htmlOptions);
     $this->htmlOptions = TbHtml::defaultOption('tabindex', '-1', $this->htmlOptions);
     $this->htmlOptions = TbHtml::addClassName('modal hide', $this->htmlOptions);
     if ($this->fade) {
         $this->htmlOptions = TbHtml::addClassName('fade', $this->htmlOptions);
     }
     if (is_array($this->footer)) {
         $this->footer = implode(' ', $this->footer);
     }
     $this->initOptions();
     $this->initEvents();
 }
예제 #9
0
 /**
  * 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;
 }
예제 #10
0
 /**
  * Displays a summary of validation errors for one or several models.
  * @param mixed $model the models whose input errors are to be displayed. This can be either
  * a single model or an array of models.
  * @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.
  * A special option named 'firstError' is recognized, which when set true, will
  * make the error summary to show only the first error message of each attribute.
  * If this is not set or is false, all error messages will be displayed.
  * This option has been available since version 1.1.3.
  * @return string the error summary. Empty if no errors are found.
  * @see CModel::getErrors
  * @see errorSummaryCss
  */
 public static function errorSummary($model, $header = null, $footer = null, $htmlOptions = array())
 {
     $htmlOptions = TbHtml::addClassName('alert alert-block alert-error', $htmlOptions);
     return CHtml::errorSummary($model, $header, $footer, $htmlOptions);
 }
예제 #11
0
 /**
  * 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;
 }
예제 #12
0
 /**
  * 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();
 }
예제 #13
0
 /**
  * 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);
 }
예제 #14
0
 /**
  * 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);
 }
예제 #15
0
 /**
  * Widget's initialization method
  */
 public function init()
 {
     $this->htmlOptions = TbHtml::defaultOption('id', $this->getId(), $this->htmlOptions);
     $this->htmlOptions = TbHtml::defaultOption('role', 'dialog', $this->htmlOptions);
     $this->htmlOptions = TbHtml::defaultOption('tabindex', '-1', $this->htmlOptions);
     $this->htmlOptions = TbHtml::addClassName('modal hide', $this->htmlOptions);
     if ($this->fade) {
         $this->htmlOptions = TbHtml::addClassName('fade', $this->htmlOptions);
     }
     $this->initOptions();
     $this->initEvents();
 }