public function run() { if ($this->hasModel()) { $replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $replace['{input}'] = Html::textInput($this->name, $this->value, $this->options); } $this->buttonOptions = array_merge($this->buttonOptions, ['class' => 'btn btn-default add-file', 'type' => 'button']); $replace['{button}'] = Html::tag('span', Html::tag('button', Html::tag('i', '', ['class' => 'fa fa-file-image-o']), $this->buttonOptions), ['class' => 'input-group-btn']); echo strtr($this->template, $replace); AssetsCallBack::register($this->getView()); if (!empty($this->multiple)) { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(files, id){ var _f = []; for (var i in files) { _f.push(files[i].url); } \$('#' + id).val(_f.join(', ')).trigger('change', [files, id]); return true;}); \$(document).on('click','#" . $this->buttonOptions['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } else { $this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){ \$('#' + id).val(file.url).trigger('change', [file, id]);; return true;}); \$(document).on('click', '#" . $this->buttonOptions['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});"); } }
/** * @inheritdoc */ protected function renderItem($item) { $item['badgeOptions'] = isset($item['badgeOptions']) ? $item['badgeOptions'] : []; if (!ArrayHelper::getValue($item, 'badgeOptions.class')) { $bg = isset($item['badgeBgClass']) ? $item['badgeBgClass'] : $this->badgeBgClass; $item['badgeOptions']['class'] = $this->badgeClass . ' ' . $bg; } if (isset($item['items']) && !isset($item['right-icon'])) { $item['right-icon'] = $this->parentRightIcon; } if (isset($item['url'])) { $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); return strtr($template, ['{badge}' => isset($item['badge']) && $item['badge'] > 0 ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', '{icon}' => isset($item['icon']) ? $item['icon'] : '', '{right-icon}' => isset($item['right-icon']) ? $item['right-icon'] : '', '{url}' => Url::to($item['url']), '{label}' => $item['label']]); } else { $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); return strtr($template, ['{badge}' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', '{icon}' => isset($item['icon']) ? $item['icon'] : '', '{right-icon}' => isset($item['right-icon']) ? $item['right-icon'] : '', '{label}' => $item['label']]); } }