|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Encore\Admin\Form; |
|
4
|
|
|
|
|
5
|
|
|
use Encore\Admin\Admin; |
|
6
|
|
|
use Illuminate\Contracts\Support\Renderable; |
|
7
|
|
|
|
|
8
|
|
|
class Footer implements Renderable |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Footer view. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $view = 'admin::form.footer'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Form builder instance. |
|
19
|
|
|
* |
|
20
|
|
|
* @var Builder |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $builder; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Available buttons. |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $buttons = ['reset', 'submit']; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Available checkboxes. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $checkboxes = ['view', 'continue_editing', 'continue_creating']; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $defaultCheck; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Footer constructor. |
|
45
|
|
|
* |
|
46
|
|
|
* @param Builder $builder |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(Builder $builder) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->builder = $builder; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Disable reset button. |
|
55
|
|
|
* |
|
56
|
|
|
* @return $this |
|
57
|
|
|
*/ |
|
58
|
|
View Code Duplication |
public function disableReset(bool $disable = true) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
if ($disable) { |
|
61
|
|
|
array_delete($this->buttons, 'reset'); |
|
62
|
|
|
} elseif (!in_array('reset', $this->buttons)) { |
|
63
|
|
|
array_push($this->buttons, 'reset'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Disable submit button. |
|
71
|
|
|
* |
|
72
|
|
|
* @return $this |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function disableSubmit(bool $disable = true) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
if ($disable) { |
|
77
|
|
|
array_delete($this->buttons, 'submit'); |
|
78
|
|
|
} elseif (!in_array('submit', $this->buttons)) { |
|
79
|
|
|
array_push($this->buttons, 'submit'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Disable View Checkbox. |
|
87
|
|
|
* |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
View Code Duplication |
public function disableViewCheck(bool $disable = true) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
if ($disable) { |
|
93
|
|
|
array_delete($this->checkboxes, 'view'); |
|
94
|
|
|
} elseif (!in_array('view', $this->checkboxes)) { |
|
95
|
|
|
array_push($this->checkboxes, 'view'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Disable Editing Checkbox. |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
|
View Code Duplication |
public function disableEditingCheck(bool $disable = true) |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
if ($disable) { |
|
109
|
|
|
array_delete($this->checkboxes, 'continue_editing'); |
|
110
|
|
|
} elseif (!in_array('continue_editing', $this->checkboxes)) { |
|
111
|
|
|
array_push($this->checkboxes, 'continue_editing'); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Disable Creating Checkbox. |
|
119
|
|
|
* |
|
120
|
|
|
* @return $this |
|
121
|
|
|
*/ |
|
122
|
|
View Code Duplication |
public function disableCreatingCheck(bool $disable = true) |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
if ($disable) { |
|
125
|
|
|
array_delete($this->checkboxes, 'continue_creating'); |
|
126
|
|
|
} elseif (!in_array('continue_creating', $this->checkboxes)) { |
|
127
|
|
|
array_push($this->checkboxes, 'continue_creating'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set `view` as default check. |
|
135
|
|
|
* |
|
136
|
|
|
* @return $this |
|
137
|
|
|
*/ |
|
138
|
|
|
public function checkView() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->defaultCheck = 'view'; |
|
141
|
|
|
|
|
142
|
|
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Set `continue_creating` as default check. |
|
147
|
|
|
* |
|
148
|
|
|
* @return $this |
|
149
|
|
|
*/ |
|
150
|
|
|
public function checkCreating() |
|
151
|
|
|
{ |
|
152
|
|
|
$this->defaultCheck = 'continue_creating'; |
|
153
|
|
|
|
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Set `continue_editing` as default check. |
|
159
|
|
|
* |
|
160
|
|
|
* @return $this |
|
161
|
|
|
*/ |
|
162
|
|
|
public function checkEditing() |
|
163
|
|
|
{ |
|
164
|
|
|
$this->defaultCheck = 'continue_editing'; |
|
165
|
|
|
|
|
166
|
|
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Setup scripts. |
|
171
|
|
|
*/ |
|
172
|
|
|
protected function setupScript() |
|
173
|
|
|
{ |
|
174
|
|
|
$script = <<<'EOT' |
|
175
|
|
|
$('.after-submit').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChecked', function () { |
|
176
|
|
|
$('.after-submit').not(this).iCheck('uncheck'); |
|
177
|
|
|
}); |
|
178
|
|
|
EOT; |
|
179
|
|
|
|
|
180
|
|
|
Admin::script($script); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Render footer. |
|
185
|
|
|
* |
|
186
|
|
|
* @return string |
|
187
|
|
|
*/ |
|
188
|
|
|
public function render() |
|
189
|
|
|
{ |
|
190
|
|
|
$this->setupScript(); |
|
191
|
|
|
|
|
192
|
|
|
$submitRedirects = [ |
|
193
|
|
|
1 => 'continue_editing', |
|
194
|
|
|
2 => 'continue_creating', |
|
195
|
|
|
3 => 'view', |
|
196
|
|
|
]; |
|
197
|
|
|
|
|
198
|
|
|
$data = [ |
|
199
|
|
|
'width' => $this->builder->getWidth(), |
|
200
|
|
|
'buttons' => $this->buttons, |
|
201
|
|
|
'checkboxes' => $this->checkboxes, |
|
202
|
|
|
'submit_redirects' => $submitRedirects, |
|
203
|
|
|
'default_check' => $this->defaultCheck, |
|
204
|
|
|
]; |
|
205
|
|
|
|
|
206
|
|
|
return view($this->view, $data)->render(); |
|
|
|
|
|
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
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.