1
1
<?php
2
-
3
2
namespace Ajax \semantic \html \elements ;
4
3
5
4
use Ajax \semantic \html \base \HtmlSemCollection ;
8
7
use Ajax \JsUtils ;
9
8
use Ajax \semantic \html \modules \checkbox \AbstractCheckbox ;
10
9
use Ajax \semantic \components \Visibility ;
10
+ use Ubiquity \utils \base \UString ;
11
11
12
12
class HtmlList extends HtmlSemCollection {
13
+
13
14
protected $ _hasCheckedList ;
14
- protected $ _fireOnInit =true ;
15
- protected $ _ckItemChange ="" ;
15
+
16
+ protected $ _fireOnInit = false ;
17
+
18
+ protected $ _ckItemChange = "" ;
19
+
16
20
protected $ _maxVisible ;
21
+
17
22
protected $ _dataList ;
23
+
18
24
protected $ _visibility ;
19
25
20
- public function __construct ($ identifier , $ items= array ()) {
26
+ public function __construct ($ identifier , $ items = array ()) {
21
27
parent ::__construct ($ identifier , "div " , "ui list " );
22
28
$ this ->addItems ($ items );
23
- $ this ->_hasCheckedList = false ;
29
+ $ this ->_hasCheckedList = false ;
24
30
}
25
31
26
32
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 );
29
35
return $ item ;
30
36
}
31
37
32
38
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 " );
34
40
$ this ->wrap ($ header );
35
41
return $ header ;
36
42
}
37
43
38
- public function getItemPart ($ index ,$ partName= "header " ){
44
+ public function getItemPart ($ index , $ partName = "header " ) {
39
45
return $ this ->getItem ($ index )->getPart ($ partName );
40
46
}
41
47
42
48
public function itemsAs ($ tagName ) {
43
49
return $ this ->contentAs ($ tagName );
44
50
}
45
51
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 );
49
57
}
50
58
51
- public function addList ($ items= array ()) {
52
- $ list= new HtmlList ("" , $ items );
59
+ public function addList ($ items = array ()) {
60
+ $ list = new HtmlList ("" , $ items );
53
61
$ list ->setClass ("list " );
54
62
return $ this ->addItem ($ list );
55
63
}
56
-
64
+
57
65
/**
66
+ *
58
67
* @return HtmlListItem
59
68
*/
60
- public function getItem ($ index ){
69
+ public function getItem ($ index ) {
61
70
return parent ::getItem ($ index );
62
71
}
63
72
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)
67
76
$ itemO ->addClass ("item " );
68
77
return $ itemO ;
69
78
}
@@ -82,33 +91,38 @@ public function setOrdered() {
82
91
83
92
public function run (JsUtils $ js ) {
84
93
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 );
89
98
$ this ->executeOnRun ($ jsCode );
90
99
}
91
- /*if(isset($this->_visibility)){
92
- $this->_visibility->run($js);
93
- }*/
100
+ /*
101
+ * if(isset($this->_visibility)){
102
+ * $this->_visibility->run($js);
103
+ * }
104
+ */
94
105
return parent ::run ($ js );
95
106
}
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; " );
101
114
}
102
- $ item= $ this ->addItem ("... " );
115
+ $ item = $ this ->addItem ("... " );
103
116
$ item ->addClass ("points " );
104
- $ item ->onClick ('$(this).hide();$("# ' . $ this ->identifier . ' .notVisible").show(); ' );
117
+ $ item ->onClick ('$(this).hide();$("# ' . $ this ->identifier . ' .notVisible").show(); ' );
105
118
}
106
-
107
- public function onCkItemChange ($ jsCode ){
108
- $ this ->_ckItemChange = $ jsCode ;
119
+
120
+ public function onCkItemChange ($ jsCode ) {
121
+ $ this ->_ckItemChange = $ jsCode ;
109
122
}
110
123
111
124
/**
125
+ *
112
126
* @param boolean $fireOnInit
113
127
*/
114
128
public function setFireOnInit ($ fireOnInit ) {
@@ -132,100 +146,105 @@ public function setHorizontal() {
132
146
}
133
147
134
148
/**
135
- * {@inheritDoc}
149
+ *
150
+ * {@inheritdoc}
136
151
* @see \Ajax\common\html\HtmlCollection::compile()
137
152
*/
138
153
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 ()) {
140
155
$ 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 );
144
159
$ 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 ;
147
162
}
148
163
}
149
- return parent ::compile ($ js ,$ view );
164
+ return parent ::compile ($ js , $ view );
150
165
}
151
166
152
167
/**
153
168
* Adds a grouped checked box to the list
169
+ *
154
170
* @param array $items
155
171
* @param string|array|null $masterItem
156
172
* @param array $values
157
173
* @param string $notAllChecked
158
174
* @return HtmlList
159
175
*/
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 ;
163
179
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 ))
167
183
$ 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 ) {
170
186
$ masterO ->getDataField ()->setProperty ("checked " , "" );
171
187
}
172
188
}
173
- }else {
174
- $ masterO= new HtmlFormCheckbox ("master- " . $ identifier , $ masterItem );
189
+ } else {
190
+ $ masterO = new HtmlFormCheckbox ("master- " . $ identifier , $ masterItem );
175
191
}
176
- if ($ notAllChecked ){
192
+ if ($ notAllChecked ) {
177
193
$ masterO ->getDataField ()->addClass ("_notAllChecked " );
178
194
}
179
195
$ masterO ->getHtmlCk ()->addToProperty ("class " , "master " );
180
196
$ masterO ->setClass ("item " );
181
197
$ this ->addItem ($ masterO );
182
198
}
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 " );
187
204
if (\array_search ($ val , $ values ) !== false ) {
188
205
$ itemO ->getDataField ()->setProperty ("checked " , "" );
189
206
}
190
- if (isset ($ name ))
207
+ if (isset ($ name ))
191
208
$ itemO ->setName ($ name );
192
209
$ itemO ->setClass ("item " );
193
- $ fields []= $ itemO ;
210
+ $ fields [] = $ itemO ;
194
211
}
195
212
if (isset ($ masterO ) === true ) {
196
- $ list= new HtmlList ("" , $ fields );
213
+ $ list = new HtmlList ("" , $ fields );
197
214
$ list ->setClass ("list " );
198
215
$ masterO ->addContent ($ list );
199
216
} else {
200
217
$ this ->addList ($ fields );
201
218
}
202
- $ this ->_hasCheckedList = true ;
219
+ $ this ->_hasCheckedList = true ;
203
220
return $ this ;
204
221
}
205
222
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 );
209
226
}
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 ++) {
212
229
$ this ->content [$ i ]->addIcon ($ icons [$ i ]);
213
230
}
214
231
return $ this ;
215
232
}
233
+
216
234
/**
235
+ *
217
236
* @return mixed
218
237
*/
219
238
public function getMaxVisible () {
220
239
return $ this ->_maxVisible ;
221
240
}
222
241
223
242
/**
243
+ *
224
244
* @param mixed $_maxVisible
225
245
*/
226
246
public function setMaxVisible ($ _maxVisible ) {
227
247
$ this ->_maxVisible = $ _maxVisible ;
228
248
return $ this ;
229
249
}
230
-
231
250
}
0 commit comments