1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Encore\Admin\Grid\Column; |
4
|
|
|
|
5
|
|
|
use Encore\Admin\Grid\Column; |
6
|
|
|
use Encore\Admin\Grid\Displayers; |
7
|
|
|
|
8
|
|
|
trait InlineEditing |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param string $selectable |
12
|
|
|
* |
13
|
|
|
* @return $this |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
public function belongsTo($selectable) |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
if (method_exists($selectable, 'display')) { |
18
|
|
|
$this->display($selectable::display()); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
return $this->displayUsing(Displayers\BelongsTo::class, [$selectable]); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $selectable |
26
|
|
|
* |
27
|
|
|
* @return $this |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function belongsToMany($selectable) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
if (method_exists($selectable, 'display')) { |
32
|
|
|
$this->display($selectable::display()); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $this->displayUsing(Displayers\BelongsToMany::class, [$selectable]); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Upload file. |
40
|
|
|
* |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
public function upload() |
44
|
|
|
{ |
45
|
|
|
return $this->displayUsing(Displayers\Upload::class); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Upload many files. |
50
|
|
|
* |
51
|
|
|
* @return $this |
52
|
|
|
*/ |
53
|
|
|
public function uplaodMany() |
54
|
|
|
{ |
55
|
|
|
return $this->displayUsing(Displayers\Upload::class, [true]); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Grid inline datetime picker. |
60
|
|
|
* |
61
|
|
|
* @param string $format |
62
|
|
|
* |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
|
|
public function datetime($format = 'YYYY-MM-DD HH:mm:ss') |
66
|
|
|
{ |
67
|
|
|
return $this->displayUsing(Displayers\Datetime::class, [$format]); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Grid inline date picker. |
72
|
|
|
* |
73
|
|
|
* @param string $format |
|
|
|
|
74
|
|
|
* |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function date() |
78
|
|
|
{ |
79
|
|
|
return $this->datetime('YYYY-MM-DD'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Grid inline time picker. |
84
|
|
|
* |
85
|
|
|
* @param string $format |
|
|
|
|
86
|
|
|
* |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
|
|
public function time() |
90
|
|
|
{ |
91
|
|
|
return $this->datetime('HH:mm:ss'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Grid inline year picker. |
96
|
|
|
* |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function year() |
100
|
|
|
{ |
101
|
|
|
return $this->datetime('YYYY'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Grid inline month picker. |
106
|
|
|
* |
107
|
|
|
* @return $this |
108
|
|
|
*/ |
109
|
|
|
public function month() |
110
|
|
|
{ |
111
|
|
|
return $this->datetime('MM'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Grid inline day picker. |
116
|
|
|
* |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
|
|
public function day() |
120
|
|
|
{ |
121
|
|
|
return $this->datetime('DD'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Grid inline input. |
126
|
|
|
* |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
protected function input($mask = []) |
130
|
|
|
{ |
131
|
|
|
return $this->displayUsing(Displayers\Input::class, [$mask]); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Grid inline text input. |
136
|
|
|
* |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
|
|
public function text() |
140
|
|
|
{ |
141
|
|
|
return $this->input(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Grid inline ip input. |
146
|
|
|
* |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
|
|
public function ip() |
150
|
|
|
{ |
151
|
|
|
return $this->input(['alias' => 'ip']); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Grid inline email input. |
156
|
|
|
* |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function email() |
160
|
|
|
{ |
161
|
|
|
return $this->input(['alias' => 'email']); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Grid inline url input. |
166
|
|
|
* |
167
|
|
|
* @return $this |
168
|
|
|
*/ |
169
|
|
|
public function url() |
170
|
|
|
{ |
171
|
|
|
return $this->input(['alias' => 'url']); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Grid inline currency input. |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function currency() |
180
|
|
|
{ |
181
|
|
|
return $this->input([ |
182
|
|
|
'alias' => 'currency', |
183
|
|
|
'radixPoint' => '.', |
184
|
|
|
'prefix' => '', |
185
|
|
|
'removeMaskOnSubmit' => true, |
186
|
|
|
]); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Grid inline decimal input. |
191
|
|
|
* |
192
|
|
|
* @return $this |
193
|
|
|
*/ |
194
|
|
|
public function decimal() |
195
|
|
|
{ |
196
|
|
|
return $this->input([ |
197
|
|
|
'alias' => 'decimal', |
198
|
|
|
'rightAlign' => true, |
199
|
|
|
]); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Grid inline integer input. |
204
|
|
|
* |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
|
|
public function integer() |
208
|
|
|
{ |
209
|
|
|
return $this->input([ |
210
|
|
|
'alias' => 'integer', |
211
|
|
|
]); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Grid inline textarea. |
216
|
|
|
* |
217
|
|
|
* @param int $rows |
218
|
|
|
* |
219
|
|
|
* @return $this |
220
|
|
|
*/ |
221
|
|
|
public function textarea($rows = 5) |
222
|
|
|
{ |
223
|
|
|
return $this->displayUsing(Displayers\Textarea::class, [$rows]); |
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Grid inline tiemzone select. |
228
|
|
|
* |
229
|
|
|
* @return $this |
230
|
|
|
*/ |
231
|
|
|
public function timezone() |
232
|
|
|
{ |
233
|
|
|
$identifiers = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL); |
234
|
|
|
|
235
|
|
|
$options = collect($identifiers)->mapWithKeys(function ($timezone) { |
236
|
|
|
return [$timezone => $timezone]; |
237
|
|
|
})->toArray(); |
238
|
|
|
|
239
|
|
|
return $this->select($options); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Grid inline select. |
244
|
|
|
* |
245
|
|
|
* @param array $options |
246
|
|
|
* |
247
|
|
|
* @return mixed |
248
|
|
|
*/ |
249
|
|
|
public function select(array $options) |
250
|
|
|
{ |
251
|
|
|
return $this->displayUsing(Displayers\Select::class, [$options]); |
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Grid inline multiple-select input. |
256
|
|
|
* |
257
|
|
|
* @param array $options |
258
|
|
|
* |
259
|
|
|
* @return $this |
260
|
|
|
*/ |
261
|
|
|
public function multipleSelect(array $options) |
262
|
|
|
{ |
263
|
|
|
return $this->displayUsing(Displayers\MultipleSelect::class, [$options]); |
|
|
|
|
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Grid inline checkbox. |
268
|
|
|
* |
269
|
|
|
* @param array $options |
270
|
|
|
* |
271
|
|
|
* @return $this |
272
|
|
|
*/ |
273
|
|
|
public function checkbox(array $options) |
274
|
|
|
{ |
275
|
|
|
return $this->displayUsing(Displayers\Checkbox::class, [$options]); |
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Grid inline checkbox. |
280
|
|
|
* |
281
|
|
|
* @param array $options |
282
|
|
|
* |
283
|
|
|
* @return $this |
284
|
|
|
*/ |
285
|
|
|
public function radio(array $options) |
286
|
|
|
{ |
287
|
|
|
return $this->displayUsing(Displayers\Radio::class, [$options]); |
|
|
|
|
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Grid inline switch. |
292
|
|
|
* |
293
|
|
|
* @param array $states |
294
|
|
|
* |
295
|
|
|
* @return $this |
296
|
|
|
*/ |
297
|
|
|
public function switch(array $states = []) |
298
|
|
|
{ |
299
|
|
|
return $this->displayUsing(Displayers\SwitchDisplay::class, [$states]); |
|
|
|
|
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Grid inline switch group. |
304
|
|
|
* |
305
|
|
|
* @param array $states |
306
|
|
|
* |
307
|
|
|
* @return $this |
308
|
|
|
*/ |
309
|
|
|
public function switchGroup(array $columns = [], array $states = []) |
310
|
|
|
{ |
311
|
|
|
return $this->displayUsing(Displayers\SwitchGroup::class, [$columns, $states]); |
|
|
|
|
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.