1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Library\CrudPanel\Traits; |
4
|
|
|
|
5
|
|
|
trait Tabs |
6
|
|
|
{ |
7
|
|
|
public function enableTabs() |
8
|
|
|
{ |
9
|
|
|
$this->setOperationSetting('tabsEnabled', true); |
|
|
|
|
10
|
|
|
$this->setOperationSetting('tabsType', config('backpack.crud.' . $this->getCurrentOperation() . '.tabsType', 'horizontal')); |
|
|
|
|
11
|
|
|
|
12
|
|
|
return $this->tabsEnabled(); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function disableTabs() |
16
|
|
|
{ |
17
|
|
|
$this->setOperationSetting('tabsEnabled', false); |
18
|
|
|
|
19
|
|
|
return $this->tabsEnabled(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return bool |
24
|
|
|
*/ |
25
|
|
|
public function tabsEnabled() |
26
|
|
|
{ |
27
|
|
|
return $this->getOperationSetting('tabsEnabled'); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
|
|
public function tabsDisabled() |
34
|
|
|
{ |
35
|
|
|
return !$this->tabsEnabled(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function setTabsType($type) |
39
|
|
|
{ |
40
|
|
|
$this->enableTabs(); |
41
|
|
|
$this->setOperationSetting('tabsType', $type); |
42
|
|
|
|
43
|
|
|
return $this->getOperationSetting('tabsType'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getTabsType() |
50
|
|
|
{ |
51
|
|
|
return $this->getOperationSetting('tabsType'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function enableVerticalTabs() |
55
|
|
|
{ |
56
|
|
|
return $this->setTabsType('vertical'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function disableVerticalTabs() |
60
|
|
|
{ |
61
|
|
|
return $this->setTabsType('horizontal'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function enableHorizontalTabs() |
65
|
|
|
{ |
66
|
|
|
return $this->setTabsType('horizontal'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function disableHorizontalTabs() |
70
|
|
|
{ |
71
|
|
|
return $this->setTabsType('vertical'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $label |
76
|
|
|
* |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public function tabExists($label) |
80
|
|
|
{ |
81
|
|
|
$tabs = $this->getTabs(); |
82
|
|
|
|
83
|
|
|
return in_array($label, $tabs); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return bool|string |
88
|
|
|
*/ |
89
|
|
|
public function getLastTab() |
90
|
|
|
{ |
91
|
|
|
$tabs = $this->getTabs(); |
92
|
|
|
|
93
|
|
|
if (count($tabs)) { |
94
|
|
|
return last($tabs); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param $label |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isLastTab($label) |
106
|
|
|
{ |
107
|
|
|
return $this->getLastTab() == $label; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return \Illuminate\Support\Collection |
112
|
|
|
*/ |
113
|
|
|
public function getFieldsWithoutATab() |
114
|
|
|
{ |
115
|
|
|
$all_fields = $this->getOperationFields(); |
116
|
|
|
|
117
|
|
|
$fields_without_a_tab = collect($all_fields)->filter(function ($value, $key) { |
|
|
|
|
118
|
|
|
return !isset($value['tab']); |
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
return $fields_without_a_tab; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param $label |
126
|
|
|
* |
127
|
|
|
* @return array|\Illuminate\Support\Collection |
128
|
|
|
*/ |
129
|
|
|
public function getTabFields($label) |
130
|
|
|
{ |
131
|
|
|
if ($this->tabExists($label)) { |
132
|
|
|
$all_fields = $this->getOperationFields(); |
133
|
|
|
|
134
|
|
|
$fields_for_current_tab = collect($all_fields)->filter(function ($value, $key) use ($label) { |
|
|
|
|
135
|
|
|
return isset($value['tab']) && $value['tab'] == $label; |
136
|
|
|
}); |
137
|
|
|
|
138
|
|
|
return $fields_for_current_tab; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return []; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
|
public function getTabs() |
148
|
|
|
{ |
149
|
|
|
$tabs = []; |
150
|
|
|
$fields = $this->getOperationFields(); |
151
|
|
|
|
152
|
|
|
$fields_with_tabs = collect($fields) |
|
|
|
|
153
|
|
|
->filter(function ($value, $key) { |
|
|
|
|
154
|
|
|
return isset($value['tab']); |
155
|
|
|
}) |
156
|
|
|
->each(function ($value, $key) use (&$tabs) { |
|
|
|
|
157
|
|
|
if (!in_array($value['tab'], $tabs)) { |
158
|
|
|
$tabs[] = $value['tab']; |
159
|
|
|
} |
160
|
|
|
}); |
161
|
|
|
|
162
|
|
|
return $tabs; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return mixed |
167
|
|
|
*/ |
168
|
|
|
public function getOperationFields() |
169
|
|
|
{ |
170
|
|
|
if ($this->getCurrentOperation() == "show") { |
171
|
|
|
return $this->columns(); |
|
|
|
|
172
|
|
|
} else { |
173
|
|
|
return $this->getCurrentFields(); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|