1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
6
|
|
|
use Ajax\semantic\html\content\HtmlListItem; |
7
|
|
|
use Ajax\semantic\html\collections\form\HtmlFormCheckbox; |
8
|
|
|
use Ajax\JsUtils; |
9
|
|
|
use Ajax\semantic\html\modules\checkbox\AbstractCheckbox; |
10
|
|
|
|
11
|
|
|
class HtmlList extends HtmlSemCollection { |
12
|
|
|
protected $_hasCheckedList; |
13
|
|
|
protected $_fireOnInit=true; |
14
|
|
|
|
15
|
|
|
public function __construct($identifier, $items=array()) { |
16
|
|
|
parent::__construct($identifier, "div", "ui list"); |
17
|
|
|
$this->addItems($items); |
18
|
|
|
$this->_hasCheckedList=false; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected function createItem($value) { |
22
|
|
|
$count=$this->count(); |
23
|
|
|
$item=new HtmlListItem("item-" . $this->identifier . "-" . $count, $value); |
24
|
|
|
return $item; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function addHeader($niveau, $content) { |
28
|
|
|
$header=new HtmlHeader("header-" . $this->identifier, $niveau, $content, "page"); |
29
|
|
|
$this->wrap($header); |
30
|
|
|
return $header; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getItemPart($index,$partName="header"){ |
34
|
|
|
return $this->getItem($index)->getPart($partName); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function itemsAs($tagName) { |
38
|
|
|
return $this->contentAs($tagName); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function asLinks($hrefs=[],$target=NUll) { |
42
|
|
|
$this->addToPropertyCtrl("class", "link", array ("link" )); |
43
|
|
|
return parent::asLinks($hrefs,$target); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function addList($items=array()) { |
47
|
|
|
$list=new HtmlList("", $items); |
48
|
|
|
$list->setClass("list"); |
49
|
|
|
return $this->addItem($list); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getItemToAdd($item){ |
53
|
|
|
$itemO=parent::getItemToAdd($item); |
54
|
|
|
if($itemO instanceof AbstractCheckbox) |
55
|
|
|
$itemO->addClass("item"); |
56
|
|
|
return $itemO; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setCelled() { |
60
|
|
|
return $this->addToProperty("class", "celled"); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setBulleted() { |
64
|
|
|
return $this->addToProperty("class", "bulleted"); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setOrdered() { |
68
|
|
|
return $this->addToProperty("class", "ordered"); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function run(JsUtils $js) { |
72
|
|
|
if ($this->_hasCheckedList === true) { |
73
|
|
|
$jsCode=include dirname(__FILE__) . '/../../components/jsTemplates/tplCheckedList.php'; |
74
|
|
|
$jsCode=\str_replace("%identifier%", "#" . $this->identifier, $jsCode); |
75
|
|
|
$jsCode=\str_replace("%fireOnInit%", $this->_fireOnInit, $jsCode); |
76
|
|
|
$this->executeOnRun($jsCode); |
77
|
|
|
} |
78
|
|
|
return parent::run($js); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param boolean $fireOnInit |
83
|
|
|
*/ |
84
|
|
|
public function setFireOnInit($fireOnInit) { |
85
|
|
|
$this->_fireOnInit = $fireOnInit; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setRelaxed() { |
89
|
|
|
return $this->addToProperty("class", "relaxed"); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setSelection() { |
93
|
|
|
return $this->addToProperty("class", "selection"); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setDivided() { |
97
|
|
|
return $this->addToProperty("class", "divided"); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function setHorizontal() { |
101
|
|
|
return $this->addToProperty("class", "horizontal"); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Adds a grouped checked box to the list |
106
|
|
|
* @param array $items |
107
|
|
|
* @param string|array|null $masterItem |
108
|
|
|
* @param array|null $values |
109
|
|
|
* @param string $notAllChecked |
110
|
|
|
* @return HtmlList |
111
|
|
|
*/ |
112
|
|
|
public function addCheckedList($items=array(), $masterItem=NULL, $values=array(),$notAllChecked=false,$name=null) { |
113
|
|
|
$count=$this->count(); |
114
|
|
|
$identifier=$this->identifier . "-" . $count; |
115
|
|
|
if (isset($masterItem)) { |
116
|
|
|
if(\is_array($masterItem)){ |
117
|
|
|
$masterO=new HtmlFormCheckbox("master-" . $identifier, @$masterItem[0],@$masterItem[1]); |
118
|
|
|
if(isset($name)) |
119
|
|
|
$masterO->setName($name); |
120
|
|
|
if(isset($masterItem[1])){ |
121
|
|
|
if(\array_search($masterItem[1], $values)!==false){ |
|
|
|
|
122
|
|
|
$masterO->getDataField()->setProperty("checked", ""); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
}else{ |
126
|
|
|
$masterO=new HtmlFormCheckbox("master-" . $identifier, $masterItem); |
127
|
|
|
} |
128
|
|
|
if($notAllChecked){ |
129
|
|
|
$masterO->getDataField()->addClass("_notAllChecked"); |
130
|
|
|
} |
131
|
|
|
$masterO->getHtmlCk()->addToProperty("class", "master"); |
132
|
|
|
$masterO->setClass("item"); |
133
|
|
|
$this->addItem($masterO); |
134
|
|
|
} |
135
|
|
|
$fields=array (); |
136
|
|
|
$i=0; |
137
|
|
|
foreach ( $items as $val => $caption ) { |
138
|
|
|
$itemO=new HtmlFormCheckbox($identifier . "-" . $i++, $caption, $val, "child"); |
139
|
|
|
if (\array_search($val, $values) !== false) { |
140
|
|
|
$itemO->getDataField()->setProperty("checked", ""); |
141
|
|
|
} |
142
|
|
|
if(isset($name)) |
143
|
|
|
$itemO->setName($name); |
144
|
|
|
$itemO->setClass("item"); |
145
|
|
|
$fields[]=$itemO; |
146
|
|
|
} |
147
|
|
|
if (isset($masterO) === true) { |
148
|
|
|
$list=new HtmlList("", $fields); |
149
|
|
|
$list->setClass("list"); |
150
|
|
|
$masterO->addContent($list); |
151
|
|
|
} else { |
152
|
|
|
$this->addList($fields); |
153
|
|
|
} |
154
|
|
|
$this->_hasCheckedList=true; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function setIcons($icons){ |
159
|
|
|
if(!\is_array($icons)){ |
160
|
|
|
$icons=\array_fill(0, \sizeof($this->content), $icons); |
161
|
|
|
} |
162
|
|
|
$max=\min(\sizeof($icons),\sizeof($this->content)); |
163
|
|
|
for($i=0;$i<$max;$i++){ |
164
|
|
|
$this->content[$i]->addIcon($icons[$i]); |
165
|
|
|
} |
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|