Example #1
4
 /**
  * @inheritdoc
  */
 public function run()
 {
     $jsOptions = ['clientOptions' => $this->clientOptions];
     $this->options['id'] = 'input-id';
     if ($this->hasModel()) {
         echo Html::activeInput('file', $this->model, $this->attribute, $this->options);
         echo Html::img('#', ['id' => 'cropper-box']);
         echo Html::button('Crop', ['id' => 'cropImage']);
         $input_name = Html::getInputName($this->model, $this->attribute);
         $input_id = Html::getInputId($this->model, $this->attribute);
         echo Html::hiddenInput($input_name . '[file]', '', ['id' => $input_id . '_image']);
         $jsOptions['model'] = $this->model;
         $jsOptions['attribute'] = $this->attribute;
     } else {
         echo Html::fileInput($this->name, $this->value, $this->options);
         echo Html::img('#', ['id' => 'cropper-box']);
         echo Html::button('Crop', ['id' => 'cropImage']);
     }
     if ($this->uploadUrl) {
         $this->uploadUrl = \Yii::getAlias($this->uploadUrl);
     }
     $jsOptions['uploadUrl'] = $this->uploadUrl;
     $jsOptions['uploadCroppedUrl'] = $this->uploadCroppedUrl;
     $jsOptions['changeUrl'] = $this->changeUrl;
     $jsOptions['name'] = $this->name;
     $jsOptions['aspectRatio'] = $this->aspectRatio;
     $this->registerPlugin($jsOptions);
 }
Example #2
1
 /**
  * 
  * @param \yii\db\ActiveRecord $model
  * @param integer $index
  * @return type
  */
 protected function renderInput($model, $index)
 {
     if ($this->inputOptions instanceof \Closure) {
         $options = call_user_func($this->inputOptions, $model, $index);
     } else {
         $options = $this->inputOptions;
     }
     $options['data-attribute'] = $this->attribute;
     if ($this->_isList) {
         if ($this->inputItems instanceof \Closure) {
             $items = call_user_func($this->inputItems, $model, $index);
         } else {
             $items = $this->inputItems;
         }
         if ($model->hasAttribute($this->attribute)) {
             return call_user_func(['yii\\helpers\\Html', 'active' . $this->inputType], $model, "[{$index}]{$this->attribute}", $items, $options);
         } else {
             $name = Html::getInputName($model, "[{$index}]{$this->attribute}");
             $value = ArrayHelper::remove($options, 'value');
             return call_user_func(['yii\\helpers\\Html', $this->inputType], $name, $value, $items, $options);
         }
     } else {
         if ($model->hasAttribute($this->attribute)) {
             return call_user_func(['yii\\helpers\\Html', 'active' . $this->inputType], $model, "[{$index}]{$this->attribute}", $options);
         } else {
             $name = Html::getInputName($model, "[{$index}]{$this->attribute}");
             $value = ArrayHelper::remove($options, 'value');
             return call_user_func(['yii\\helpers\\Html', $this->inputType], $name, $value, $options);
         }
     }
 }
 public function run()
 {
     if ($this->model === null) {
         $inputId = $this->getId();
     } else {
         if ($this->getId(false) === null) {
             $inputId = Html::getInputId($this->model, $this->attribute);
             $this->setId($inputId);
         } else {
             $inputId = $this->getId();
         }
     }
     $widgetId = $inputId . '-map';
     if ($this->name === null) {
         $inputName = $this->model === null ? null : Html::getInputName($this->model, $this->attribute);
     } else {
         $inputName = $this->name;
     }
     if ($this->enableSearchBox === true) {
         $this->_renderSearchBox();
     }
     // render attribute as hidden input
     if ($this->model === null) {
         echo Html::hiddenInput($inputName, $this->value, ['id' => $inputId, 'name' => $inputName]);
     } else {
         echo Html::activeHiddenInput($this->model, $this->attribute, ['id' => $inputId, 'name' => $inputName]);
     }
     $this->_registerOnChangedEvent($this->id);
     $this->_registerOnInitializedEvent();
     $this->_setClientLocation();
     $widgetOptions = $this->options;
     unset($widgetOptions['id']);
     echo LocationPickerWidget::widget(['id' => $widgetId, 'key' => $this->key, 'options' => $widgetOptions, 'clientOptions' => $this->clientOptions, 'clientEvents' => $this->clientEvents]);
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     Asset::register($this->view);
     $inputId = Html::getInputId($this->model, $this->attribute);
     $field = $this->render('_field', ['fieldClass' => 'field-' . $inputId, 'inputId' => $inputId, 'inputName' => Html::getInputName($this->model, $this->attribute) . '[]', 'inputLabel' => $this->model->getAttributeLabel($this->attribute)]);
     $options = Json::htmlEncode(['field' => $field, 'firstAddTogglerText' => 'добавить свою категорию', 'addTogglerText' => 'добавить ещё', 'values' => $this->model->{$this->attribute}]);
     $this->view->registerJs('jQuery("#' . $this->id . '").kategoriiSlushatelejInputFields(' . $options . ');');
     return Html::tag('div', $this->renderFirstToggler(), ['id' => $this->id, 'class' => 'kategorii-slushatelej-input-fields']);
 }
 /**
  * @return EmbeddedDocument
  */
 public function getStorage()
 {
     if (empty($this->_storage)) {
         $this->_storage = $this->createEmbedded((array) $this->owner->{$this->attribute}, false, ['formName' => $this->setFormName ? Html::getInputName($this->owner, $this->fakeAttribute) : null]);
     }
     return $this->_storage;
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     if ($this->hasModel()) {
         $name = Html::getInputName($this->model, $this->attribute);
         $value = null;
         if (is_array($this->model->{$this->attribute})) {
             $value = StringHelper::base64EncodeUrl(serialize((array) $this->model->{$this->attribute}));
         } else {
             if (is_string($this->model->{$this->attribute})) {
                 $value = $this->model->{$this->attribute};
             }
         }
         $this->options['id'] = Html::getInputId($this->model, $this->attribute);
         //$element = Html::activeHiddenInput($this->model, $this->attribute, $this->options);
         $element = Html::hiddenInput($name, $value, $this->options);
     } else {
         $element = Html::hiddenInput($this->name, $this->value, $this->options);
     }
     $this->registerPlugin();
     $this->clientOptions['componentSelectId'] = $this->componentSelectId;
     $this->clientOptions['componentSettingsId'] = Html::getInputId($this->model, $this->attribute);
     $this->clientOptions['id'] = $this->id;
     $this->clientOptions['backend'] = UrlHelper::construct('/cms/admin-universal-component-settings/index')->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->enableAdmin()->toString();
     return $this->render('element', ['widget' => $this, 'element' => $element]);
 }
