1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Encore\Admin\Form\Field; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
6
|
|
|
|
7
|
|
|
class Checkbox extends MultipleSelect |
8
|
|
|
{ |
9
|
|
|
protected $inline = true; |
10
|
|
|
|
11
|
|
|
protected $canCheckAll = false; |
12
|
|
|
|
13
|
|
|
protected $groups = null; |
14
|
|
|
|
15
|
|
|
protected static $css = [ |
16
|
|
|
'/vendor/laravel-admin/AdminLTE/plugins/iCheck/all.css', |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
protected static $js = [ |
20
|
|
|
'/vendor/laravel-admin/AdminLTE/plugins/iCheck/icheck.min.js', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $cascadeEvent = 'ifChanged'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set options. |
30
|
|
|
* |
31
|
|
|
* @param array|callable|string $options |
32
|
|
|
* |
33
|
|
|
* @return $this|mixed |
34
|
|
|
*/ |
35
|
|
|
public function options($options = []) |
36
|
|
|
{ |
37
|
|
|
if ($options instanceof Arrayable) { |
38
|
|
|
$options = $options->toArray(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (is_callable($options)) { |
42
|
|
|
$this->options = $options; |
|
|
|
|
43
|
|
|
} else { |
44
|
|
|
$this->options = (array) $options; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Add a checkbox above this component, so you can select all checkboxes by click on it. |
52
|
|
|
* |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function canCheckAll() |
56
|
|
|
{ |
57
|
|
|
$this->canCheckAll = true; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set chekbox groups. |
64
|
|
|
* |
65
|
|
|
* @param array |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function groups($groups = []) |
70
|
|
|
{ |
71
|
|
|
$this->groups = $groups; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Set checked. |
78
|
|
|
* |
79
|
|
|
* @param array|callable|string $checked |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function checked($checked = []) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
if ($checked instanceof Arrayable) { |
86
|
|
|
$checked = $checked->toArray(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->checked = (array) $checked; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Draw inline checkboxes. |
96
|
|
|
* |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function inline() |
100
|
|
|
{ |
101
|
|
|
$this->inline = true; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Draw stacked checkboxes. |
108
|
|
|
* |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function stacked() |
112
|
|
|
{ |
113
|
|
|
$this->inline = false; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function render() |
122
|
|
|
{ |
123
|
|
|
$this->script = "$('{$this->getElementClassSelector()}').iCheck({checkboxClass:'icheckbox_minimal-blue'});"; |
124
|
|
|
|
125
|
|
|
$this->addVariables([ |
126
|
|
|
'checked' => $this->checked, |
127
|
|
|
'inline' => $this->inline, |
128
|
|
|
'canCheckAll' => $this->canCheckAll, |
129
|
|
|
'groups' => $this->groups, |
130
|
|
|
]); |
131
|
|
|
|
132
|
|
|
if ($this->canCheckAll) { |
133
|
|
|
$checkAllClass = uniqid('check-all-'); |
134
|
|
|
|
135
|
|
|
$this->script .= <<<SCRIPT |
136
|
|
|
$('.{$checkAllClass}').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () { |
137
|
|
|
if (this.checked) { |
138
|
|
|
$('{$this->getElementClassSelector()}').iCheck('check'); |
139
|
|
|
} else { |
140
|
|
|
$('{$this->getElementClassSelector()}').iCheck('uncheck'); |
141
|
|
|
} |
142
|
|
|
}); |
143
|
|
|
SCRIPT; |
144
|
|
|
$this->addVariables(['checkAllClass' => $checkAllClass]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return parent::render(); |
|
|
|
|
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..