1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
<?php
class Vipanel_Form extends Zend_Form
{
public $element_decorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element')),
'Label',
array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'container'))
);
public $button_decorators = array(
'ViewHelper'
);
public $button_group_decorators = array(
'FormElements',
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element buttons')),
array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'container')),
);
public $display_group_decorators = array(
'FormElements',
array(array('group' => 'HtmlTag'), array('tag' => 'div', 'class' => 'display-group')),
);
public $subform_decorators = array(
'FormElements',
'Fieldset'
);
public $form_decorators = array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'vipanel-form')),
'Form',
);
private $__button_group_for = array(
'submit', 'reset', 'button', 'image'
);
private $__button_group_id = 'buttons';
protected $_element_groups = array(
'button' => array('image', 'reset', 'submit'),
'image' => array('captcha'),
'multielements' => array('checkbox', 'multi', 'multicheckbox', 'multiselect', 'radio'),
'multirows' => array('select', 'multiselect', 'textarea'),
'input' => array('password', 'text')
);
private $__element_types = array();
public function addElement($element, $name = null, $options = null)
{
parent::addElement($element, $name, $options);
if($element instanceof Zend_Form_Element) {
$name = $element->getName();
$type = strtolower($element->getType());
$type = substr($type, 18);
}else {
$type = $element;
$element = $this->getElement($name);
}
$decorator = $this->element_decorators;
if(in_array($type, $this->__button_group_for)
&& (null !== $name && '_button' == substr($name, -7))) {
$decorator = $this->button_decorators;
$display_group = $this->getDisplayGroup($this->__button_group_id);
if(null === $display_group) {
$group_options['decorators'] = $this->button_group_decorators;
$this->addDisplayGroup(array($name), $this->__button_group_id, $group_options);
}else {
if($this->removeElement($name)) {
$display_group->addElement($element);
}
}
}
if(empty($options['decorators'])) {
$element->setDecorators($decorator);
}
$row_decorator = $element->getDecorator('data');
if(false !== $row_decorator) {
$class_names = array($row_decorator->getOption('class'));
foreach($this->_element_groups as $group_name => $group_types) {
foreach($group_types as $group_type) {
if($type == $group_type) {
$class_names[] = $group_name;
continue 1;
}
}
}
$class_names[] = $type;
$row_decorator->setOption('class', implode(' ', $class_names));
}
return $this;
}
public function addDisplayGroup(array $elements, $name, $options = null)
{
if(empty($options['decorators'])) {
$options['decorators'] = $this->display_group_decorators;
}
return parent::addDisplayGroup($elements, $name, $options);
}
public function addSubForm(Zend_Form $form, $name, $order = null)
{
$decorators = $form->getDecorators();
if(empty($decorators)) {
$form->setDecorators($this->subform_decorators);
}
return parent::addSubForm($form, $name, $order);
}
public function loadDefaultDecorators()
{
$this->setDecorators($this->form_decorators);
}
}
|