phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlList.php
Go to the documentation of this file.
1<?php
3
10use Ubiquity\utils\base\UString;
11
13
15
16 protected $_fireOnInit = false;
17
18 protected $_ckItemChange = "";
19
20 protected $_maxVisible;
21
22 protected $_dataList;
23
24 protected $_visibility;
25
26 public function __construct($identifier, $items = array()) {
27 parent::__construct($identifier, "div", "ui list");
28 $this->addItems($items);
29 $this->_hasCheckedList = false;
30 }
31
32 protected function createItem($value) {
33 $count = $this->count();
34 $item = new HtmlListItem("item-" . $this->identifier . "-" . $count, $value);
35 return $item;
36 }
37
38 public function addHeader($niveau, $content) {
39 $header = new HtmlHeader("header-" . $this->identifier, $niveau, $content, "page");
40 $this->wrap($header);
41 return $header;
42 }
43
44 public function getItemPart($index, $partName = "header") {
45 return $this->getItem($index)->getPart($partName);
46 }
47
48 public function itemsAs($tagName) {
49 return $this->contentAs($tagName);
50 }
51
52 public function asLinks($hrefs = [], $target = NUll) {
53 $this->addToPropertyCtrl("class", "link", array(
54 "link"
55 ));
56 return parent::asLinks($hrefs, $target);
57 }
58
59 public function addList($items = array()) {
60 $list = new HtmlList("", $items);
61 $list->setClass("list");
62 return $this->addItem($list);
63 }
64
69 public function getItem($index) {
70 return parent::getItem($index);
71 }
72
73 protected function getItemToAdd($item) {
74 $itemO = parent::getItemToAdd($item);
75 if ($itemO instanceof AbstractCheckbox)
76 $itemO->addClass("item");
77 return $itemO;
78 }
79
80 public function setCelled() {
81 return $this->addToProperty("class", "celled");
82 }
83
84 public function setBulleted() {
85 return $this->addToProperty("class", "bulleted");
86 }
87
88 public function setOrdered() {
89 return $this->addToProperty("class", "ordered");
90 }
91
92 public function run(JsUtils $js) {
93 if ($this->_hasCheckedList === true) {
94 $jsCode = include dirname(__FILE__) . '/../../components/jsTemplates/tplCheckedList.php';
95 $jsCode = \str_replace("%identifier%", "#" . $this->identifier, $jsCode);
96 $jsCode = \str_replace("%fireOnInit%", $this->_fireOnInit, $jsCode);
97 $jsCode = \str_replace("%onChange%", $this->_ckItemChange, $jsCode);
98 $this->executeOnRun($jsCode);
99 }
100 /*
101 * if(isset($this->_visibility)){
102 * $this->_visibility->run($js);
103 * }
104 */
105 return parent::run($js);
106 }
107
108 protected function addFollowPoints() {
109 $count = $this->count();
110 for ($i = $this->_maxVisible; $i < $count; $i ++) {
111 $this->getItem($i)
112 ->addClass("notVisible")
113 ->setProperty("style", "display: none;");
114 }
115 $item = $this->addItem("...");
116 $item->addClass("points");
117 $item->onClick('$(this).hide();$("#' . $this->identifier . ' .notVisible").show();');
118 }
119
120 public function onCkItemChange($jsCode) {
121 $this->_ckItemChange = $jsCode;
122 }
123
128 public function setFireOnInit($fireOnInit) {
129 $this->_fireOnInit = $fireOnInit;
130 }
131
132 public function setRelaxed() {
133 return $this->addToProperty("class", "relaxed");
134 }
135
136 public function setSelection() {
137 return $this->addToProperty("class", "selection");
138 }
139
140 public function setDivided() {
141 return $this->addToProperty("class", "divided");
142 }
143
144 public function setHorizontal() {
145 return $this->addToProperty("class", "horizontal");
146 }
147
153 public function compile(JsUtils $js = NULL, &$view = NULL) {
154 if (isset($this->_maxVisible) && $this->_maxVisible < $this->count()) {
155 $this->addFollowPoints();
156 if (isset($js)) {
157 $visibility = new Visibility($js);
158 $visibility->attach("#" . $this->identifier);
159 $visibility->setOnTopVisible("$(this).children('.notVisible').hide();$(this).find('.points').show();");
160 $visibility->compile($js, $view);
161 $this->_visibility = $visibility;
162 }
163 }
164 return parent::compile($js, $view);
165 }
166
176 public function addCheckedList($items = array(), $masterItem = NULL, $values = array(), $notAllChecked = false, $name = null) {
177 $count = $this->count();
178 $identifier = $this->identifier . "-" . $count;
179 if (isset($masterItem)) {
180 if (\is_array($masterItem)) {
181 $masterO = new HtmlFormCheckbox("master-" . $identifier, @$masterItem[0], @$masterItem[1]);
182 if (isset($name))
183 $masterO->setName($name);
184 if (isset($masterItem[1])) {
185 if (\array_search($masterItem[1], $values) !== false) {
186 $masterO->getDataField()->setProperty("checked", "");
187 }
188 }
189 } else {
190 $masterO = new HtmlFormCheckbox("master-" . $identifier, $masterItem);
191 }
192 if ($notAllChecked) {
193 $masterO->getDataField()->addClass("_notAllChecked");
194 }
195 $masterO->getHtmlCk()->addToProperty("class", "master");
196 $masterO->setClass("item");
197 $this->addItem($masterO);
198 }
199 $fields = array();
200 $i = 0;
201 $this->setFireOnInit(UString::getBooleanStr($this->_fireOnInit || count($items) < 30));
202 foreach ($items as $val => $caption) {
203 $itemO = new HtmlFormCheckbox($identifier . "-" . $i ++, $caption, $val, "child");
204 if (\array_search($val, $values) !== false) {
205 $itemO->getDataField()->setProperty("checked", "");
206 }
207 if (isset($name))
208 $itemO->setName($name);
209 $itemO->setClass("item");
210 $fields[] = $itemO;
211 }
212 if (isset($masterO) === true) {
213 $list = new HtmlList("", $fields);
214 $list->setClass("list");
215 $masterO->addContent($list);
216 } else {
217 $this->addList($fields);
218 }
219 $this->_hasCheckedList = true;
220 return $this;
221 }
222
223 public function setIcons($icons) {
224 if (! \is_array($icons)) {
225 $icons = \array_fill(0, \sizeof($this->content), $icons);
226 }
227 $max = \min(\sizeof($icons), \sizeof($this->content));
228 for ($i = 0; $i < $max; $i ++) {
229 $this->content[$i]->addIcon($icons[$i]);
230 }
231 return $this;
232 }
233
238 public function getMaxVisible() {
239 return $this->_maxVisible;
240 }
241
246 public function setMaxVisible($_maxVisible) {
247 $this->_maxVisible = $_maxVisible;
248 return $this;
249 }
250}
JQuery PHP library.
Definition JsUtils.php:23
wrap($before, $after="")
Definition BaseHtml.php:170
addItem($item)
adds and returns an item
Visibility provides a set of callbacks for when a content appears in the viewport.
Base class for Semantic Html collections.
addToProperty($name, $value, $separator=" ")
addToPropertyCtrl($name, $value, $typeCtrl)
Semantic Header component.
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\Bas...
Definition HtmlList.php:92
createItem($value)
The item factory.
Definition HtmlList.php:32
asLinks($hrefs=[], $target=NUll)
Definition HtmlList.php:52
__construct($identifier, $items=array())
Definition HtmlList.php:26
compile(JsUtils $js=NULL, &$view=NULL)
{}
Definition HtmlList.php:153
addCheckedList($items=array(), $masterItem=NULL, $values=array(), $notAllChecked=false, $name=null)
Adds a grouped checked box to the list.
Definition HtmlList.php:176
getItemPart($index, $partName="header")
Definition HtmlList.php:44