Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 2
0
 public function fileField($model, $attribute, $htmlOptions = array())
 {
     $controlOptions = BsArray::popValue('controlOptions', $htmlOptions, array());
     $labelOptions = BsArray::popValue('labelOptions', $htmlOptions, array());
     $layout = $this->layout;
     $output = '';
     $output .= CHtml::activeFileField($model, $attribute, $htmlOptions);
     $attr = $model->{$attribute};
     if (!empty($attr)) {
         //Special logic for ContentTypes
         $tmpModel = $model;
         if ($model instanceof ContentType) {
             $tmpModel = $model->Content;
         }
         $output .= '<p class="file">' . CHtml::link($model->{$attribute}, array('/site/getFile', 'id' => $tmpModel->id, 'field' => $attribute, 'modelName' => get_class($tmpModel))) . '</p>';
         $output .= '<div class="checkbox">' . CHtml::checkBox($attribute . '_delete');
         $output .= CHtml::label('Delete?', $attribute . '_delete') . '</div>';
     }
     $htmlOptions['input'] = $output;
     $htmlOptions['labelOptions'] = BsHtml::setLabelOptionsByLayout($layout, $labelOptions);
     if (!empty($layout)) {
         if ($layout === BsHtml::FORM_LAYOUT_HORIZONTAL) {
             $controlClass = BsArray::popValue('class', $controlOptions, BsHtml::$formLayoutHorizontalControlClass);
             BsHtml::addCssClass($controlClass, $htmlOptions['controlOptions']);
         }
     }
     return BsHTML::activeTextFieldControlGroup($model, $attribute, $htmlOptions);
 }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 5
0
 /**
  * Initializes this form.
  */
 public function init()
 {
     BsArray::defaultValue('layout', $this->layout, $this->activeForm);
 }
Exemplo n.º 6
0
 /**
  * Generates a carousel item.
  * @param string $content the content.
  * @param string $label the item label text.
  * @param string $caption the item caption text.
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated item.
  */
 public static function carouselItem($content, $label, $caption, $htmlOptions = array())
 {
     self::addCssClass('item', $htmlOptions);
     $overlayOptions = BsArray::popValue('overlayOptions', $htmlOptions, array());
     self::addCssClass('carousel-caption', $overlayOptions);
     $labelOptions = BsArray::popValue('labelOptions', $htmlOptions, array());
     $captionOptions = BsArray::popValue('captionOptions', $htmlOptions, array());
     $url = BsArray::popValue('url', $htmlOptions, false);
     if ($url !== false) {
         $content = self::link($content, $url);
     }
     $output = self::openTag('div', $htmlOptions);
     $output .= $content;
     if (isset($label) || isset($caption)) {
         $output .= self::openTag('div', $overlayOptions);
         if ($label) {
             $output .= self::tag('h4', $labelOptions, $label);
         }
         if ($caption) {
             $output .= self::tag('p', $captionOptions, $caption);
         }
         $output .= '</div>';
     }
     $output .= '</div>';
     return $output;
 }
Exemplo n.º 7
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     $brand = $this->brandLabel !== false ? BsHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions) : '';
     ob_start();
     foreach ($this->items as $item) {
         if (is_string($item)) {
             echo $item;
         } else {
             $widgetClassName = BsArray::popValue('class', $item);
             if ($widgetClassName !== null) {
                 $this->controller->widget($widgetClassName, $item);
             }
         }
     }
     $items = ob_get_clean();
     ob_start();
     if ($this->collapse !== false) {
         BsHtml::addCssClass('collapse navbar-collapse', $this->collapseOptions);
         ob_start();
         /* @var BsCollapse $collapseWidget */
         $collapseWidget = $this->controller->widget('bootstrap.widgets.BsCollapse', array('toggle' => false, 'content' => $items, 'htmlOptions' => $this->collapseOptions));
         $collapseContent = ob_get_clean();
         $collapseLink = BsHtml::navbarCollapseLink('#' . $collapseWidget->getId());
         echo BsHtml::tag('div', array('class' => 'navbar-header'), $collapseLink . $brand) . $collapseContent;
     } else {
         echo BsHtml::tag('div', array('class' => 'navbar-header'), $brand) . $items;
     }
     $containerContent = ob_get_clean();
     if (isset($this->position) && ($this->position === BsHtml::NAVBAR_POSITION_FIXED_TOP || $this->position === BsHtml::NAVBAR_POSITION_STATIC_TOP)) {
         $fluid = BsArray::popValue('containerOptions', $this->htmlOptions, false);
         $containerOptions = BsArray::popValue('containerOptions', $this->htmlOptions, array());
         $containerClass = 'container';
         if ($fluid) {
             $containerOptions = BsArray::removeValue('fluid', $this->htmlOptions, array());
             $containerClass = 'container-fluid';
         }
         BsHtml::addCssClass($containerClass, $containerOptions);
         $content = BsHtml::tag('div', $containerOptions, $containerContent);
         echo BsHtml::navbar($content, $this->htmlOptions);
         return;
     }
     echo BsHtml::navbar($containerContent, $this->htmlOptions);
 }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
 /**
  * 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 = BsArray::popValue('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'] = BsHtml::INPUT_COLOR_ERROR;
     }
     if (!$this->hideInlineErrors) {
         $options['error'] = $error;
     }
     $helpOptions = BsArray::popValue('helpOptions', $options, array());
     $helpOptions['type'] = $this->helpType;
     $labelOptions = BsArray::popValue('labelOptions', $options, array());
     $options['helpOptions'] = $helpOptions;
     $options['labelOptions'] = BsHtml::setLabelOptionsByLayout($this->layout, $labelOptions);
     $options['formLayout'] = $this->layout;
     return $options;
 }