Example #7
0
 public function run()
 {
     if (empty($this->name) && (!empty($this->model) && !empty($this->attribute))) {
         $this->name = Html::getInputName($this->model, $this->attribute);
     }
     if (empty($this->url)) {
         $this->url = Url::toRoute(['site/upload']);
     }
     $options = ['url' => $this->url, 'paramName' => $this->name, 'params' => []];
     if (Yii::$app->request->enableCsrfValidation) {
         $options['params'][Yii::$app->request->csrfParam] = Yii::$app->request->getCsrfToken();
     }
     if (!empty($this->message)) {
         $message = Html::tag('div', $this->message, $this->messageOptions);
     } else {
         $message = '';
     }
     $this->htmlOptions['id'] = $this->id;
     $this->options = ArrayHelper::merge($this->options, $options);
     echo Html::tag('div', $message, $this->htmlOptions);
     $this->registerAssets();
     $this->createDropzone();
     foreach ($this->eventHandlers as $event => $handler) {
         $handler = new \yii\web\JsExpression($handler);
         $this->getView()->registerJs($this->dropzoneName . ".on('{$event}', {$handler})");
     }
     $this->addFiles($this->storedFiles);
     $this->decrementMaxFiles(count($this->storedFiles));
     if ($this->sortable) {
         $options = Json::encode($this->sortableOptions);
         $this->getView()->registerJs("jQuery('#{$this->id}').sortable(" . $options . ");");
     }
 }
