Ejemplo n.º 1
2
 /**
  * Initializes the widget.
  * This method will register the bootstrap asset bundle. If you override this method,
  * make sure you call the parent implementation first.
  */
 public function init()
 {
     parent::init();
     if (!isset($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if (empty($this->leafLet) || !$this->leafLet instanceof LeafLet) {
         throw new InvalidConfigException("'leafLet' attribute cannot be empty and should be of type LeafLet component.");
     }
     if (is_numeric($this->height)) {
         $this->height .= 'px';
     }
     Html::addCssStyle($this->options, ['height' => $this->height], false);
 }
Ejemplo n.º 2
2
    /**
     * @inheritdoc
     */
    public function run()
    {
        $width = null;
        if ($this->thumbsEnabled) {
            $filename = $this->behavior->getThumbFilePath($this->attribute, $this->thumbProfileName);
        } else {
            $filename = $this->behavior->getUploadedFilePath($this->attribute);
        }
        if (is_readable($filename)) {
            list($width) = getimagesize($filename);
        } else {
            Yii::warning("Unable to read file: '{$filename}' referenced by '{$this->attribute}' in model {$this->model->className()}");
            if (empty($this->previewOptions['style'])) {
                $this->previewOptions['style'] = '';
            }
            $this->previewOptions['style'] .= ';display: none;';
        }
        $previewOptions = ArrayHelper::merge(['id' => $this->id . '-thumb', 'width' => $width], $this->previewOptions);
        if (empty($previewOptions['class'])) {
            $previewOptions['class'] = '';
        }
        $previewOptions['class'] .= ' img-responsive img-thumbnail';
        if (isset($this->model->attributeLabels()[$this->attribute]) and !isset($previewOptions['alt'])) {
            $previewOptions['alt'] = $this->model->attributeLabels()[$this->attribute];
        }
        if ($this->thumbsEnabled) {
            $url = $this->behavior->getThumbFileUrl($this->attribute, $this->thumbProfileName);
        } else {
            $url = $this->behavior->getImageFileUrl($this->attribute);
        }
        Html::addCssStyle($previewOptions, "background-image: url({$url})");
        $image = Html::tag('div', '', $previewOptions);
        $fileInput = Html::activeFileInput($this->model, $this->attribute, ['id' => $this->id . '-input'] + $this->options);
        echo $this->render('index', compact('image', 'fileInput'));
        $this->getView()->registerJs(";(function(\$){\n    var widget = \$('#{$this->id}');\n    var fileInput = widget.find('input[type=file]');\n    var preview = \$('#{$previewOptions['id']}');\n    var button = fileInput.closest('.image-up-input-button');\n\n    fileInput.on('change', function() {\n        var selectedFile = this.files[0];\n\n        if (selectedFile) {\n            var reader = new FileReader();\n            reader.readAsDataURL(selectedFile);\n            reader.onload = function (e) {\n                preview.css('background-image', 'url(' +  e.target.result + ')');\n            }\n\n            preview.show();\n        }\n    });\n\n})(jQuery);");
        $this->getView()->registerCss(<<<CSS
#{$previewOptions['id']} {
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}
CSS
);
    }
Ejemplo n.º 3
1
 /**
  * Renders menu items.
  * @param  array                  $items the menu items to be rendered
  * @return string                 the rendering result.
  * @throws InvalidConfigException if the label option is not specified in one of the items.
  */
 protected function renderItems($items)
 {
     $lines = [];
     foreach ($items as $i => $item) {
         if (isset($item['visible']) && !$item['visible']) {
             unset($items[$i]);
             continue;
         }
         if (is_string($item)) {
             $lines[] = $item;
             continue;
         }
         if (!isset($item['title'])) {
             throw new InvalidConfigException("The 'title' option is required.");
         }
         $title = $this->encode ? Html::encode($item['title']) : $item['title'];
         $titleOptions = ArrayHelper::getValue($item, 'titleOptions', []);
         Html::addCssClass($titleOptions, 'list-group-item-heading');
         $titleCode = Html::tag('h4', $title, $titleOptions);
         $description = $this->encode ? Html::encode($item['description']) : $item['description'];
         $descriptionOptions = ArrayHelper::getValue($item, 'descriptionOptions', []);
         Html::addCssClass($descriptionOptions, 'list-group-item-text');
         $descriptionCode = Html::tag('p', $description, $descriptionOptions);
         $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
         Html::addCssClass($linkOptions, 'list-group-item');
         Html::addCssStyle($linkOptions, 'word-wrap: break-word');
         if (isset($item['active']) && $item['active']) {
             Html::addCssClass($linkOptions, 'active');
         }
         $linkOptions['tabindex'] = '-1';
         $lines[] = Html::a($titleCode . "\n" . $descriptionCode, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
     }
     return Html::tag('div', implode("\n", $lines), $this->options);
 }
Ejemplo n.º 4
1
 public function render($type)
 {
     $image = $this->image;
     if (!$image) {
         $image = $this->desktop->assetsUrl . '/images/icon_application.png';
     } else {
         if (\yii\helpers\Url::isRelative($image) && $this->desktop->iconPath) {
             $image = rtrim($this->desktop->iconPath, '/') . '/' . $image;
         }
     }
     $attributes = ['src' => $image];
     $styles = [];
     switch ($type) {
         case self::DISPLAY_MENU:
             $styles = ['height' => '16px', 'position' => 'relative', 'top' => '-2px'];
             break;
         case self::DISPLAY_DOCK:
             $styles = ['height' => '16px'];
             break;
         case self::DISPLAY_TITLEBAR:
             $styles = ['float' => 'left', 'margin' => '4px 5px 0 0', 'height' => '20px'];
             break;
         case self::DISPLAY_DESKTOP:
             $styles = ['height' => '32px'];
             break;
     }
     Html::addCssStyle($attributes, $styles);
     return Html::img($attributes['src'], $attributes);
 }
Ejemplo n.º 5
1
 /**
  * @inheritdoc
  */
 public function run()
 {
     $this->_msgCat = 'kvcolor';
     if (!isset($this->type)) {
         $this->type = $this->useNative ? 'color' : 'text';
     }
     $this->width = '60px';
     $this->initI18N(__DIR__);
     if (empty($this->html5Container['id'])) {
         $this->html5Container['id'] = $this->options['id'] . '-cont';
     }
     if ($this->type === 'text') {
         Html::addCssStyle($this->html5Options, 'display:none');
         if ($this->pluginLoading) {
             Html::addCssClass($this->html5Container, 'kv-center-loading');
         }
     }
     $this->html5Options['value'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     if (substr($this->language, 0, 2) !== 'en') {
         $this->_defaultOptions += ['cancelText' => Yii::t('kvcolor', 'cancel'), 'chooseText' => Yii::t('kvcolor', 'choose'), 'clearText' => Yii::t('kvcolor', 'Clear Color Selection'), 'noColorSelectedText' => Yii::t('kvcolor', 'No Color Selected'), 'togglePaletteMoreText' => Yii::t('kvcolor', 'more'), 'togglePaletteLessText' => Yii::t('kvcolor', 'less')];
     }
     Html::addCssClass($this->containerOptions, 'spectrum-group');
     Html::addCssClass($this->html5Options, 'spectrum-source');
     Html::addCssClass($this->options, 'spectrum-input');
     if (!$this->useNative) {
         Html::addCssClass($this->html5Container, 'input-group-sp');
         $this->pluginOptions = array_replace_recursive($this->_defaultOptions, $this->pluginOptions);
     }
     $this->initInput();
     $this->registerColorInput();
 }
Ejemplo n.º 6
0
 private function renderTextInput()
 {
     if ($this->state() !== self::STATE_TEXT) {
         Html::addCssStyle($this->textInputOptions, 'display:none');
     }
     return Html::textInput(null, $this->inputValue(self::STATE_TEXT), $this->textInputOptions);
 }
Ejemplo n.º 7
0
 public function init()
 {
     parent::init();
     foreach (['url', 'srcNode'] as $property) {
         if ($this->pluginOptions[$property] === null) {
             throw new InvalidConfigException("The \"{$property}\" property must be set to \"pluginOptions\".");
         }
     }
     Html::addCssStyle($this->itemOptions, ['display' => 'none']);
 }
Ejemplo n.º 8
0
 public function init()
 {
     parent::init();
     if ($this->pageSizeMargin) {
         Html::addCssStyle($this->pageSizeOptions, $this->pageSizeMargin);
     }
     if ($this->customPageWidth) {
         Html::addCssStyle($this->customPageOptions, 'width:' . $this->customPageWidth . 'px;');
     }
     if ($this->customPageMargin) {
         Html::addCssStyle($this->customPageOptions, $this->customPageMargin);
     }
 }
Ejemplo n.º 9
0
 public function run()
 {
     if (!array_key_exists('id', $this->options)) {
         $this->options['id'] = $this->getId();
     }
     if (!is_null($this->width)) {
         Html::addCssStyle($this->options, 'width:' . $this->width);
     }
     if (!is_null($this->height)) {
         Html::addCssStyle($this->options, 'height:' . $this->height);
     }
     echo Html::tag('div', '', $this->options);
     $this->registerChart();
 }
Ejemplo n.º 10
0
 public function init()
 {
     $this->options['id'] = $this->getId();
     if (!$this->settings['name']) {
         $this->settings['name'] = $this->options['id'];
     }
     if (empty($this->settings['panels'] && is_array($this->panels))) {
         $this->settings['panels'] = $this->panels;
     }
     if (is_null($this->locale) && \Yii::$app->language != 'en-US') {
         $this->locale = strtolower(\Yii::$app->language);
     }
     Html::addCssStyle();
     parent::init();
 }
Ejemplo n.º 11
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     AceEditorAsset::register($this->getView());
     $editor_id = $this->getId();
     $editor_var = 'aceeditor_' . $editor_id;
     $this->getView()->registerJs("var {$editor_var} = ace.edit(\"{$editor_id}\")");
     $this->getView()->registerJs("{$editor_var}.setTheme(\"ace/theme/{$this->theme}\")");
     $this->getView()->registerJs("{$editor_var}.getSession().setMode(\"ace/mode/{$this->mode}\")");
     $textarea_var = 'acetextarea_' . $editor_id;
     $this->getView()->registerJs("\n            var {$textarea_var} = \$('#{$this->options['id']}').hide();\n            {$editor_var}.getSession().setValue({$textarea_var}.val());\n            {$editor_var}.getSession().on('change', function(){\n                {$textarea_var}.val({$editor_var}.getSession().getValue());\n            });\n        ");
     Html::addCssStyle($this->options, 'display: none');
     $this->containerOptions['id'] = $editor_id;
     $this->getView()->registerCss("#{$editor_id}{position:relative}");
 }
Ejemplo n.º 12
0
    /**
     * Initializes the widget.
     */
    public function init()
    {
        parent::init();
        $style = <<<EOF
    @media screen and (max-width: 767px) {
        .row-offcanvas {
            position: relative;
            -webkit-transition: all 0.25s ease-out;
            -moz-transition: all 0.25s ease-out;
            transition: all 0.25s ease-out;
        }

        .row-offcanvas-right
        .sidebar-offcanvas {
            right: -50%; /* 6 columns */
        }

        .row-offcanvas-left
        .sidebar-offcanvas {
            left: -50%; /* 6 columns */
        }

        .row-offcanvas-right.active {
            right: 50%; /* 6 columns */
        }

        .row-offcanvas-left.active {
            left: 50%; /* 6 columns */
        }

        .sidebar-offcanvas {
            position: absolute;
            top: 0;
            width: 50%; /* 6 columns */
        }
    }
EOF;
        Html::addCssStyle($options, $style);
    }
Ejemplo n.º 13
0
 public function run()
 {
     $this->registerJs();
     Html::addCssClass($this->options, 'ui progress');
     $this->options['data-percent'] = $this->percent;
     if ($this->active) {
         Html::addCssClass($this->options, 'active');
     }
     if ($this->indicating) {
         Html::addCssClass($this->options, 'indicating');
     }
     if ($this->autoHide && !$this->percent) {
         Html::addCssStyle($this->options, 'display: none');
     }
     $body = Html::beginTag('div', ['class' => 'bar']);
     $body .= Html::tag('div', $this->progressLabel, ['class' => 'progress']);
     $body .= Html::endTag('div');
     $body .= Html::tag('div', $this->label, ['class' => 'label']);
     if ($this->ajax) {
         $this->registerAjax();
     }
     echo Html::tag('div', $body, $this->options);
 }
Ejemplo n.º 14
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if ($this->empty !== false) {
         // Empty item must be first.
         $items = $this->items;
         $this->items = ['' => is_string($this->empty) ? $this->empty : Yii::t('app', 'None')] + $items;
     }
     if ($this->fullWidth) {
         Html::addCssStyle($this->options, 'width: 100%');
     }
     if ($this->hideSearch) {
         $this->clientOptions['minimumResultsForSearch'] = 'Infinity';
     }
     if ($this->multiple) {
         $this->options['multiple'] = true;
     }
     $this->registerClientScript();
     if ($this->hasModel()) {
         return Html::activeDropDownList($this->model, $this->attribute, $this->items, $this->options);
     } else {
         return Html::dropDownList($this->name, $this->value, $this->items, $this->options);
     }
 }
Ejemplo n.º 15
0
 public function render($type)
 {
     // Obviously we need the bootstrap assets for this
     \yii\bootstrap\BootstrapPluginAsset::register($this->desktop->view);
     $glyph = $this->image;
     if (!$glyph) {
         $glyph = 'folder-open';
     }
     $attributes = ['class' => "glyphicon glyphicon-{$glyph}"];
     $styles = [];
     switch ($type) {
         case self::DISPLAY_DOCK:
             $styles = ['position' => 'relative', 'top' => '3px', 'font-size' => '16px', 'padding-right' => '5px'];
             break;
         case self::DISPLAY_TITLEBAR:
             $styles = ['float' => 'left', 'margin' => '4px 8px 0 0', 'font-size' => '20px'];
             break;
         case self::DISPLAY_DESKTOP:
             $styles = ['font-size' => '32px'];
             break;
     }
     Html::addCssStyle($attributes, $styles);
     return Html::tag('span', '', $attributes);
 }
Ejemplo n.º 16
0
 public function testAddCssStyle()
 {
     $options = ['style' => 'width: 100px; height: 200px;'];
     Html::addCssStyle($options, 'width: 110px; color: red;');
     $this->assertEquals('width: 110px; height: 200px; color: red;', $options['style']);
     $options = ['style' => 'width: 100px; height: 200px;'];
     Html::addCssStyle($options, ['width' => '110px', 'color' => 'red']);
     $this->assertEquals('width: 110px; height: 200px; color: red;', $options['style']);
     $options = ['style' => 'width: 100px; height: 200px;'];
     Html::addCssStyle($options, 'width: 110px; color: red;', false);
     $this->assertEquals('width: 100px; height: 200px; color: red;', $options['style']);
     $options = [];
     Html::addCssStyle($options, 'width: 110px; color: red;');
     $this->assertEquals('width: 110px; color: red;', $options['style']);
     $options = [];
     Html::addCssStyle($options, 'width: 110px; color: red;', false);
     $this->assertEquals('width: 110px; color: red;', $options['style']);
 }
Ejemplo n.º 17
0
//标题截取长度
$dlength = 82;
?>

<div class="list">
	<?php 
//这里可以考虑从content中获取图片
?>
    <?php 
echo Html::a(General::showImg($model->pic_url, 'c', $model->title, 'px', 140, 102), ['/site/post/view', 'id' => $model->id], ['class' => 'img', 'title' => $model->title]);
?>
    <div class="list_detail">
    	<?php 
$options = ['style' => ''];
if (!empty($model->colorval) || !empty($model->boldval)) {
    Html::addCssStyle($options, ['color' => $model->colorval, 'font-weight' => $model->boldval]);
}
?>
    	<?php 
echo Html::a(StringHelper::truncate($model->title, $length), ['/site/post/view', 'id' => $model->id], ['class' => 'title', 'title' => $model->title, 'style' => $options['style']]);
?>
        
        <div class="cont">
        	<?php 
if (empty($model->description)) {
    $des = $model->content;
    //去除图片链接
} else {
    $des = $model->description;
}
echo StringHelper::truncate(strip_tags($des), $dlength);
Ejemplo n.º 18
0
 /**
  * Initializes the inline settings & options.
  *
  * @throws InvalidConfigException
  */
 protected function initInlineOptions()
 {
     $title = Yii::t('kveditable', 'Close');
     $this->inlineSettings = array_replace_recursive(['templateBefore' => self::INLINE_BEFORE_1, 'templateAfter' => self::INLINE_AFTER_1, 'options' => ['class' => 'panel panel-default'], 'closeButton' => "<button class='kv-editable-close close' title='{$title}'>&times;</button>"], $this->inlineSettings);
     Html::addCssClass($this->contentOptions, 'kv-editable-inline');
     Html::addCssStyle($this->contentOptions, 'display:none');
 }
Ejemplo n.º 19
0
 /**
  * Renders a multi select list box. This control extends the checkboxList and radioList available in
  * [[YiiActiveField]] - to display a scrolling multi select list box.
  *
  * @param array $items the data item used to generate the checkboxes or radio.
  * @param array $options the options for checkboxList or radioList. Additional parameters
  * - `height`: _string_, the height of the multiselect control - defaults to 145px
  * - `selector`: _string_, whether checkbox or radio - defaults to checkbox
  * - `container`: _array_, options for the multiselect container
  * - `unselect`: _string_, the value that should be submitted when none of the radio buttons is selected. By setting
  *   this option, a hidden input will be generated.
  * - `separator`: _string_, the HTML code that separates items.
  * - `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a
  *   single item in $items. The signature of this callback must be:
  * - `inline`: _boolean_, whether the list should be displayed as a series on the same line, default is false
  * - `selector`: _string_, whether the selection input is [[TYPE_RADIO]] or [[TYPE_CHECKBOX]]
  *
  * @return ActiveField object
  */
 public function multiselect($items, $options = [])
 {
     $this->initDisability($options);
     $options['encode'] = false;
     $height = ArrayHelper::remove($options, 'height', self::MULTI_SELECT_HEIGHT);
     $selector = ArrayHelper::remove($options, 'selector', self::TYPE_CHECKBOX);
     $container = ArrayHelper::remove($options, 'container', []);
     Html::addCssStyle($container, 'height:' . $height, true);
     Html::addCssClass($container, $this->addClass . ' input-multiselect');
     $container['tabindex'] = 0;
     $this->_multiselect = Html::tag('div', '{input}', $container);
     return $selector == self::TYPE_RADIO ? $this->radioList($items, $options) : $this->checkboxList($items, $options);
 }
Ejemplo n.º 20
0
 /**
  * @param $img
  * @param array $loadingOptions
  * @return string
  */
 public function loadingBox($img, $loadingOptions = [])
 {
     DisplayAsset::register($this->getView());
     $loadingOptions = ArrayHelper::merge($this->loadingOptions, $loadingOptions);
     Html::addCssClass($loadingOptions, 'display');
     $width = ArrayHelper::remove($loadingOptions, 'width', '100%');
     $height = ArrayHelper::remove($loadingOptions, 'height', 400);
     if (is_integer($width) && $width < $this->loadingBgSize['width']) {
         Html::addCssClass($loadingOptions, 'bg-size');
     } elseif (is_integer($height) && $height < $this->loadingBgSize['height']) {
         Html::addCssClass($loadingOptions, 'bg-size');
     }
     if (is_integer($width)) {
         $width .= 'px';
     }
     if (is_integer($height)) {
         $height .= 'px';
     }
     Html::addCssStyle($loadingOptions, ['width' => $width, 'height' => $height]);
     if ($width == '100%') {
         Html::addCssStyle($loadingOptions, ['display' => 'block']);
     }
     $html = Html::beginTag('div', $loadingOptions);
     $html .= $img;
     $html .= Html::tag('div', null, ['class' => 'display-loading']);
     $html .= Html::endTag('div');
     return $html;
 }
Ejemplo n.º 21
0
 /**
  * @return string
  */
 protected function renderInputAddon()
 {
     $content = [];
     if (!array_key_exists('class', $this->inputAddonOptions)) {
         Html::addCssClass($this->inputAddonOptions, 'input-group-addon');
     }
     if (!array_key_exists('style', $this->inputAddonOptions)) {
         Html::addCssStyle($this->inputAddonOptions, ['cursor' => 'pointer']);
     }
     $content[] = Html::beginTag('span', $this->inputAddonOptions);
     if ($this->inputAddonContent) {
         $content[] = $this->inputAddonContent;
     } else {
         $content[] = Html::tag('span', '', ['class' => 'glyphicon glyphicon-calendar']);
     }
     $content[] = Html::endTag('span');
     return implode("\n", $content);
 }
Ejemplo n.º 22
0
 /**
  Init config set options
 */
 protected function initOption()
 {
     if (!isset($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if ($this->multiple) {
         $this->options['data-multiple'] = $this->boolToStr(true);
         $this->options['multiple'] = true;
     }
     if (isset($this->tags)) {
         $this->options['data-tags'] = $this->tags;
         $this->options['multiple'] = true;
     }
     if ($this->loadItemsUrl !== null) {
         $this->options['data-load-items-url'] = Url::to($this->loadItemsUrl);
     }
     if ($this->toggleEnable) {
         $this->options['data-toggle-enable'] = $this->boolToStr($this->toggleEnable);
     }
     if ($this->language) {
         $this->options['data-language'] = $this->language;
     }
     if (isset($this->ajax)) {
         $this->options['data-ajax--url'] = Url::to($this->ajax);
         $this->options['data-ajax--cache'] = $this->boolToStr($this->ajax);
         $this->options['data-minimum-input-length'] = $this->minimumInputLength;
     }
     if (isset($this->placeholder)) {
         $this->options['data-placeholder'] = $this->placeholder;
     }
     $this->clientOptions['theme'] = $this->theme;
     Html::addCssStyle($this->options, ['width' => '100%'], false);
     Html::addCssClass($this->options, 'select2 form-control');
 }
Ejemplo n.º 23
0
 /**
  * Renders the special HTML5 input
  * Mainly useful for the color and range inputs
  */
 protected function renderInput()
 {
     Html::addCssClass($this->options, 'form-control');
     $size = isset($this->size) ? ' input-group-' . $this->size : '';
     Html::addCssClass($this->containerOptions, 'input-group input-group-html5' . $size);
     if (isset($this->width) && (int) $this->width > 0) {
         Html::addCssStyle($this->html5Container, 'width:' . $this->width);
     }
     Html::addCssClass($this->html5Container, 'input-group-addon addon-' . $this->type);
     $caption = $this->getInput('textInput');
     $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     $input = Html::input($this->type, $this->html5Options['id'], $value, $this->html5Options);
     $prepend = static::getAddonContent(ArrayHelper::getValue($this->addon, 'prepend', ''));
     $append = static::getAddonContent(ArrayHelper::getValue($this->addon, 'append', ''));
     $preCaption = static::getAddonContent(ArrayHelper::getValue($this->addon, 'preCaption', ''));
     $prepend .= Html::tag('span', $input, $this->html5Container);
     $content = Html::tag('div', $prepend . $preCaption . $caption . $append, $this->containerOptions);
     Html::addCssClass($this->noSupportOptions, 'alert alert-warning');
     if ($this->noSupport === false) {
         $message = '';
     } else {
         $noSupport = !empty($this->noSupport) ? $this->noSupport : Yii::t('kvbase', 'It is recommended you use an upgraded browser to display the {type} control properly.', ['type' => $this->type]);
         $message = "\n<br>" . Html::tag('div', $noSupport, $this->noSupportOptions);
     }
     return "<!--[if lt IE 10]>\n{$caption}{$message}\n<![endif]--><![if gt IE 9]>\n{$content}\n<![endif]>";
 }
Ejemplo n.º 24
0
 /**
  * Parses the input to render based on markup type
  *
  * @param string $input
  * @return string
  */
 protected function parseMarkup($input)
 {
     $css = $this->disabled ? ' disabled' : '';
     if ($this->type == self::TYPE_INPUT || $this->type == self::TYPE_INLINE) {
         if (isset($this->size)) {
             Html::addCssClass($this->options, 'input-' . $this->size . $css);
         }
     } elseif ($this->type != self::TYPE_BUTTON && isset($this->size)) {
         Html::addCssClass($this->_container, 'input-group input-group-' . $this->size . $css);
     } elseif ($this->type != self::TYPE_BUTTON) {
         Html::addCssClass($this->_container, 'input-group' . $css);
     }
     if ($this->type == self::TYPE_INPUT) {
         return $input;
     }
     if ($this->type == self::TYPE_COMPONENT_PREPEND) {
         Html::addCssClass($this->_container, 'date');
         $addon = $this->renderAddon($this->pickerButton) . $this->renderAddon($this->removeButton, 'remove');
         return Html::tag('div', $addon . $input, $this->_container);
     }
     if ($this->type == self::TYPE_COMPONENT_APPEND) {
         Html::addCssClass($this->_container, 'date');
         $addon = $this->renderAddon($this->removeButton, 'remove') . $this->renderAddon($this->pickerButton);
         return Html::tag('div', $input . $addon, $this->_container);
     }
     if ($this->type == self::TYPE_BUTTON) {
         Html::addCssClass($this->_container, 'date');
         $label = ArrayHelper::remove($this->buttonOptions, 'label', self::CALENDAR_ICON);
         if (!isset($this->buttonOptions['disabled'])) {
             $this->buttonOptions['disabled'] = $this->disabled;
         }
         if (empty($this->buttonOptions['class'])) {
             $this->buttonOptions['class'] = 'btn btn-default';
         }
         $button = Html::button($label, $this->buttonOptions);
         Html::addCssStyle($this->_container, 'display:block');
         return Html::tag('span', "{$input}{$button}", $this->_container);
     }
     if ($this->type == self::TYPE_INLINE) {
         $this->_id = $this->options['id'] . '-inline';
         $this->_container['id'] = $this->_id;
         return Html::tag('div', '', $this->_container) . $input;
     }
 }
Ejemplo n.º 25
0
 /**
  * Generates the size css and adds it to the options
  */
 protected function addSizeToOptions()
 {
     $val = floatval($this->sizeCss);
     $charPos = 0;
     while (is_numeric($this->sizeCss[$charPos])) {
         $charPos++;
     }
     $unit = $charPos > 0 ? substr($this->sizeCss, $charPos) : '';
     Html::addCssStyle($this->options, ['width' => $this->isSquared ? $val . $unit : 1.33333 * $val . $unit, 'line-height' => $val . $unit]);
 }
Ejemplo n.º 26
0
 /**
  * Parses the input to render based on markup type
  *
  * @param string $input
  *
  * @return string
  */
 protected function parseMarkup($input)
 {
     $css = $this->disabled ? ' disabled' : '';
     $size = isset($this->size) ? "input-{$this->size} " : '';
     switch ($this->type) {
         case self::TYPE_INPUT:
             Html::addCssClass($this->options, $size . $css);
             return $input;
         case self::TYPE_COMPONENT_PREPEND:
         case self::TYPE_COMPONENT_APPEND:
             $size = isset($this->size) ? "input-group-{$this->size} " : '';
             Html::addCssClass($this->_container, "input-group {$size}date");
             $out = strtr($this->layout, ['{picker}' => $this->renderAddon($this->pickerButton), '{remove}' => $this->renderAddon($this->removeButton, 'remove'), '{input}' => $input]);
             return Html::tag('div', $out, $this->_container);
         case self::TYPE_BUTTON:
             Html::addCssClass($this->_container, 'date' . $css);
             $label = ArrayHelper::remove($this->buttonOptions, 'label', self::CALENDAR_ICON);
             if (!isset($this->buttonOptions['disabled'])) {
                 $this->buttonOptions['disabled'] = $this->disabled;
             }
             if (empty($this->buttonOptions['class'])) {
                 $this->buttonOptions['class'] = 'btn btn-default';
             }
             $button = Html::button($label, $this->buttonOptions);
             Html::addCssStyle($this->_container, 'display:block');
             return Html::tag('span', "{$input}{$button}", $this->_container);
         case self::TYPE_RANGE:
             $size = isset($this->size) ? "input-group-{$this->size} " : '';
             Html::addCssClass($this->_container, "input-group {$size}input-daterange");
             $this->initDisability($this->options2);
             if (isset($this->form)) {
                 Html::addCssClass($this->options, 'form-control kv-field-from');
                 Html::addCssClass($this->options2, 'form-control kv-field-to');
                 $input = $this->form->field($this->model, $this->attribute, ['template' => '{input}{error}', 'options' => ['class' => 'kv-container-from form-control']])->textInput($this->options);
                 $input2 = $this->form->field($this->model, $this->attribute2, ['template' => '{input}{error}', 'options' => ['class' => 'kv-container-to form-control']])->textInput($this->options2);
             } else {
                 if (empty($this->options2['id'])) {
                     $this->options2['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute2) : $this->getId() . '-2';
                 }
                 Html::addCssClass($this->options2, 'form-control');
                 $input2 = $this->hasModel() ? Html::activeTextInput($this->model, $this->attribute2, $this->options2) : Html::textInput($this->name2, $this->value2, $this->options2);
             }
             $out = strtr($this->layout, ['{input1}' => $input, '{separator}' => "<span class='input-group-addon kv-field-separator'>{$this->separator}</span>", '{input2}' => $input2]);
             return Html::tag('div', $out, $this->_container);
         case self::TYPE_INLINE:
             Html::addCssClass($this->options, $size . $css);
             return Html::tag('div', '', $this->_container) . $input;
         default:
             return '';
     }
 }
Ejemplo n.º 27
0
 /**
  * Parses and fetches updated content options for grid visibility and format
  *
  * @param mixed   $model the data model being rendered
  * @param mixed   $key the key associated with the data model
  * @param integer $index the zero-based index of the data item among the item array returned by
  *     [[GridView::dataProvider]].
  *
  * @return array
  */
 protected function fetchContentOptions($model, $key, $index)
 {
     if ($this->contentOptions instanceof \Closure) {
         $options = call_user_func($this->contentOptions, $model, $key, $index, $this);
     } else {
         $options = $this->contentOptions;
     }
     if ($this->hidden === true) {
         Html::addCssClass($options, "kv-grid-hide");
     }
     if ($this->hiddenFromExport === true) {
         Html::addCssClass($options, "skip-export");
     }
     if (is_array($this->hiddenFromExport) && !empty($this->hiddenFromExport)) {
         $tag = 'skip-export-';
         $css = $tag . implode(" {$tag}", $this->hiddenFromExport);
         Html::addCssClass($options, $css);
     }
     if ($this->isValidAlignment()) {
         Html::addCssClass($options, "kv-align-{$this->hAlign}");
     }
     if ($this->noWrap) {
         Html::addCssClass($options, GridView::NOWRAP);
     }
     if ($this->isValidAlignment('vAlign')) {
         Html::addCssClass($options, "kv-align-{$this->vAlign}");
     }
     if (trim($this->width) != '') {
         Html::addCssStyle($options, "width:{$this->width};");
     }
     return $options;
 }
Ejemplo n.º 28
0
 /**
  * Renders the source Input for the Select2 plugin.
  * Graceful fallback to a normal HTML select dropdown
  * or text input - in case JQuery is not supported by
  * the browser
  */
 protected function renderInput()
 {
     if ($this->pluginLoading) {
         $this->_loadIndicator = '<div class="kv-plugin-loading loading-' . $this->options['id'] . '">&nbsp;</div>';
         Html::addCssStyle($this->options, 'display:none');
     }
     $input = $this->getInput('dropDownList', true, true);
     echo $this->_loadIndicator . $this->embedAddon($input);
 }
Ejemplo n.º 29
0
 /**
  * Initializes the widget
  *
  * @throw InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->_hidden = !empty($this->pluginOptions['data']) ||
         !empty($this->pluginOptions['query']) ||
         !empty($this->pluginOptions['ajax']) ||
         isset($this->pluginOptions['tags']);
     if (!isset($this->data) && !$this->_hidden) {
         throw new InvalidConfigException("No 'data' source found for Select2. Either the 'data' property must be set OR one of 'data', 'query', 'ajax', or 'tags' must be set within 'pluginOptions'.");
     }
     if ($this->hideSearch) {
         $css = ArrayHelper::getValue($this->pluginOptions, 'dropdownCssClass', '');
         $css .= ' kv-hide';
         $this->pluginOptions['dropdownCssClass'] = $css;
     }
     if (!empty($this->options['placeholder']) && !$this->_hidden &&
         (empty($this->options['multiple']) || $this->options['multiple'] == false)
     ) {
         $this->data = ["" => ""] + $this->data;
     }
     Html::addCssClass($this->options, 'form-control');
     Html::addCssStyle($this->options, 'width:100%', false);
     $this->registerAssets();
     $this->renderInput();
 }
Ejemplo n.º 30
0
 /**
  * Renders a table row with the given data model and key.
  * @param mixed $model the data model to be rendered
  * @param mixed $key the key associated with the data model
  * @param integer $index the zero-based index of the data model among the model array returned by [[dataProvider]].
  * @return string the rendering result
  */
 public function renderTableRow($model, $key, $index)
 {
     $cells = [];
     /* @var $column TreeColumn */
     foreach ($this->columns as $column) {
         $cells[] = $column->renderDataCell($model, $key, $index);
     }
     if ($this->rowOptions instanceof Closure) {
         $options = call_user_func($this->rowOptions, $model, $key, $index, $this);
     } else {
         $options = $this->rowOptions;
     }
     $options['data-key'] = is_array($key) ? json_encode($key) : (string) $key;
     $id = ArrayHelper::getValue($model, $this->keyColumnName);
     Html::addCssClass($options, "treegrid-{$id}");
     $parentId = ArrayHelper::getValue($model, $this->parentColumnName);
     if ($parentId) {
         if (ArrayHelper::getValue($this->pluginOptions, 'initialState') == 'collapsed') {
             Html::addCssStyle($options, 'display: none;');
         }
         Html::addCssClass($options, "treegrid-parent-{$parentId}");
     }
     return Html::tag('tr', implode('', $cells), $options);
 }