Esempio n. 1
0
 public function init()
 {
     parent::init();
     $this->emptyText = Html::t('templete', 'noData');
     $this->summary = Html::t('templete', 'summary');
     $this->getView()->registerCssFile('/css/listStyle.css');
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) {
         throw new InvalidConfigException('Invalid layout type: ' . $this->layout);
     }
     if ($this->layout !== 'default') {
         Html::addCssClass($this->options, 'form-' . $this->layout);
     }
     //		BootstrapAsset::register($this->view);
     parent::init();
 }
Esempio n. 3
0
 /**
  * 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']);
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (!$this->requiresPjax()) {
         echo Html::endTag('div');
         $this->registerClientScript();
         return;
     }
     $view = $this->getView();
     $view->endBody();
     // Do not re-send css files as it may override the css files that were loaded after them.
     // This is a temporary fix for https://github.com/yiisoft/yii2/issues/2310
     // It should be removed once pjax supports loading only missing css files
     $view->cssFiles = null;
     $view->endPage(true);
     $content = ob_get_clean();
     // only need the content enclosed within this widget
     $response = Yii::$app->getResponse();
     $response->clearOutputBuffers();
     $response->setStatusCode(200);
     $response->format = Response::FORMAT_HTML;
     $response->content = $content;
     $response->send();
     Yii::$app->end();
 }
Esempio n. 5
0
    /**
     * Run this widget.
     * This method registers necessary javascript and renders the needed HTML code.
     */
    public function run()
    {
        $ret = '<span class="ui-autocomplete-span">';
        //		list($name,$id)=$this->resolveNameID();
        //		$name = Html::getAttributeName($this->attribute);
        $name = Html::getInputName($this->model, $this->attribute);
        $id = 'autocomplete-' . $this->attribute . '-' . self::$counter++;
        $defOptions = array('id' => $id, 'name' => $name, 'autocomplete' => 'off');
        $defClientOptions = array('minLength' => 1, 'delay' => 500, 'autoFocus' => false);
        $this->options = array_merge($defOptions, $this->options);
        $this->clientOptions = array_merge($defClientOptions, $this->clientOptions);
        if ($this->keyValue === true) {
            $inputValue = isset($this->options['value']) ? $this->options['value'] : null;
            $value = Html::getAttributeValue($this->model, $this->attribute);
            $hiddenId = $this->options['id'] . '-value';
            $ret .= Html::hiddenInput($name, $value, ['id' => $hiddenId]);
            if (empty($this->clientEvents['select'])) {
                $this->clientEvents['select'] = <<<Eof
function(event,ui){
\t\$(this).parents(".ui-autocomplete-span").children("input[type='hidden']").val(ui.item.id?ui.item.id:ui.item.value);
}
Eof;
            }
            if (empty($this->clientEvents['change'])) {
                $this->clientEvents['change'] = <<<Eof
function(event,ui){
\tif(ui.item === null)
\t\t\$(this).parents(".ui-autocomplete-span").children("input[type='hidden']").val('');
}
Eof;
            }
            $name2 = 'query[' . $this->model->formName() . '][' . $this->attribute . ']';
            $ret .= Html::textInput($name2, $inputValue, $this->options);
        } else {
            if ($this->hasModel()) {
                //			\THtml::dump($this->options);
                $ret .= Html::activeTextInput($this->model, $this->attribute, $this->options);
            } else {
                $ret .= Html::textInput($name, $this->value, $this->options);
            }
        }
        if ($this->readOnly === TRUE) {
            $ret .= '</span>';
            return $ret;
        }
        if ($this->sourceUrl !== null) {
            $url = $this->sourceUrl;
            $field = isset($this->clientOptions['searchField']) ? $this->clientOptions['searchField'] : $this->attribute;
            if (is_string($url)) {
                $url = array($url, 'field' => $field);
            } elseif (is_array($url)) {
                $url['field'] = $field;
            }
            $this->clientOptions['source'] = Url::to($url);
        } else {
            $this->clientOptions['source'] = $this->source;
        }
        $this->clientOptions['isOpened'] = false;
        if (empty($this->clientEvents['open'])) {
            $this->clientEvents['open'] = <<<Eof
function(event,ui){
\t\$(this).autocomplete( "option", "isOpened",true );
}
Eof;
        }
        if (empty($this->clientEvents['close'])) {
            $this->clientEvents['close'] = <<<Eof
function(event,ui){
\t\$(this).autocomplete( "option", "isOpened",false );
}
Eof;
        }
        if ($this->showDropdown === true) {
            $ret .= '<span class="dropdown"><i class="iconfont small-btn">&#xe651;</i></span>';
            $js = <<<Eof
\$(".ui-autocomplete-span .dropdown").on('click',function(event){
\tvar obj=\$(this).prev();
\tvar isOpened = obj.autocomplete( "option", "isOpened" );
\tif( isOpened ){
\t\tobj.autocomplete( "close");
\t}else{
\t\tif( obj.attr("readonly")==="readonly" )return;
\t\tvar minLength = obj.autocomplete( "option", "minLength" );
\t\tobj.autocomplete( "option", "minLength", 0 );
\t\tobj.autocomplete("search",""); 
\t\tobj.autocomplete( "option", "minLength", minLength );
\t}
});
Eof;
            $this->getView()->registerJs($js);
            //			Yii::app()->getClientScript()->registerScript(__CLASS__,$js);
        }
        $ret .= '</span>';
        //		$clientOptions= Json::encode($this->clientOptions);
        //		$clientOptions=CJavaScript::encode($this->clientOptions);
        //		$this->registerJs(__CLASS__.'#'.$id,"jQuery('#{$id}').autocomplete($clientOptions);");
        $this->registerWidget('autocomplete');
        return $ret;
    }