Example #8
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $this->clientOptions = array_merge_recursive(self::$defaultSettings, $this->clientOptions);
     $this->clientOptions['extended_valid_elements'] = implode(',', $this->clientOptions['extended_valid_elements']);
     if ($this->hasModel()) {
         $this->options['name'] = isset($this->options['name']) ? $this->options['name'] : Html::getInputName($this->model, $this->attribute);
         if (isset($this->options['value'])) {
             $value = $this->options['value'];
             unset($this->options['value']);
         } else {
             $value = Html::getAttributeValue($this->model, $this->attribute);
         }
         if (!array_key_exists('id', $this->options)) {
             $this->options['id'] = Html::getInputId($this->model, $this->attribute);
         }
     } else {
         $options['name'] = $this->name;
         $value = $this->value;
     }
     if (!isset($this->options['class'])) {
         $this->options['class'] = 'tinymce';
     }
     echo Html::tag('div', $value, $this->options);
     $this->registerClientScript();
 }
Example #9
0
 public function run()
 {
     if ($this->hasModel()) {
         $replace['{input}'] = Html::activeHiddenInput($this->model, $this->attribute, $this->options);
         $attributeId = Html::getInputId($this->model, $this->attribute);
         $id = Html::getInputId($this->model, 'hydra_' . $this->attribute);
         $name = Html::getInputName($this->model, 'hydra_' . $this->attribute);
         $this->value = $this->model[$this->attribute];
     } else {
         $replace['{input}'] = Html::hiddenInput($this->name, $this->value, $this->options);
         $name = $id = 'hydra_' . $this->name;
         $attributeId = $this->name;
     }
     $fileInputName = empty($this->fileInputName) ? $name : $this->fileInputName;
     $replace['{preview}'] = 'Файл еще не загружен';
     if (!empty($this->value)) {
         $replace['{preview}'] = $this->value;
         $extension = Yii::$app->hydra->getExtension($this->value);
         if (Yii::$app->hydra->isImage($extension)) {
             $replace['{preview}'] = Html::img(Yii::$app->hydra->getCacheUrl($this->value, $this->resolution), ['id' => $id . '_image']);
         }
         $replace['{reset-button}'] = Html::tag($this->resetButton['tag'], $this->resetButton['label'], ArrayHelper::merge(['onClick' => '$("#' . $attributeId . '").val("");$("#' . $id . '_image' . '").remove();$(this).remove();'], $this->resetButton['options']));
     }
     $replace['{input}'] .= Html::fileInput($fileInputName, null, ArrayHelper::merge(['id' => $id], $this->fileInput['options']));
     return strtr($this->template, $replace);
 }
 /**
  * @inheritdoc
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     if (isset($this->htmlOptions['class'])) {
         $this->htmlOptions['class'] .= 'editableCell form-control';
     } else {
         $this->htmlOptions['class'] = 'editableCell form-control';
     }
     // We need to number the submit attributes because data attribute is not case sensitive
     $this->htmlOptions['data-submit-attributes'] = implode(',', $this->submitAttributes);
     $i = 0;
     foreach ($this->submitAttributes as $attribute) {
         $this->htmlOptions['data-attribute' . $i] = $model[$attribute];
         $i++;
     }
     $options = [];
     if (is_array($this->dropDownOptions)) {
         $options = $this->dropDownOptions;
     } else {
         $options = $model[$this->dropDownOptions];
     }
     $inputName = is_array($model) ? $this->attribute : Html::getInputName($model, $this->attribute);
     $readonly = $this->readonly;
     if (!is_bool($readonly)) {
         $readonly = call_user_func($this->readonly, $model, $key, $index, $this);
     }
     if ($readonly) {
         if (isset($options[$model[$this->attribute]])) {
             return $options[$model[$this->attribute]];
         }
         return $model[$this->attribute];
     }
     return Html::dropDownList($inputName, $model[$this->attribute], $options, $this->htmlOptions);
 }
Example #11
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     if (empty($this->id)) {
         $this->id = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
     }
     if (empty($this->name)) {
         $this->name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->id;
     }
     if (empty($this->value) && $this->hasModel() && $this->model->hasAttribute($this->attribute)) {
         $this->value = $this->model->getAttribute($this->attribute);
     }
     if (!$this->autoHeightEnable) {
         if (empty($this->width)) {
             $this->width = '100%';
         }
         if (empty($this->height)) {
             $this->height = '350';
         }
     }
     $options = ['id' => $this->id, 'style' => 'width:100%;height:350px'];
     $this->options = array_merge($options, $this->options);
     $jsOptions = ['serverUrl' => Url::to(['ueditor', 'type' => 'ueditor']), 'autoHeightEnable' => $this->autoHeightEnable, 'autoFloatEnable' => true, 'textarea' => $this->name];
     $this->jsOptions = array_merge($jsOptions, $this->jsOptions);
 }
 /**
  *
  */
 public function init()
 {
     if (empty($this->parentName)) {
         throw new InvalidParamException('RelativeSelect2 $parentName must be set!');
     }
     if (empty($this->url)) {
         throw new InvalidParamException('RelativeSelect2 $url must be set!');
     }
     if ($this->parentModel instanceof Model) {
         $this->options['data']['select2-parent-name'] = Html::getInputName($this->parentModel, $this->parentName);
     } else {
         $this->options['data']['select2-parent-name'] = $this->hasModel() ? Html::getInputName($this->model, $this->parentName) : $this->parentName;
     }
     if (is_array($this->url)) {
         $this->url = Url::to($this->url);
     }
     $this->options['data']['select2-url'] = $this->url;
     if (!empty($this->model) && isset($this->model->{$this->attribute})) {
         if (is_array($this->model->{$this->attribute})) {
             $this->options['data']['select2-selected-items'] = implode(',', $this->model->{$this->attribute});
         } else {
             $this->options['data']['select2-selected-items'] = $this->model->{$this->attribute};
         }
     } else {
         $this->options['data']['select2-selected-items'] = $this->value;
     }
     parent::init();
     RelativeSelect2Asset::register($this->getView());
 }
