|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HiPanel core package. |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://hipanel.com/ |
|
6
|
|
|
* @package hipanel-core |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2014-2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hipanel\widgets; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\helpers\ArrayHelper; |
|
14
|
|
|
use hiqdev\assets\autosize\AutosizeAsset; |
|
15
|
|
|
use hiqdev\combo\Combo; |
|
16
|
|
|
use Yii; |
|
17
|
|
|
use yii\helpers\Html; |
|
18
|
|
|
use yii\widgets\ActiveField; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class AdvancedSearchActiveField |
|
22
|
|
|
* |
|
23
|
|
|
* @author Dmytro Naumenko <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class AdvancedSearchActiveField extends ActiveField |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
private $_inputId; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function widget($class, $config = []) |
|
33
|
|
|
{ |
|
34
|
|
|
/* @var $class \yii\base\Widget */ |
|
35
|
|
|
$config['class'] = $class; |
|
36
|
|
|
$config['model'] = $this->model; |
|
37
|
|
|
$config['attribute'] = $this->attribute; |
|
38
|
|
|
$config['view'] = $this->form->getView(); |
|
39
|
|
|
$widget = Yii::createObject($config); |
|
40
|
|
|
|
|
41
|
|
|
if ($widget instanceof Combo) { |
|
42
|
|
|
$this->_inputId = $this->_inputId ?: ($this->getInputId() . '-' . mt_rand()); |
|
43
|
|
|
$widget->inputOptions['id'] = $this->getInputId(); |
|
44
|
|
|
$widget->setPluginOptions([ |
|
45
|
|
|
'select2Options' => [ |
|
46
|
|
|
'placeholder' => $this->model->getAttributeLabel($this->attribute), |
|
47
|
|
|
], |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$this->parts['{input}'] = $widget->run(); |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function textarea($options = []) |
|
57
|
|
|
{ |
|
58
|
|
|
AutosizeAsset::activate($this->form->getView(), '[data-autosize]'); |
|
59
|
|
|
|
|
60
|
|
|
return parent::textarea(ArrayHelper::merge([ |
|
61
|
|
|
'data-autosize' => true, 'rows' => 1, |
|
62
|
|
|
'placeholder' => $this->model->getAttributeLabel('domains'), |
|
63
|
|
|
'style' => ['max-height' => '30vh'] |
|
64
|
|
|
], $options)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
protected function getInputId() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->_inputId ?: parent::getInputId(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Renders the opening tag of the field container. |
|
75
|
|
|
* @return string the rendering result |
|
76
|
|
|
*/ |
|
77
|
|
|
public function begin() |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->form->enableClientScript) { |
|
80
|
|
|
$clientOptions = $this->getClientOptions(); |
|
81
|
|
|
if (!empty($clientOptions)) { |
|
82
|
|
|
$this->form->attributes[] = $clientOptions; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$inputID = $this->getInputId(); |
|
87
|
|
|
$attribute = Html::getAttributeName($this->attribute); |
|
88
|
|
|
$options = $this->options; |
|
89
|
|
|
$class = isset($options['class']) ? [$options['class']] : []; |
|
90
|
|
|
$class[] = "field-$inputID"; |
|
91
|
|
|
if ($this->model->isAttributeRequired($attribute)) { |
|
92
|
|
|
$class[] = $this->form->requiredCssClass; |
|
93
|
|
|
} |
|
94
|
|
|
if ($this->model->hasErrors($attribute)) { |
|
95
|
|
|
$class[] = $this->form->errorCssClass; |
|
96
|
|
|
} |
|
97
|
|
|
$options['class'] = implode(' ', $class); |
|
98
|
|
|
|
|
99
|
|
|
$tag = ArrayHelper::remove($options, 'tag', 'div'); |
|
100
|
|
|
// Added tooltip help |
|
101
|
|
|
$options['data'] = [ |
|
102
|
|
|
'toggle' => 'tooltip', |
|
103
|
|
|
'title' => $this->model->getAttributeLabel($this->attribute), |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
return Html::beginTag($tag, $options); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|