|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Encore\Admin\Widgets; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Support\Renderable; |
|
6
|
|
|
use Encore\Admin\Admin; |
|
7
|
|
|
|
|
8
|
|
|
class Box extends Widget implements Renderable |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $view = 'admin::widgets.box'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $title = ''; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $content = 'here is the box content.'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $footer = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $tools = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $script; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Box constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $title |
|
44
|
|
|
* @param string $content |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct($title = '', $content = '', $footer = '') |
|
47
|
|
|
{ |
|
48
|
|
|
if ($title) { |
|
49
|
|
|
$this->title($title); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if ($content) { |
|
53
|
|
|
$this->content($content); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($footer) { |
|
57
|
|
|
$this->footer($footer); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->class('box'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set box content. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $content |
|
67
|
|
|
* |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
public function content($content) |
|
71
|
|
|
{ |
|
72
|
|
|
if ($content instanceof Renderable) { |
|
73
|
|
|
$this->content = $content->render(); |
|
74
|
|
|
} else { |
|
75
|
|
|
$this->content = (string) $content; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set box footer. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $footer |
|
85
|
|
|
* |
|
86
|
|
|
* @return $this |
|
87
|
|
|
*/ |
|
88
|
|
|
public function footer($footer) |
|
89
|
|
|
{ |
|
90
|
|
|
if ($footer instanceof Renderable) { |
|
91
|
|
|
$this->footer = $footer->render(); |
|
92
|
|
|
} else { |
|
93
|
|
|
$this->footer = (string) $footer; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Set box title. |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $title |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
|
|
public function title($title) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->title = $title; |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Set box as collapsable. |
|
115
|
|
|
* |
|
116
|
|
|
* @return $this |
|
117
|
|
|
*/ |
|
118
|
|
|
public function collapsable() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->tools[] = |
|
121
|
|
|
'<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>'; |
|
122
|
|
|
|
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Set box body scrollable |
|
128
|
|
|
* |
|
129
|
|
|
* @param array $options |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
|
|
public function scrollable($options = [], $nodeSelector = '') |
|
133
|
|
|
{ |
|
134
|
|
|
$this->id = uniqid('box-slim-scroll-'); |
|
135
|
|
|
$scrollOptions = json_encode($options); |
|
136
|
|
|
$nodeSelector = $nodeSelector ?: '.box-body'; |
|
137
|
|
|
|
|
138
|
|
|
$this->script = <<<SCRIPT |
|
139
|
|
|
$("#{$this->id} {$nodeSelector}").slimScroll({$scrollOptions}); |
|
140
|
|
|
SCRIPT; |
|
141
|
|
|
|
|
142
|
|
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Set box as removable. |
|
147
|
|
|
* |
|
148
|
|
|
* @return $this |
|
149
|
|
|
*/ |
|
150
|
|
|
public function removable() |
|
151
|
|
|
{ |
|
152
|
|
|
$this->tools[] = |
|
153
|
|
|
'<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>'; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Set box style. |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $styles |
|
162
|
|
|
* |
|
163
|
|
|
* @return $this|Box |
|
164
|
|
|
*/ |
|
165
|
|
|
public function style($styles) |
|
166
|
|
|
{ |
|
167
|
|
|
if (is_string($styles)) { |
|
168
|
|
|
return $this->style([$styles]); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
$styles = array_map(function ($style) { |
|
172
|
|
|
return 'box-'.$style; |
|
173
|
|
|
}, $styles); |
|
174
|
|
|
|
|
175
|
|
|
$this->class = $this->class.' '.implode(' ', $styles); |
|
176
|
|
|
|
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Add `box-solid` class to box. |
|
182
|
|
|
* |
|
183
|
|
|
* @return $this |
|
184
|
|
|
*/ |
|
185
|
|
|
public function solid() |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->style('solid'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Variables in view. |
|
192
|
|
|
* |
|
193
|
|
|
* @return array |
|
194
|
|
|
*/ |
|
195
|
|
|
protected function variables() |
|
196
|
|
|
{ |
|
197
|
|
|
return [ |
|
198
|
|
|
'title' => $this->title, |
|
199
|
|
|
'content' => $this->content, |
|
200
|
|
|
'footer' => $this->footer, |
|
201
|
|
|
'tools' => $this->tools, |
|
202
|
|
|
'attributes' => $this->formatAttributes(), |
|
203
|
|
|
'script' => $this->script, |
|
204
|
|
|
]; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Render box. |
|
209
|
|
|
* |
|
210
|
|
|
* @return string |
|
211
|
|
|
*/ |
|
212
|
|
|
public function render() |
|
213
|
|
|
{ |
|
214
|
|
|
return view($this->view, $this->variables())->render(); |
|
|
|
|
|
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: