1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Form; |
4
|
|
|
|
5
|
|
|
use SleepingOwl\Admin\Form\Panel\Body; |
6
|
|
|
use SleepingOwl\Admin\Form\Element\Html; |
7
|
|
|
use SleepingOwl\Admin\Form\Panel\Footer; |
8
|
|
|
use SleepingOwl\Admin\Form\Panel\Header; |
9
|
|
|
use SleepingOwl\Admin\Traits\PanelControl; |
10
|
|
|
use SleepingOwl\Admin\Contracts\Form\FormElementInterface; |
11
|
|
|
|
12
|
|
|
class FormPanel extends FormDefault |
13
|
|
|
{ |
14
|
|
|
use PanelControl; |
15
|
|
|
|
16
|
|
|
const POSITION_HEADER = 'header'; |
17
|
|
|
const POSITION_BODY = 'body'; |
18
|
|
|
const POSITION_FOOTER = 'footer'; |
19
|
|
|
|
20
|
|
|
const SEPARATOR = '<hr class="panel-wide" />'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $view = 'form.panel'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* FormPanel constructor. |
29
|
|
|
* |
30
|
|
|
* @param array $elements |
31
|
|
|
*/ |
32
|
|
|
public function __construct(array $elements = []) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($elements); |
35
|
|
|
|
36
|
|
|
$this->setPanelClass('panel-form'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Initialize form. |
41
|
|
|
*/ |
42
|
|
|
public function initialize() |
43
|
|
|
{ |
44
|
|
|
$this->getButtons()->setHtmlAttribute('class', 'panel-footer'); |
45
|
|
|
|
46
|
|
|
$this->setHtmlAttribute('class', 'panel panel-default '.$this->getPanelClass()); |
47
|
|
|
|
48
|
|
|
parent::initialize(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param array|FormElementInterface $items |
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function setItems($items) |
57
|
|
|
{ |
58
|
|
|
if (! is_array($items)) { |
59
|
|
|
$items = func_get_args(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->addBody($items); |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param FormElementInterface $item |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function addItem($item) |
73
|
|
|
{ |
74
|
|
|
if ($part = $this->getElements()->last()) { |
75
|
|
|
$part->addElement($item); |
76
|
|
|
} else { |
77
|
|
|
$this->addBody($item); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array|FormElementInterface $items |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
|
|
public function addHeader($items) |
89
|
|
|
{ |
90
|
|
|
if (! is_array($items)) { |
91
|
|
|
$items = func_get_args(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->addElement(new Header($items)); |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array|FormElementInterface $items |
101
|
|
|
* |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
|
|
public function addBody($items) |
105
|
|
|
{ |
106
|
|
|
if (! is_array($items)) { |
107
|
|
|
$items = func_get_args(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$class = $this->getElements()->last(); |
111
|
|
|
if (is_object($class) && get_class($class) === Body::class) { |
112
|
|
|
$this->addElement(new Html('<hr />')); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$this->addElement(new Body($items)); |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param array|FormElementInterface $items |
122
|
|
|
* |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function addFooter($items) |
126
|
|
|
{ |
127
|
|
|
if (! is_array($items)) { |
128
|
|
|
$items = func_get_args(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$this->addElement(new Footer($items)); |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|