diff --git a/src/widgets/ImageSelectInput.php b/src/widgets/AImageSelectInput.php similarity index 100% rename from src/widgets/ImageSelectInput.php rename to src/widgets/AImageSelectInput.php diff --git "a/src/widgets/ImageSelectInpu\341\271\255.php" "b/src/widgets/ImageSelectInpu\341\271\255.php" new file mode 100644 index 0000000..597fd00 --- /dev/null +++ "b/src/widgets/ImageSelectInpu\341\271\255.php" @@ -0,0 +1,73 @@ +fileManagerPathTpl) { + throw new ErrorException('Specify fileManagerPathTpl in bootstrap.php for rahulabs\yii2\imgSelector\ImageSelector'); + } + // иначе начинаем конфигурироваться + if (!array_key_exists('class', $this->options)) { + $this->options['class'] = 'form-control'; + } + $this->options = array_merge($this->options, ['readonly' => true]); + $input = Html::hiddenInput($this->name, $this->value, $this->options); + if ($this->hasModel()) { + $input = Html::activeTextInput($this->model, $this->attribute, $this->options); + } + $url = sprintf($this->fileManagerPathTpl, $this->options['id']); + $selectImgBtn = Html::a('Choose file', $url, [ + 'class' => 'btn iframe-btn btn-dark btn-sm', + 'type' => 'button', + ]); + $removeImgBtn = Html::tag('span', 'Delete file', [ + 'class' => 'btn btn-danger js_RemoveImg btn-sm', + 'type' => 'button', + 'data-img-id' => $this->options['id'], + ]); + $style= ''; + if(!empty($this->options['value'])) { + $style = 'background-image:url("' .WEBSITE_URL. $this->options['value'] . '");'; + } + + if(isset($this->model->{$this->attribute})) { + $style = 'background-image:url("' .WEBSITE_URL.$this->model->{$this->attribute} . '");'; + } + $imgPreview = Html::tag('div', ' ', [ + 'id' => 'preview__' . $this->options['id'], + 'class' => 'imgSelectorPreview', + 'style' => $style + ]); + echo ' +