11<?php
2-
32namespace Ajax \semantic \html \elements ;
43
54use Ajax \semantic \html \base \HtmlSemCollection ;
87use Ajax \JsUtils ;
98use Ajax \semantic \html \modules \checkbox \AbstractCheckbox ;
109use Ajax \semantic \components \Visibility ;
10+ use Ubiquity \utils \base \UString ;
1111
1212class HtmlList extends HtmlSemCollection {
13+
1314 protected $ _hasCheckedList ;
14- protected $ _fireOnInit =true ;
15- protected $ _ckItemChange ="" ;
15+
16+ protected $ _fireOnInit = false ;
17+
18+ protected $ _ckItemChange = "" ;
19+
1620 protected $ _maxVisible ;
21+
1722 protected $ _dataList ;
23+
1824 protected $ _visibility ;
1925
20- public function __construct ($ identifier , $ items= array ()) {
26+ public function __construct ($ identifier , $ items = array ()) {
2127 parent ::__construct ($ identifier , "div " , "ui list " );
2228 $ this ->addItems ($ items );
23- $ this ->_hasCheckedList = false ;
29+ $ this ->_hasCheckedList = false ;
2430 }
2531
2632 protected function createItem ($ value ) {
27- $ count= $ this ->count ();
28- $ item= new HtmlListItem ("item- " . $ this ->identifier . "- " . $ count , $ value );
33+ $ count = $ this ->count ();
34+ $ item = new HtmlListItem ("item- " . $ this ->identifier . "- " . $ count , $ value );
2935 return $ item ;
3036 }
3137
3238 public function addHeader ($ niveau , $ content ) {
33- $ header= new HtmlHeader ("header- " . $ this ->identifier , $ niveau , $ content , "page " );
39+ $ header = new HtmlHeader ("header- " . $ this ->identifier , $ niveau , $ content , "page " );
3440 $ this ->wrap ($ header );
3541 return $ header ;
3642 }
3743
38- public function getItemPart ($ index ,$ partName= "header " ){
44+ public function getItemPart ($ index , $ partName = "header " ) {
3945 return $ this ->getItem ($ index )->getPart ($ partName );
4046 }
4147
4248 public function itemsAs ($ tagName ) {
4349 return $ this ->contentAs ($ tagName );
4450 }
4551
46- public function asLinks ($ hrefs =[],$ target =NUll ) {
47- $ this ->addToPropertyCtrl ("class " , "link " , array ("link " ));
48- return parent ::asLinks ($ hrefs ,$ target );
52+ public function asLinks ($ hrefs = [], $ target = NUll ) {
53+ $ this ->addToPropertyCtrl ("class " , "link " , array (
54+ "link "
55+ ));
56+ return parent ::asLinks ($ hrefs , $ target );
4957 }
5058
51- public function addList ($ items= array ()) {
52- $ list= new HtmlList ("" , $ items );
59+ public function addList ($ items = array ()) {
60+ $ list = new HtmlList ("" , $ items );
5361 $ list ->setClass ("list " );
5462 return $ this ->addItem ($ list );
5563 }
56-
64+
5765 /**
66+ *
5867 * @return HtmlListItem
5968 */
60- public function getItem ($ index ){
69+ public function getItem ($ index ) {
6170 return parent ::getItem ($ index );
6271 }
6372
64- protected function getItemToAdd ($ item ){
65- $ itemO= parent ::getItemToAdd ($ item );
66- if ($ itemO instanceof AbstractCheckbox)
73+ protected function getItemToAdd ($ item ) {
74+ $ itemO = parent ::getItemToAdd ($ item );
75+ if ($ itemO instanceof AbstractCheckbox)
6776 $ itemO ->addClass ("item " );
6877 return $ itemO ;
6978 }
@@ -82,33 +91,38 @@ public function setOrdered() {
8291
8392 public function run (JsUtils $ js ) {
8493 if ($ this ->_hasCheckedList === true ) {
85- $ jsCode= include dirname (__FILE__ ) . '/../../components/jsTemplates/tplCheckedList.php ' ;
86- $ jsCode= \str_replace ("%identifier% " , "# " . $ this ->identifier , $ jsCode );
87- $ jsCode= \str_replace ("%fireOnInit% " , $ this ->_fireOnInit , $ jsCode );
88- $ jsCode= \str_replace ("%onChange% " , $ this ->_ckItemChange , $ jsCode );
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 );
8998 $ this ->executeOnRun ($ jsCode );
9099 }
91- /*if(isset($this->_visibility)){
92- $this->_visibility->run($js);
93- }*/
100+ /*
101+ * if(isset($this->_visibility)){
102+ * $this->_visibility->run($js);
103+ * }
104+ */
94105 return parent ::run ($ js );
95106 }
96-
97- protected function addFollowPoints (){
98- $ count =$ this ->count ();
99- for ($ i =$ this ->_maxVisible ;$ i <$ count ;$ i ++){
100- $ this ->getItem ($ i )->addClass ("notVisible " )->setProperty ("style " , "display: none; " );
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; " );
101114 }
102- $ item= $ this ->addItem ("... " );
115+ $ item = $ this ->addItem ("... " );
103116 $ item ->addClass ("points " );
104- $ item ->onClick ('$(this).hide();$("# ' . $ this ->identifier . ' .notVisible").show(); ' );
117+ $ item ->onClick ('$(this).hide();$("# ' . $ this ->identifier . ' .notVisible").show(); ' );
105118 }
106-
107- public function onCkItemChange ($ jsCode ){
108- $ this ->_ckItemChange = $ jsCode ;
119+
120+ public function onCkItemChange ($ jsCode ) {
121+ $ this ->_ckItemChange = $ jsCode ;
109122 }
110123
111124 /**
125+ *
112126 * @param boolean $fireOnInit
113127 */
114128 public function setFireOnInit ($ fireOnInit ) {
@@ -132,100 +146,105 @@ public function setHorizontal() {
132146 }
133147
134148 /**
135- * {@inheritDoc}
149+ *
150+ * {@inheritdoc}
136151 * @see \Ajax\common\html\HtmlCollection::compile()
137152 */
138153 public function compile (JsUtils $ js = NULL , &$ view = NULL ) {
139- if (isset ($ this ->_maxVisible ) && $ this ->_maxVisible < $ this ->count ()){
154+ if (isset ($ this ->_maxVisible ) && $ this ->_maxVisible < $ this ->count ()) {
140155 $ this ->addFollowPoints ();
141- if (isset ($ js )){
142- $ visibility= new Visibility ($ js );
143- $ visibility ->attach ("# " . $ this ->identifier );
156+ if (isset ($ js )) {
157+ $ visibility = new Visibility ($ js );
158+ $ visibility ->attach ("# " . $ this ->identifier );
144159 $ visibility ->setOnTopVisible ("$(this).children('.notVisible').hide();$(this).find('.points').show(); " );
145- $ visibility ->compile ($ js ,$ view );
146- $ this ->_visibility = $ visibility ;
160+ $ visibility ->compile ($ js , $ view );
161+ $ this ->_visibility = $ visibility ;
147162 }
148163 }
149- return parent ::compile ($ js ,$ view );
164+ return parent ::compile ($ js , $ view );
150165 }
151166
152167 /**
153168 * Adds a grouped checked box to the list
169+ *
154170 * @param array $items
155171 * @param string|array|null $masterItem
156172 * @param array $values
157173 * @param string $notAllChecked
158174 * @return HtmlList
159175 */
160- public function addCheckedList ($ items= array (), $ masterItem= NULL , $ values= array (),$ notAllChecked= false ,$ name= null ) {
161- $ count= $ this ->count ();
162- $ identifier= $ this ->identifier . "- " . $ count ;
176+ public function addCheckedList ($ items = array (), $ masterItem = NULL , $ values = array (), $ notAllChecked = false , $ name = null ) {
177+ $ count = $ this ->count ();
178+ $ identifier = $ this ->identifier . "- " . $ count ;
163179 if (isset ($ masterItem )) {
164- if (\is_array ($ masterItem )){
165- $ masterO= new HtmlFormCheckbox ("master- " . $ identifier , @$ masterItem [0 ],@$ masterItem [1 ]);
166- if (isset ($ name ))
180+ if (\is_array ($ masterItem )) {
181+ $ masterO = new HtmlFormCheckbox ("master- " . $ identifier , @$ masterItem [0 ], @$ masterItem [1 ]);
182+ if (isset ($ name ))
167183 $ masterO ->setName ($ name );
168- if (isset ($ masterItem [1 ])){
169- if (\array_search ($ masterItem [1 ], $ values )!==false ){
184+ if (isset ($ masterItem [1 ])) {
185+ if (\array_search ($ masterItem [1 ], $ values ) !== false ) {
170186 $ masterO ->getDataField ()->setProperty ("checked " , "" );
171187 }
172188 }
173- }else {
174- $ masterO= new HtmlFormCheckbox ("master- " . $ identifier , $ masterItem );
189+ } else {
190+ $ masterO = new HtmlFormCheckbox ("master- " . $ identifier , $ masterItem );
175191 }
176- if ($ notAllChecked ){
192+ if ($ notAllChecked ) {
177193 $ masterO ->getDataField ()->addClass ("_notAllChecked " );
178194 }
179195 $ masterO ->getHtmlCk ()->addToProperty ("class " , "master " );
180196 $ masterO ->setClass ("item " );
181197 $ this ->addItem ($ masterO );
182198 }
183- $ fields =array ();
184- $ i =0 ;
185- foreach ( $ items as $ val => $ caption ) {
186- $ itemO =new HtmlFormCheckbox ($ identifier . "- " . $ i ++, $ caption , $ val , "child " );
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 " );
187204 if (\array_search ($ val , $ values ) !== false ) {
188205 $ itemO ->getDataField ()->setProperty ("checked " , "" );
189206 }
190- if (isset ($ name ))
207+ if (isset ($ name ))
191208 $ itemO ->setName ($ name );
192209 $ itemO ->setClass ("item " );
193- $ fields []= $ itemO ;
210+ $ fields [] = $ itemO ;
194211 }
195212 if (isset ($ masterO ) === true ) {
196- $ list= new HtmlList ("" , $ fields );
213+ $ list = new HtmlList ("" , $ fields );
197214 $ list ->setClass ("list " );
198215 $ masterO ->addContent ($ list );
199216 } else {
200217 $ this ->addList ($ fields );
201218 }
202- $ this ->_hasCheckedList = true ;
219+ $ this ->_hasCheckedList = true ;
203220 return $ this ;
204221 }
205222
206- public function setIcons ($ icons ){
207- if (! \is_array ($ icons )){
208- $ icons= \array_fill (0 , \sizeof ($ this ->content ), $ icons );
223+ public function setIcons ($ icons ) {
224+ if (! \is_array ($ icons )) {
225+ $ icons = \array_fill (0 , \sizeof ($ this ->content ), $ icons );
209226 }
210- $ max= \min (\sizeof ($ icons ),\sizeof ($ this ->content ));
211- for ($ i= 0 ; $ i < $ max ;$ i ++){
227+ $ max = \min (\sizeof ($ icons ), \sizeof ($ this ->content ));
228+ for ($ i = 0 ; $ i < $ max ; $ i ++) {
212229 $ this ->content [$ i ]->addIcon ($ icons [$ i ]);
213230 }
214231 return $ this ;
215232 }
233+
216234 /**
235+ *
217236 * @return mixed
218237 */
219238 public function getMaxVisible () {
220239 return $ this ->_maxVisible ;
221240 }
222241
223242 /**
243+ *
224244 * @param mixed $_maxVisible
225245 */
226246 public function setMaxVisible ($ _maxVisible ) {
227247 $ this ->_maxVisible = $ _maxVisible ;
228248 return $ this ;
229249 }
230-
231250}
0 commit comments