Example #13
0
 public function run()
 {
     $id = $this->options['id'];
     $options = Json::htmlEncode($this->getClientOptions());
     $view = $this->getView();
     EditorGridViewAsset::register($view);
     $view->registerJs("jQuery('#{$id}').yiiGridView({$options});\$(document).off('change.yiiGridView keydown.yiiGridView');");
     if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) {
         $content = preg_replace_callback("/{\\w+}/", function ($matches) {
             $content = $this->renderSection($matches[0]);
             return $content === false ? $matches[0] : $content;
         }, $this->layout);
     } else {
         $content = $this->renderEmpty();
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     echo Html::tag($tag, $content, $options);
     foreach ($this->columns as $column) {
         if (isset($column->attribute) && $column->editable) {
             $models = $this->dataProvider->getModels();
             if (($model = reset($models)) instanceof Model) {
                 $name = Html::getInputName($model, $column->attribute);
             } else {
                 $name = $column->attribute;
             }
             $attributeName = $column->attribute;
             $view->registerJs("\$('.{$attributeName}').editable({\n                    placement:'right',\n                    ajaxOptions: {\n                        type: 'GET',\n                        dataType: 'json'\n                    },\n                    success: function(response, newValue) {\n                        if(response.status=='success')\n                        {\n                            return jQuery('#{$this->options['id']}').yiiGridView('applyFilter');\n                        }\n                        else\n                        {\n                            return response.msg;\n                        }\n                    },\n                    params: function(rawParams) {\n                        var params = {};\n                        params['{$name}']=rawParams.value;\n                        params['pk']=rawParams.pk;\n                        return params;\n                    }\n                });");
         }
     }
 }
Example #14
0
 public function init()
 {
     if (empty($this->name)) {
         $this->name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->id;
     }
     if (empty($this->url)) {
         $this->url = Url::to(['index/upload']);
     }
     if (empty($this->id)) {
         $this->id = 'filePicker';
     }
     if (empty($this->template)) {
         $this->template = '<div id="' . $this->id . '">选择图片</div>';
     }
     $this->jsOptions['auto'] = isset($this->jsOptions['auto']) ? $this->jsOptions['auto'] : 'true';
     $this->jsOptions['swf'] = "'./asset/js/Uploader.swf'";
     $this->jsOptions['server'] = "'{$this->url}'";
     $this->jsOptions['pick'] = "{id:'#{$this->id}',multiple:false}";
     // $this->jsOptions['accept'] = "{
     // 					        title: 'Images',
     // 					        extensions: 'png,jpg,gif,doc,docx,xls,xlsx,pdf,txt',
     // 					        mimeTypes: 'application/zip,application/vnd.ms-excel,application/vnd.ms-powerpoint,image/*' +
     // 					            ',application/vnd.openxmlformats-officedocument.presentationml.presentation' +
     // 					            ',application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword' +
     // 					            ',application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/plain,application/x-rar-compressed'}";
     parent::init();
 }
