element.php
2.09 KB
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
<?php
class N2Element {
/**
* @var N2Form
*/
public $_form;
var $_tab;
var $_xml;
var $_default;
var $_name;
public $_label = '';
var $_description;
var $_id;
var $_inputname;
var $_editableName = false;
public $hasLabel = true;
function __construct(&$form, &$tab, &$xml) {
$this->_form = $form;
$this->_tab = $tab;
$this->_xml = $xml;
$this->_name = N2XmlHelper::getAttribute($xml, 'name');
}
function render($control_name = 'params', $tooltip = true) {
$this->control_name = $control_name;
$this->_default = N2XmlHelper::getAttribute($this->_xml, 'default');
$this->_id = $this->generateId($control_name . $this->_name);
$this->_inputname = (N2XmlHelper::getAttribute($this->_xml, 'hidename') ? '' : $control_name . '[' . $this->_name . ']');
$this->_label = N2XmlHelper::getAttribute($this->_xml, 'label');
if (empty($this->_label)) $this->hasLabel = false;
return array(
$tooltip ? $this->fetchTooltip() : '',
$this->fetchElement()
);
}
function fetchTooltip() {
if ($this->_label == '-') {
$this->_label = '';
} else {
$this->_label = n2_($this->_label);
}
$attrs = array(
'for' => $this->_id
);
$tip = N2XmlHelper::getAttribute($this->_xml, 'tip');
if (!empty($tip)) {
$attrs['data-n2tip'] = n2_($tip);
}
$html = N2Html::tag('label', $attrs, $this->_label);
return $html;
}
function fetchNoTooltip() {
return "";
}
function fetchElement() {
}
function getValue() {
return $this->_form->get($this->_name, $this->_default);
}
function setValue($value) {
return $this->_form->set($this->_name, $value);
}
function generateId($name) {
return str_replace(array(
'[',
']',
' '
), array(
'',
'',
''
), $name);
}
}