|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections\form; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
|
6
|
|
|
use Ajax\semantic\html\base\constants\Wide; |
|
7
|
|
|
use Ajax\JsUtils; |
|
8
|
|
|
use Phalcon\Mvc\View; |
|
9
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
|
10
|
|
|
|
|
11
|
|
|
class HtmlFormFields extends HtmlSemCollection { |
|
12
|
|
|
|
|
13
|
|
|
use FieldsTrait; |
|
14
|
|
|
protected $_equalWidth; |
|
15
|
|
|
protected $_name; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($identifier, $fields=array(),$equalWidth=true) { |
|
18
|
|
|
parent::__construct($identifier, "div"); |
|
19
|
|
|
$this->_equalWidth=$equalWidth; |
|
20
|
|
|
$this->addItems($fields); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param string|HtmlSemDoubleElement $label |
|
25
|
|
|
* @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
|
26
|
|
|
*/ |
|
27
|
|
|
public function setLabel($label){ |
|
28
|
|
|
$labelO=$label; |
|
29
|
|
|
if(\is_string($label)){ |
|
30
|
|
|
$labelO=new HtmlSemDoubleElement("","label","",$label); |
|
31
|
|
|
} |
|
32
|
|
|
$this->insertItem($labelO,0); |
|
33
|
|
|
return $labelO; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function compile(JsUtils $js=NULL,View $view=NULL){ |
|
37
|
|
|
if($this->_equalWidth){ |
|
38
|
|
|
$count=$this->count(); |
|
39
|
|
|
$this->addToProperty("class", Wide::getConstants()["W".$count]." fields"); |
|
40
|
|
|
}else |
|
41
|
|
|
$this->addToProperty("class","fields"); |
|
42
|
|
|
return parent::compile($js,$view); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function setWidth($index,$width){ |
|
46
|
|
|
$this->_equalWidth=false; |
|
47
|
|
|
return $this->getItem($index)->setWidth($width); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function setInline(){ |
|
51
|
|
|
$this->_equalWidth=false; |
|
52
|
|
|
$this->addToProperty("class", "inline"); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function setGrouped(){ |
|
56
|
|
|
$this->_equalWidth=false; |
|
57
|
|
|
$this->addToProperty("class", "grouped"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getName() { |
|
61
|
|
|
return $this->_name; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function setName($_name) { |
|
65
|
|
|
$this->_name=$_name; |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function radios($name,$items=array(),$label=NULL){ |
|
70
|
|
|
$fields=array(); |
|
71
|
|
|
$i=0; |
|
72
|
|
|
foreach ($items as $item){ |
|
73
|
|
|
$fields[]=new HtmlFormRadio($name."-".$i++,$name,$item,$item); |
|
74
|
|
|
} |
|
75
|
|
|
$radios=new HtmlFormFields("fields-".$name,$fields); |
|
76
|
|
|
if(isset($label)) |
|
77
|
|
|
$radios->setLabel($label)->setProperty("for", $name); |
|
78
|
|
|
return $radios; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |