示例#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
 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);
 }
示例#3
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     $this->attachBehavior('BsWidget', new BsWidget());
     $this->copyId();
     $route = $this->controller->getRoute();
     if ($this->stacked) {
         BsHtml::addCssClass('nav-stacked', $this->htmlOptions);
     }
     $pull = BsArray::popValue('pull', $this->htmlOptions);
     if (!empty($pull)) {
         if ($pull === BsHtml::NAVBAR_NAV_PULL_RIGHT || $pull === BsHtml::NAVBAR_NAV_PULL_LEFT) {
             BsHtml::addCssClass('navbar-' . $pull, $this->htmlOptions);
         }
     }
     $this->items = $this->normalizeItems($this->items, $route, $hasActiveChild);
 }
示例#4
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;
 }
示例#5
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);
 }
示例#6
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);
     }
 }
示例#7
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;
 }