Example #15
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->registerMessages();
     if ($this->maxNumberOfFiles > 1 || $this->multiple) {
         $this->multiple = true;
     }
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!array_key_exists('name', $this->clientOptions)) {
         $this->clientOptions['name'] = $this->name;
     }
     if ($this->multiple && $this->value && !is_array($this->value)) {
         throw new InvalidParamException('In "multiple" mode, value must be an array.');
     }
     if (!array_key_exists('fileparam', $this->url)) {
         $this->url['fileparam'] = $this->getFileInputName();
     }
     if (!$this->files && $this->value) {
         $this->files = $this->multiple ? $this->value : [$this->value];
     }
     if ($this->files) {
         foreach ($this->files as &$file) {
             if (!isset($file['alias_url']) && is_array($file)) {
                 $option = isset($this->clientOptions['baseUrlAttribute']) ? $this->clientOptions['baseUrlAttribute'] : null;
                 $file['alias_url'] = $option ? isset($file[$option]) ? Yii::getAlias($file[$option]) : null : null;
             }
         }
     }
     $this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'showPreviewFilename' => $this->showPreviewFilename, 'pathAttribute' => 'path', 'baseUrlAttribute' => 'base_url', 'pathAttributeName' => 'path', 'baseUrlAttributeName' => 'base_url', 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small')]], $this->clientOptions);
 }
Example #16
0
 /**
  * @return string
  */
 public function run()
 {
     $this->registerClientScript();
     $attributeValue = $this->model->{$this->attribute};
     $file = File::findOne(['fid' => $attributeValue]);
     return $this->renderFile(dirname(__FILE__) . '/views/widget.php', ['id' => $this->options['id'], 'name' => Html::getInputName($this->model, $this->attribute), 'fileInputId' => $this->id, 'fileInputName' => "_fileinput_" . $this->id, 'fid' => $attributeValue, 'url' => isset($file) ? $file->url : null, 'uploadUrl' => $this->uploadUrl, 'deleteUrl' => $this->deleteUrl]);
 }
Example #17
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->registerMessages();
     if ($this->maxNumberOfFiles > 1) {
         $this->multiple = true;
     }
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!array_key_exists('name', $this->clientOptions)) {
         $this->clientOptions['name'] = $this->name;
     }
     if ($this->multiple && $this->value && !is_array($this->value)) {
         throw new InvalidParamException('In "multiple" mode, value must be an array.');
     }
     if (!array_key_exists('fileparam', $this->url)) {
         $this->url['fileparam'] = $this->getFileInputName();
     }
     if (!$this->files && $this->value) {
         $this->files = $this->multiple ? $this->value : [$this->value];
     }
     $this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded', [], 'en'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed', [], 'en'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large', [], 'en'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small', [], 'en')]], $this->clientOptions);
 }
 /**
  * @inheritdoc
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     $attribute = $this->attribute;
     $name = Html::getInputName($model, $attribute);
     $value = $model->{$attribute};
     $options = ArrayHelper::merge(['class' => $this->classPrefix . '-' . $attribute, 'data-id' => $key], $this->options);
     return Html::dropDownList($name, $value, $model::$enum_category, $options);
 }
 public function init()
 {
     parent::init();
     if (!isset($this->inputId)) {
         $this->inputId = isset($this->model) ? Html::getInputId($this->model, $this->attribute) : $this->getId() . '-input';
         $this->inputName = isset($this->model) ? Html::getInputName($this->model, $this->attribute) : $this->getId() . '-name';
     }
 }
 public function getFormName($index)
 {
     if ($this->setFormName) {
         return Html::getInputName($this->owner, $this->fakeAttribute . "[{$index}]");
     } else {
         return null;
     }
 }
Example #21
0
 public function init()
 {
     if (!isset($this->options['class']) or empty($this->options['class'])) {
         $this->options['class'] = 'form-control m-b-xs';
     }
     $this->options['onkeydown'] = 'addItemWhenPressKey(event);';
     $this->inputName = Html::getInputName($this->model, $this->attribute);
     $this->registerAssets();
 }
Example #22
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     if ($this->hasModel()) {
         $this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : $this->options['name'];
         $this->value = Html::getAttributeValue($this->model, $this->attribute);
     }
     echo Html::tag('div', '', $this->options);
     $this->registerClientScript();
 }
Example #23
0
 public function run()
 {
     $view = $this->getView();
     FileUploadAsset::register($view);
     $this->createUploaderOptions();
     $this->options['class'] = 'required';
     echo Html::hiddenInput(Html::getInputName($this->model, $this->attribute), '', ['id' => 'dwz-file-uploader']);
     echo Html::activeInput('file', $this->model, $this->attribute, $this->options);
 }
Example #24
0
 /**
  * Загружает файлы
  * @param string $model клысс модели
  * @param string $attr атрибут модели
  * @return string
  */
 public function run($model, $attr)
 {
     $item = Yii::createObject($model);
     $name = Html::getInputName($item, $attr);
     $files = $item->uploadFiles($name);
     $res = array_shift($files);
     Yii::$app->getResponse()->setStatusCode(200);
     return $res;
 }
