Пример #1
0
 /**
  * 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 = BsArray::popValue('url', $button, '#');
     if ($url !== '#') {
         $url = $this->evaluateExpression($url, array('data' => $data, 'row' => $row));
     }
     $imageUrl = BsArray::popValue('imageUrl', $button, false);
     $label = BsArray::popValue('label', $button, $id);
     $options = BsArray::popValue('options', $button, array());
     BsArray::defaultValue('data-title', $label, $options);
     BsArray::defaultValue('title', $label, $options);
     BsArray::defaultValue('data-toggle', 'tooltip', $options);
     if ($icon = BsArray::popValue('icon', $button, false)) {
         echo CHtml::link(BsHtml::icon($icon), $url, $options);
     } else {
         if ($imageUrl && is_string($imageUrl)) {
             echo CHtml::link(CHtml::image($imageUrl, $label), $url, $options);
         } else {
             echo CHtml::link($label, $url, $options);
         }
     }
 }
Пример #2
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     $this->attachBehavior('BsWidget', new BsWidget());
     $this->copyId();
     if (isset($this->size)) {
         BsArray::defaultValue('size', $this->size, $this->htmlOptions);
     }
 }
Пример #3
0
 /**
  * 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)) {
         BsArray::defaultValue('color', $this->color, $this->htmlOptions);
     }
     if (isset($this->position) && $this->position !== BsHtml::NAVBAR_POSITION) {
         BsArray::defaultValue('position', $this->position, $this->htmlOptions);
     }
 }
Пример #4
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     Yii::app()->clientScript->registerCoreScript('jquery');
     $this->attachBehavior('BsWidget', new BsWidget());
     $this->copyId();
     BsHtml::addCssClass('collapse', $this->htmlOptions);
     if (isset($this->parent)) {
         BsArray::defaultValue('data-parent', $this->parent, $this->htmlOptions);
     }
     if (isset($this->toggle) && $this->toggle) {
         BsHtml::addCssClass('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 BsHtml::openTag($this->tagName, $this->htmlOptions);
     echo $this->content;
 }
Пример #5
0
 /**
  * Initializes this form.
  */
 public function init()
 {
     BsArray::defaultValue('layout', $this->layout, $this->activeForm);
 }
Пример #6
0
 /**
  * Generates an image carousel.
  * @param array $items the item configurations.
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated carousel.
  */
 public static function carousel(array $items, $htmlOptions = array())
 {
     if (!empty($items)) {
         $id = BsArray::getValue('id', $htmlOptions, parent::ID_PREFIX . parent::$count++);
         BsArray::defaultValue('id', $id, $htmlOptions);
         $selector = '#' . $id;
         self::addCssClass('carousel', $htmlOptions);
         if (BsArray::popValue('slide', $htmlOptions, true)) {
             self::addCssClass('slide', $htmlOptions);
         }
         $interval = BsArray::popValue('data-interval', $htmlOptions);
         if ($interval) {
             $htmlOptions['data-interval'] = $interval;
         }
         $pause = BsArray::popValue('data-pause', $htmlOptions);
         if ($pause) {
             $htmlOptions['data-pause'] = $pause;
         }
         $indicatorOptions = BsArray::popValue('indicatorOptions', $htmlOptions, array());
         $innerOptions = BsArray::popValue('innerOptions', $htmlOptions, array());
         self::addCssClass('carousel-inner', $innerOptions);
         $prevOptions = BsArray::popValue('prevOptions', $htmlOptions, array());
         $prevLabel = BsArray::popValue('label', $prevOptions, '‹');
         $nextOptions = BsArray::popValue('nextOptions', $htmlOptions, array());
         $nextLabel = BsArray::popValue('label', $nextOptions, '›');
         $hidePrevAndNext = BsArray::popValue('hidePrevAndNext', $htmlOptions, false);
         $output = self::openTag('div', $htmlOptions);
         $output .= self::carouselIndicators($selector, count($items), $indicatorOptions);
         $output .= self::openTag('div', $innerOptions);
         foreach ($items as $i => $itemOptions) {
             if (isset($itemOptions['visible']) && $itemOptions['visible'] === false) {
                 continue;
             }
             if ($i === 0) {
                 // first item should be active
                 self::addCssClass('active', $itemOptions);
             }
             $content = BsArray::popValue('content', $itemOptions, '');
             $image = BsArray::popValue('image', $itemOptions, '');
             $imageOptions = BsArray::popValue('imageOptions', $itemOptions, array());
             $imageAlt = BsArray::popValue('alt', $imageOptions, '');
             if (!empty($image)) {
                 $content = parent::image($image, $imageAlt, $imageOptions);
             }
             $label = BsArray::popValue('label', $itemOptions);
             $caption = BsArray::popValue('caption', $itemOptions);
             $output .= self::carouselItem($content, $label, $caption, $itemOptions);
         }
         $output .= '</div>';
         if (!$hidePrevAndNext) {
             $output .= self::carouselPrevLink($prevLabel, $selector, $prevOptions);
             $output .= self::carouselNextLink($nextLabel, $selector, $nextOptions);
         }
         $output .= '</div>';
         return $output;
     }
     return '';
 }
Пример #7
0
 /**
  * Renders the button
  */
 public function renderButton()
 {
     if (!empty($this->buttonOptions) && is_array($this->buttonOptions)) {
         BsArray::defaultValue('data-toggle', 'modal', $this->buttonOptions);
         if ($this->remote !== null) {
             $this->buttonOptions['data-remote'] = CHtml::normalizeUrl($this->remote);
         }
         $selector = '#' . $this->htmlOptions['id'];
         $label = BsArray::popValue('label', $this->buttonOptions, 'button');
         $attr = isset($this->buttonOptions['data-remote']) ? 'data-target' : 'href';
         BsArray::defaultValue($attr, $selector, $this->buttonOptions);
         echo BsHtml::button($label, $this->buttonOptions);
     }
 }
Пример #8
0
 /**
  * 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;
         }
         BsArray::defaultValue('label', '', $item);
         if ($this->encodeLabel) {
             $items[$i]['label'] = CHtml::encode($item['label']);
         }
         $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);
 }
Пример #9
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 BsHtml::errorSummary($models, $header, $footer, $htmlOptions);
     }
     BsArray::defaultValue('id', $this->id . '_es_', $htmlOptions);
     $html = BsHtml::errorSummary($models, $header, $footer, $htmlOptions);
     if ($html === '') {
         if ($header === null) {
             $header = '<p>' . Yii::t('yii', 'Please fix the following input errors:') . '</p>';
         }
         BsHtml::addCssClass(BsHtml::$errorSummaryCss, $htmlOptions);
         BsHtml::addCssStyle('display:none', $htmlOptions);
         $html = CHtml::tag('div', $htmlOptions, $header . '<ul><li>dummy</li></ul>' . $footer);
     }
     $this->summaryID = $htmlOptions['id'];
     foreach (is_array($models) ? $models : array($models) as $model) {
         foreach ($model->getSafeAttributeNames() as $attribute) {
             $this->_summaryAttributes[] = CHtml::activeId($model, $attribute);
         }
     }
     return $html;
 }