/** * Widget's initialization method */ public function init() { parent::init(); if (!$this->selector) { $this->selector = '#' . ArrayHelper::getValue($this->options, 'id'); } }
/** * Renders menu items. * @param array $items the menu items to be rendered * @return string the rendering result. * @throws \CException if the label option is not specified in one of the items. */ protected function renderItems($items) { $lines = array(); foreach ($items as $item) { if (is_string($item)) { $lines[] = $item; continue; } if (!isset($item['label'])) { throw new \CException("The 'label' option is required."); } $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); $linkOptions['tabindex'] = '-1'; if (isset($item['items'])) { $this->addCssClass($options, 'dropdown-submenu'); $content = \CHtml::link($label, '#', $linkOptions) . $this->renderItems($item['items']); } else { $content = \CHtml::link($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions); } $lines[] = \CHtml::tag('li', $options, $content); } return \CHtml::tag('ul', $this->options, implode("\n", $lines)); }
/** * Widget's init function. */ public function init() { parent::init(); list($name, $id) = $this->resolveNameID(); $this->options['id'] = ArrayHelper::getValue($this->options, 'id', $id); $this->options['name'] = ArrayHelper::getValue($this->options, 'name', $name); }
/** * Builds meta-tag options based on the options and attributes */ public function buildOptions() { $options = $this->options; ArrayHelper::remove($this->options, 'disabled'); $this->addCssClass($options, 'switch'); $options['data-animated'] = $this->animated ? 'true' : 'false'; $options['data-on-label'] = $this->onLabel; $options['data-off-label'] = $this->offLabel; $options['data-on'] = $this->onStyle ? $this->offStyle : 'primary'; $options['data-off'] = $this->offStyle ? $this->offStyle : 'default'; }
/** * Widget's initialization method * @throws \CException */ public function init() { parent::init(); if ($this->route === null) { throw new \CException(\Yii::t('wheels', '"route" attribute cannot be blank')); } if ($this->noScriptText === null) { $this->noScriptText = \Yii::t('wheels', "Please enable JavaScript to use file uploader."); } $this->clientOptions = ArrayHelper::merge(array('request' => array('endpoint' => \CHtml::normalizeUrl($this->route), 'inputName' => ArrayHelper::getValue($this->options, 'name')), 'validation' => $this->getValidator(), 'messages' => array('typeError' => \Yii::t('wheels', '{file} has an invalid extension. Valid extension(s): {extensions}.'), 'sizeError' => \Yii::t('wheels', '{file} is too large, maximum file size is {sizeLimit}.'), 'minSizeError' => \Yii::t('wheels', '{file} is too small, minimum file size is {minSizeLimit}.'), 'emptyError:' => \Yii::t('wheels', '{file} is empty, please select files again without it.'), 'noFilesError' => \Yii::t('wheels', 'No files to upload.'), 'onLeave' => \Yii::t('zii', 'The files are being uploaded, if you leave now the upload will be cancelled.'))), $this->clientOptions); }
/** * Registers required client script for bootstrap datepicker. */ public function registerClientScript() { /* @var $cs \CClientScript */ $cs = \Yii::app()->getClientScript(); $this->registerCss('datepicker.css', 'wheels.widgets.assets.datepicker'); $cs->registerScriptFile($this->getAssetsUrl() . '/js/bootstrap-datepicker.js'); if ($language = ArrayHelper::getValue($this->clientOptions, 'language')) { $cs->registerScriptFile($this->getAssetsUrl() . '/js/locales/bootstrap-datepicker.' . $language . '.js', \CClientScript::POS_END); } $this->registerPlugin('datepicker'); }
/** * Generates the buttons that compound the group as specified on [[items]]. * @return string the rendering result. */ protected function renderButtons() { $buttons = array(); foreach ($this->buttons as $button) { if (is_array($button)) { $label = ArrayHelper::getValue($button, 'label'); $options = ArrayHelper::getValue($button, 'options'); $buttons[] = Button::widget(array('label' => $label, 'options' => $options, 'encodeLabel' => $this->encodeLabels)); } else { $buttons[] = $button; } } return implode("\n", $buttons); }
/** * Renders field */ public function renderField() { list($name, $id) = $this->resolveNameID(); $this->options['id'] = ArrayHelper::getValue($this->options, 'id', $id); $this->options['name'] = ArrayHelper::getValue($this->options, 'name', $name); $tagOptions = $this->options; $tagOptions['id'] = 'aceEditor_' . $tagOptions['id']; echo \CHtml::tag('div', $tagOptions); $this->options['style'] = 'display:none'; if ($this->hasModel()) { echo \CHtml::activeTextArea($this->model, $this->attribute, $this->options); } else { echo \CHtml::textArea($name, $this->value, $this->options); } $this->options = $tagOptions; }
/** * Registers required client script for bootstrap select2. It is not used through bootstrap->registerPlugin * in order to attach events if any */ public function registerClientScript() { /* publish assets dir */ $assetsUrl = $this->getAssetsUrl('wheels.widgets.assets.redactor'); /* @var $cs CClientScript */ $cs = \Yii::app()->getClientScript(); $script = YII_DEBUG ? 'redactor.js' : 'redactor.min.js'; $cs->registerCssFile($assetsUrl . '/css/redactor.css')->registerScriptFile($assetsUrl . '/js/' . $script); /* register language */ $language = ArrayHelper::getValue($this->clientOptions, 'lang'); if (!empty($language) && $language != 'en') { $cs->registerScriptFile($assetsUrl . '/js/langs/' . $language . '.js', \CClientScript::POS_END); } /* register plugins (if any) */ $this->registerPlugins($assetsUrl); $this->registerPlugin('redactor'); }
/** * Publishes and registers the necessary script files. */ protected function registerClientScript() { /* publish assets dir */ $assetsUrl = $this->getAssetsUrl('wheels.widgets.assets.highcharts'); /* @var $cs CClientScript */ $cs = \Yii::app()->getClientScript(); $cs->registerScriptFile($assetsUrl . '/js/highcharts.js'); /* register required files */ $defaultOptions = array('exporting' => array('enabled' => true)); $this->clientOptions = ArrayHelper::merge($defaultOptions, $this->clientOptions); if (isset($this->clientOptions['exporting']) && @$this->clientOptions['exporting']['enabled']) { $cs->registerScriptFile($assetsUrl . '/js/modules/exporting.js'); } if ($theme = ArrayHelper::getValue($this->clientOptions, 'theme')) { $cs->registerScriptFile($assetsUrl . '/js/themes/' . $theme . '.js'); } $options = \CJavaScript::encode($this->clientOptions); $script = "var highchart{$this->options['id']} = new Highcharts.Chart({$options});"; $cs->registerScript(md5($script), $script); }
/** * Renders the close button. * @return string the rendering result */ protected function renderCloseButton() { if ($this->closeButton !== null) { $tag = ArrayHelper::remove($this->closeButton, 'tag', 'button'); $label = ArrayHelper::remove($this->closeButton, 'label', '×'); if ($tag === 'button' && !isset($this->closeButton['type'])) { $this->closeButton['type'] = 'button'; } return \CHtml::tag($tag, $this->closeButton, $label); } else { return null; } }
/** * Initializes the widget. */ public function init() { $this->options['id'] = ArrayHelper::getValue($this->options, 'id', $this->getId()); }
/** * Renders the data cell content. * This method renders the view, update and toggle buttons in the data cell. * @param integer $row the row number (zero-based) * @param mixed $data the data associated with the row */ protected function renderDataCellContent($row, $data) { $checked = \CHtml::value($data, $this->name); $toggleOptions = $this->toggleOptions; $toggleOptions['icon'] = $checked === null ? $this->emptyIcon : ($checked ? $this->checkedIcon : $this->uncheckedIcon); $toggleOptions['url'] = isset($toggleOptions['url']) ? $this->evaluateExpression($toggleOptions['url'], array('data' => $data, 'row' => $row)) : '#'; if (!$this->displayText) { $htmlOptions = ArrayHelper::remove($this->toggleOptions, 'htmlOptions', array()); $htmlOptions['title'] = $this->getButtonLabel($checked); $htmlOptions['rel'] = 'tooltip'; echo \CHtml::link($toggleOptions['icon'], $toggleOptions['url'], $htmlOptions); } else { echo \CHtml::button($this->getButtonLabel($checked), $toggleOptions); } }
/** * Renders a single carousel item * @param string|array $item a single item from [[items]] * @param integer $index the item index as the first item should be set to `active` * @return string the rendering result * @throws \CException if the item is invalid */ public function renderItem($item, $index) { if (is_string($item)) { $content = $item; $caption = null; $options = array(); } elseif (isset($item['content'])) { $content = $item['content']; $caption = ArrayHelper::getValue($item, 'caption'); if ($caption !== null) { $caption = \CHtml::tag('div', array('class' => 'carousel-caption'), $caption); } $options = ArrayHelper::getValue($item, 'options', array()); } else { throw new \CException('The "content" option is required.'); } $this->addCssClass($options, 'item'); if ($index === 0) { $this->addCssClass($options, 'active'); } return \CHtml::tag('div', $options, $content . "\n" . $caption); }
/** * Renders the progress. * @return string the rendering result. * @throws \CException if the "percent" option is not set in a stacked progress bar. */ protected function renderProgress() { if (empty($this->bars)) { return $this->renderBar($this->percent, $this->label, $this->barOptions); } $bars = array(); foreach ($this->bars as $bar) { $label = ArrayHelper::getValue($bar, 'label', ''); if (!isset($bar['percent'])) { throw new \CException("The 'percent' option is required."); } $options = ArrayHelper::getValue($bar, 'options', array()); $bars[] = $this->renderBar($bar['percent'], $label, $options); } return implode("\n", $bars); }
/** * Builds the options */ protected function buildOptions() { $options = array('arrows' => $this->arrows, 'delayOut' => $this->delayOut, 'durationIn' => $this->durationIn, 'durationOut' => $this->durationOut, 'valueLabels' => $this->valueLabels, 'formatter' => $this->formatter, 'step' => $this->step, 'wheelMode' => $this->wheelMode, 'wheelSpeed' => $this->wheelSpeed, 'type' => $this->type == 'dateRange' ? null : $this->inputType); $this->clientOptions = array_filter($options); if ($this->minRange && $this->maxRange && $this->minRange < $this->maxRange) { $this->clientOptions = ArrayHelper::merge($this->clientOptions, array('range' => array('min' => $this->minRange, 'max' => $this->maxRange))); } if ($this->minValue && $this->maxValue && $this->minValue < $this->maxValue) { $this->clientOptions = ArrayHelper::merge($this->clientOptions, array('bounds' => array('min' => $this->minValue, 'max' => $this->maxValue))); } if ($this->minDefaultValue && $this->maxDefaultValue && $this->minDefaultValue < $this->maxDefaultValue) { $this->clientOptions = ArrayHelper::merge($this->clientOptions, array('defaultValues' => array('min' => $this->minDefaultValue, 'max' => $this->maxDefaultValue))); } }
/** * Renders a widget's item. * @param mixed $item the item to render. * @return string the rendering result. * @throws \CException */ public function renderItem($item) { if (is_string($item)) { return $item; } if (!isset($item['label'])) { throw new \CException("The 'label' option is required."); } $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); $items = ArrayHelper::getValue($item, 'items'); $url = \Yii::app()->createUrl(ArrayHelper::getValue($item, 'url', '#')); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); if (ArrayHelper::getValue($item, 'active')) { $this->addCssClass($options, 'active'); } if ($items !== null) { $linkOptions['data-toggle'] = 'dropdown'; $this->addCssClass($options, 'dropdown'); $this->addCssClass($urlOptions, 'dropdown-toggle'); $label .= ' ' . \CHtml::tag('b', array('class' => 'caret'), ''); if (is_array($items)) { $items = Dropdown::widget(array('items' => $items, 'clientOptions' => false)); } } return \CHtml::tag('li', $options, \CHtml::link($label, $url, $linkOptions) . $items); }
/** * Renders a item. The item can be a string, a custom class or a Nav widget (defaults if no class specified. * @param mixed $item the item to render. If array, it is assumed the configuration of a widget being `class` * required and if not specified, then defaults to `yii\bootstrap\Nav`. * @return string the rendering result. * @throws \CException */ protected function renderItem($item) { if (is_string($item)) { return $item; } $config = ArrayHelper::getValue($item, 'options', array()); $config['clientOptions'] = false; $class = ArrayHelper::getValue($item, 'class', 'wheels.bootstrap.Nav'); return $class::widget($config); }
/** * Renders fileupload views */ public function renderViews() { $htmlOptions = array(); $htmlOptions['multiple'] = ArrayHelper::remove($this->options, 'multiple', ''); $htmlOptions['name'] = ArrayHelper::remove($this->options, 'name'); $this->render($this->uploadView); $this->render($this->downloadView); $this->render($this->formView, compact('htmlOptions')); if ($this->previewImages || $this->imageProcessing) { $this->render($this->galleryView); } }
/** * Builds the [[clientOptions]] of the plugin. */ protected function buildOptions() { $onChange = ArrayHelper::remove($this->clientEvents, 'onChange', 'js:$.noop'); $config = array('onChange' => $onChange, 'width' => $this->width, 'height' => $this->height, 'animated' => $this->animated, 'transitionSpeed' => $this->transitionSpeed, 'label' => array('enabled' => $this->onLabel, 'disabled' => $this->offLabel), 'style' => array()); if (!empty($this->enabledStyle)) { $config['style']['enabled'] = $this->enabledStyle; } if (!empty($this->disabledStyle)) { $config['style']['disabled'] = $this->disabledStyle; } if (!empty($this->customEnabledStyle)) { $config['style']['custom'] = array('enabled' => $this->customEnabledStyle); } if (!empty($this->customDisabledStyle)) { if (isset($config['style']['custom'])) { $config['style']['custom']['disabled'] = $this->customDisabledStyle; } else { $config['style']['custom'] = array('disabled' => $this->customDisabledStyle); } } foreach ($config as $key => $element) { if (empty($element)) { unset($config[$key]); } } $this->clientOptions = ArrayHelper::merge($this->clientOptions, $config); }
/** * Renders a single collapsible item group * @param string $header a label of the item group [[items]] * @param array $item a single item from [[items]] * @param integer $index the item index as each item group content must have an id * @return string the rendering result * @throws \CException */ public function renderItem($header, $item, $index) { if (isset($item['content'])) { $id = $this->options['id'] . '-collapse' . $index; $options = ArrayHelper::getValue($item, 'contentOptions', array()); $options['id'] = $id; $this->addCssClass($options, 'accordion-body collapse'); $header = \CHtml::link($header, '#' . $id, array('class' => 'accordion-toggle', 'data-toggle' => 'collapse', 'data-parent' => '#' . $this->options['id'])) . "\n"; $content = \CHtml::tag('div', $item['content'], array('class' => 'accordion-inner')) . "\n"; } else { throw new \CException('The "content" option is required.'); } $group = array(); $group[] = \CHtml::tag('div', array('class' => 'accordion-heading'), $header); $group[] = \CHtml::tag('div', $options, $content); return implode("\n", $group); }
/** * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also * configure `panes` accordingly. * @param array $items the dropdown items configuration. * @param array $panes the panes reference array. * @return boolean whether any of the dropdown items is `active` or not. * @throws \CException */ protected function renderDropdown(&$items, &$panes) { $itemActive = false; foreach ($items as $n => &$item) { if (is_string($item)) { continue; } if (!isset($item['content'])) { throw new \CException("The 'content' option is required."); } $content = ArrayHelper::remove($item, 'content'); $options = ArrayHelper::remove($item, 'contentOptions', array()); $this->addCssClass($options, 'tab-pane'); if (ArrayHelper::remove($item, 'active')) { $this->addCssClass($options, 'active'); $this->addCssClass($item['options'], 'active'); $itemActive = true; } $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd-tab' . $n); $item['url'] = '#' . $options['id']; $item['linkOptions']['data-toggle'] = 'tab'; $panes[] = \CHtml::tag('div', $options, $content); unset($item); } return $itemActive; }