Example #25
0
 /**
  * Configure client options
  *
  * @return void
  */
 protected function configureClientOptions()
 {
     $assetBundle = StarRatingAsset::register($this->view);
     $this->clientOptions['score'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
     $this->clientOptions['path'] = $assetBundle->baseUrl . self::IMAGE_PATH;
     if (!isset($this->clientOptions['scoreName']) && $this->hasModel()) {
         $this->clientOptions['scoreName'] = Html::getInputName($this->model, $this->attribute);
     }
 }
 protected function getFileInputName()
 {
     if ($this->hasModel()) {
         $name = preg_replace('[\\[|\\]]', '-', Html::getInputName($this->model, $this->attribute));
     } else {
         $name = $this->name;
     }
     return '_file_' . $name;
 }
Example #27
0
 /**
  * @return string input name
  */
 public function getInputName()
 {
     if ($this->hasModel()) {
         $inputName = Html::getInputName($this->model, $this->attribute);
         $inputName .= $this->multiple ? '[]' : '';
         return $inputName;
     } else {
         return $this->name;
     }
 }
 public function init()
 {
     if (!isset($this->htmlOptions['id'])) {
         $this->htmlOptions['id'] = $this->getId();
     }
     if (!isset($this->htmlOptions['name'])) {
         $this->htmlOptions['name'] = Html::getInputName($this->model, $this->attribute);
     }
     parent::init();
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     // Generate an selector which will be used by jQuery
     if (isset($this->options['id'])) {
         $this->_selector = '#' . $this->options['id'];
     } elseif (!isset($this->options['data-tokenfield-id'])) {
         $id = uniqid('tokenfield_');
         $this->options['data-tokenfield-id'] = $id;
         $this->_selector = "[data-tokenfield-id={$id}]";
     }
     // Input
     if ($this->hasModel()) {
         // If overwriting the model value
         if ($this->overwriteValue && $this->value) {
             $name = Html::getInputName($this->model, $this->attribute);
             $val = is_array($this->value) ? implode(', ', $this->value) : $this->value;
             echo Html::textInput($name, $val, $this->options);
             // If normal model
         } else {
             echo Html::activeTextInput($this->model, $this->attribute, $this->options);
         }
         // Not active record
     } else {
         $val = is_array($this->value) ? implode(', ', $this->value) : $this->value;
         echo Html::textInput($this->name, $val, $this->options);
     }
     // Register the bootstrap-tokenfield script
     $this->registerClientScript();
 }
 public function init()
 {
     if ($this->name === null && !$this->hasModel() && $this->selector === null) {
         throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
     }
     if (null === $this->schema) {
         throw new InvalidConfigException("You must specify 'schema' property.");
     }
     if ($this->hasModel() && !isset($this->options['id'])) {
         $this->options['id'] = Html::getInputId($this->model, $this->attribute);
     }
     if ($this->hasModel()) {
         $this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : $this->options['name'];
         $this->value = Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!isset($this->containerOptions['id'])) {
         $this->containerOptions['id'] = ($this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId()) . '-container';
     }
     if ($this->inputId === null) {
         $this->inputId = $this->options['id'];
     } else {
         $this->_renderInput = false;
     }
     parent::init();
     JsonEditorAsset::register($this->getView());
 }