|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Display\Column; |
|
4
|
|
|
|
|
5
|
|
|
use SleepingOwl\Admin\Contracts\Display\Extension\ActionInterface; |
|
6
|
|
|
|
|
7
|
|
|
class Action extends NamedColumn implements ActionInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Action icon class. |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $icon; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $style = 'long'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $action; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $method = 'post'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $title; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $view = 'column.action'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var bool |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $orderable = false; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var bool |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $selected = false; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Action constructor. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \Closure|null|string $name |
|
54
|
|
|
* @param string|null $title |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct($name, $title = null) |
|
57
|
|
|
{ |
|
58
|
|
|
parent::__construct($name); |
|
59
|
|
|
|
|
60
|
|
|
$this->setTitle($title); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function initialize() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->setHtmlAttributes([ |
|
66
|
|
|
'class' => 'btn btn-action btn-default', |
|
67
|
|
|
'name' => 'action', |
|
68
|
|
|
'value' => $this->getName(), |
|
69
|
|
|
'data-action' => $this->getAction(), |
|
70
|
|
|
'data-method' => $this->getMethod(), |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getTitle() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->title; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $title |
|
84
|
|
|
* |
|
85
|
|
|
* @return $this |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setTitle($title) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->title = $title; |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return bool |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getSelected() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->selected; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param bool $selected |
|
104
|
|
|
* |
|
105
|
|
|
* @return $this |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setSelected($selected) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->selected = $selected; |
|
110
|
|
|
|
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getAction() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->action; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param string $action |
|
124
|
|
|
* |
|
125
|
|
|
* @return $this |
|
126
|
|
|
*/ |
|
127
|
|
|
public function setAction($action) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->action = $action; |
|
130
|
|
|
|
|
131
|
|
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getMethod() |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->method; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param string $method |
|
144
|
|
|
* |
|
145
|
|
|
* @return $this |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setMethod($method) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->method = $method; |
|
150
|
|
|
|
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return $this |
|
156
|
|
|
*/ |
|
157
|
|
|
public function useGet() |
|
158
|
|
|
{ |
|
159
|
|
|
$this->method = 'get'; |
|
160
|
|
|
|
|
161
|
|
|
return $this; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return $this |
|
166
|
|
|
*/ |
|
167
|
|
|
public function usePost() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->method = 'post'; |
|
170
|
|
|
|
|
171
|
|
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return $this |
|
176
|
|
|
*/ |
|
177
|
|
|
public function usePut() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->method = 'put'; |
|
180
|
|
|
|
|
181
|
|
|
return $this; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return $this |
|
186
|
|
|
*/ |
|
187
|
|
|
public function useDelete() |
|
188
|
|
|
{ |
|
189
|
|
|
$this->method = 'delete'; |
|
190
|
|
|
|
|
191
|
|
|
return $this; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @return string |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getIcon() |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->icon; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @param string $icon |
|
204
|
|
|
* |
|
205
|
|
|
* @return $this |
|
206
|
|
|
*/ |
|
207
|
|
|
public function setIcon($icon) |
|
208
|
|
|
{ |
|
209
|
|
|
$this->icon = $icon; |
|
210
|
|
|
|
|
211
|
|
|
return $this; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return array |
|
216
|
|
|
*/ |
|
217
|
|
|
public function toArray() |
|
218
|
|
|
{ |
|
219
|
|
|
return parent::toArray() + [ |
|
220
|
|
|
'icon' => $this->getIcon(), |
|
221
|
|
|
'action' => $this->getAction(), |
|
222
|
|
|
'method' => $this->getMethod(), |
|
223
|
|
|
'title' => $this->getTitle(), |
|
224
|
|
|
'selected' => $this->getSelected(), |
|
225
|
|
|
]; |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|