/**
  * (non-PHPdoc)
  *
  * @see \yii\base\Widget::run()
  */
 public function run()
 {
     if (!empty($this->_fields)) {
         throw new InvalidCallException('Each beginField() should have a matching endField() call.');
     }
     echo Html::endForm();
 }
 /**
  * 渲染选项
  */
 protected function renderOptions()
 {
     $html = '';
     if ($this->items) {
         foreach ($this->items as $key => $val) {
             $attr = ['value' => $key];
             if ($this->value !== false && $this->value == $key) {
                 $attr['selected'] = 'true';
             }
             $html .= Html::tag('option', $val, $attr);
             unset($attr);
         }
     }
     return $html;
 }
 /**
  *  渲染工具列表
  */
 protected function renderTools()
 {
     if ($this->items) {
         $toolsContent = '';
         foreach ($this->items as $item) {
             $innerContent = '';
             if ($item['icon']) {
                 $innerContent = Html::tag('i', '', ['class' => $item['icon']]);
             }
             $options = isset($item['options']) ? $item['options'] : [];
             $toolsContent .= Html::tag('a', $innerContent . $item['label'], ArrayHelper::merge(['data-original-title' => $item['title'], 'title' => $item['title']], $options));
             unset($innerContent);
             unset($options);
         }
         return $toolsContent;
     }
     return '';
 }
示例#4
0
 /**
  * Initializes the widget options.
  * This method sets the default values for various options.
  */
 protected function initOptions()
 {
     $this->options = array_merge(['class' => 'fade', 'role' => 'dialog', 'tabindex' => -1, 'aria-hidden' => 'true'], $this->options);
     Html::addCssClass($this->options, 'modal');
     if ($this->closeButton !== false) {
         $this->closeButton = array_merge(['data-dismiss' => 'modal', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton);
     }
     if ($this->toggleButton !== false) {
         $this->toggleButton = array_merge(['data-toggle' => 'modal'], $this->toggleButton);
         if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) {
             $this->toggleButton['data-target'] = '#' . $this->options['id'];
         }
     }
     /**
      * 初始化操作按钮
      */
     if ($this->operationButtons === false) {
         $this->operationButtons = Html::tag('button', Module::t('close'), ['data-dismiss' => 'modal', 'class' => 'btn btn-default']);
         $this->operationButtons .= Html::tag('button', Module::t('save'), ['id' => 'btn-submit', 'class' => 'btn green-meadow']);
         $this->footer = $this->operationButtons;
     }
 }
示例#5
0
 /**
  * @inheritDoc
  */
 public static function error($model, $attribute, $options = [])
 {
     $tag = isset($options['tag']) ? $options['tag'] : 'div';
     unset($options['tag'], $options['encode']);
     return Html::tag($tag, '', $options);
 }
示例#6
0
 /**
  * 设置默认配置项
  */
 protected function initOptions()
 {
     $this->options = array_merge(['class' => 'table table-striped table-bordered table-hover dataTable'], $this->options);
     if (!$this->pages) {
         Html::addCssClass($this->options, 'no-footer');
     }
     if ($this->class) {
         if (is_string($this->class)) {
             $this->class = explode(' ', $this->class);
         }
         foreach ($this->class as $cl) {
             Html::addCssClass($this->options, $cl);
         }
     }
 }
 /**
  * Returns the JS options for the field.
  *
  * @return array the JS options
  */
 protected function getClientOptions()
 {
     $attribute = Html::getAttributeName($this->attribute);
     if (!in_array($attribute, $this->model->activeAttributes(), true)) {
         return [];
     }
     $enableClientValidation = $this->enableClientValidation || $this->enableClientValidation === null && $this->form->enableClientValidation;
     $enableAjaxValidation = $this->enableAjaxValidation || $this->enableAjaxValidation === null && $this->form->enableAjaxValidation;
     if ($enableClientValidation) {
         $validators = [];
         foreach ($this->model->getActiveValidators($attribute) as $validator) {
             /* @var $validator \yii\validators\Validator */
             $js = $validator->clientValidateAttribute($this->model, $attribute, $this->form->getView());
             if ($validator->enableClientValidation && $js != '') {
                 if ($validator->whenClient !== null) {
                     $js = "if (({$validator->whenClient})(attribute, value)) { {$js} }";
                 }
                 $validators[] = $js;
             }
         }
     }
     if (!$enableAjaxValidation && (!$enableClientValidation || empty($validators))) {
         return [];
     }
     $options = [];
     $inputID = Html::getInputId($this->model, $this->attribute);
     $options['id'] = $inputID;
     $options['name'] = $this->attribute;
     $options['container'] = isset($this->selectors['container']) ? $this->selectors['container'] : ".field-{$inputID}";
     $options['input'] = isset($this->selectors['input']) ? $this->selectors['input'] : "#{$inputID}";
     if (isset($this->selectors['error'])) {
         $options['error'] = $this->selectors['error'];
     } elseif (isset($this->errorOptions['class'])) {
         $options['error'] = '.' . implode('.', preg_split('/\\s+/', $this->errorOptions['class'], -1, PREG_SPLIT_NO_EMPTY));
     } else {
         $options['error'] = isset($this->errorOptions['tag']) ? $this->errorOptions['tag'] : 'span';
     }
     $options['encodeError'] = !isset($this->errorOptions['encode']) || $this->errorOptions['encode'];
     if ($enableAjaxValidation) {
         $options['enableAjaxValidation'] = true;
     }
     foreach (['validateOnChange', 'validateOnBlur', 'validateOnType', 'validationDelay'] as $name) {
         $options[$name] = $this->{$name} === null ? $this->form->{$name} : $this->{$name};
     }
     if (!empty($validators)) {
         $options['validate'] = new JsExpression("function (attribute, value, messages, deferred, \$form) {" . implode('', $validators) . '}');
     }
     // only get the options that are different from the default ones (set in yii.activeForm.js)
     return array_diff_assoc($options, ['validateOnChange' => true, 'validateOnBlur' => true, 'validateOnType' => false, 'validationDelay' => 500, 'encodeError' => true, 'error' => '.help-block']);
 }
 /**
  * 渲染checkbox
  * @param $value    元素值
  * @return string   dom元素
  */
 protected function renderContent($value)
 {
     return Html::checkbox($this->name . '[' . $value . ']', in_array($value, $this->values), ['class' => 'icheck', 'data-checkbox' => 'icheckbox_' . $this->style . '-' . $this->color, 'value' => $value]);
 }
 /**
  * @inheritDoc
  */
 protected function renderContent($value)
 {
     return Html::radio($this->name, in_array($value, $this->values), ['class' => 'icheck', 'data-radio' => 'iradio_' . $this->style . '-' . $this->color, 'value' => $value]);
 }
 /**
  * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also
  * configure `panes` accordingly.
  *
  * @param string $itemNumber number of the item
  * @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 InvalidConfigException
  */
 protected function renderDropdown($itemNumber, &$items, &$panes)
 {
     $itemActive = false;
     foreach ($items as $n => &$item) {
         if (is_string($item)) {
             continue;
         }
         if (!array_key_exists('content', $item)) {
             throw new InvalidConfigException("The 'content' option is required.");
         }
         $content = ArrayHelper::remove($item, 'content');
         $options = ArrayHelper::remove($item, 'contentOptions', []);
         Html::addCssClass($options, 'tab-pane');
         if (ArrayHelper::remove($item, 'active')) {
             Html::addCssClass($options, 'active');
             Html::addCssClass($item['options'], 'active');
             $itemActive = true;
         }
         $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd' . $itemNumber . '-tab' . $n);
         $item['url'] = '#' . $options['id'];
         $item['linkOptions']['data-toggle'] = 'tab';
         $panes[] = Html::tag('div', $content, $options);
         unset($item);
     }
     return $itemActive;
 }
 /**
  * Renders menu items.
  *
  * @param array $items the menu items to be rendered
  * @param array $options the container HTML attributes
  * @return string the rendering result.
  * @throws InvalidConfigException if the label option is not specified in one of the items.
  */
 protected function renderItems($items, $options = [])
 {
     $lines = [];
     foreach ($items as $i => $item) {
         if (isset($item['visible']) && !$item['visible']) {
             unset($items[$i]);
             continue;
         }
         if (is_string($item)) {
             $lines[] = $item;
             continue;
         }
         if (!array_key_exists('label', $item)) {
             throw new InvalidConfigException("The 'label' option is required.");
         }
         $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
         $label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
         $itemOptions = ArrayHelper::getValue($item, 'options', []);
         $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
         $linkOptions['tabindex'] = '-1';
         $url = array_key_exists('url', $item) ? $item['url'] : null;
         if (empty($item['items'])) {
             if ($url === null) {
                 $content = $label;
                 Html::addCssClass($itemOptions, 'dropdown-header');
             } else {
                 $content = Html::a($label, $url, $linkOptions);
             }
         } else {
             $submenuOptions = $options;
             unset($submenuOptions['id']);
             $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions);
             Html::addCssClass($itemOptions, 'dropdown-submenu');
         }
         $lines[] = Html::tag('li', $content, $itemOptions);
     }
     return Html::tag('ul', implode("\n", $lines), $options);
 }