66use Ajax \semantic \html \content \HtmlListItem ;
77use Ajax \semantic \html \collections \form \HtmlFormCheckbox ;
88use Ajax \JsUtils ;
9+ use Ajax \semantic \html \modules \checkbox \AbstractCheckbox ;
910
1011class HtmlList extends HtmlSemCollection {
1112 protected $ _hasCheckedList ;
@@ -47,6 +48,13 @@ public function addList($items=array()) {
4748 return $ this ->addItem ($ list );
4849 }
4950
51+ protected function getItemToAdd ($ item ){
52+ $ itemO =parent ::getItemToAdd ($ item );
53+ if ($ itemO instanceof AbstractCheckbox)
54+ $ itemO ->addClass ("item " );
55+ return $ itemO ;
56+ }
57+
5058 public function setCelled () {
5159 return $ this ->addToProperty ("class " , "celled " );
5260 }
@@ -84,11 +92,31 @@ public function setHorizontal() {
8492 return $ this ->addToProperty ("class " , "horizontal " );
8593 }
8694
87- public function addCheckedList ($ items =array (), $ masterItem =NULL , $ values =array ()) {
95+ /**
96+ * Adds a grouped checked box to the list
97+ * @param array $items
98+ * @param string|array|null $masterItem
99+ * @param array|null $values
100+ * @param string $notAllChecked
101+ * @return HtmlList
102+ */
103+ public function addCheckedList ($ items =array (), $ masterItem =NULL , $ values =array (),$ notAllChecked =false ) {
88104 $ count =$ this ->count ();
89105 $ identifier =$ this ->identifier . "- " . $ count ;
90106 if (isset ($ masterItem )) {
91- $ masterO =new HtmlFormCheckbox ("master- " . $ identifier , $ masterItem );
107+ if (\is_array ($ masterItem )){
108+ $ masterO =new HtmlFormCheckbox ("master- " . $ identifier , @$ masterItem [0 ],@$ masterItem [1 ]);
109+ if (isset ($ masterItem [1 ])){
110+ if (\array_search ($ masterItem [1 ], $ values )!==false ){
111+ $ masterO ->getDataField ()->setProperty ("checked " , "" );
112+ }
113+ }
114+ }else {
115+ $ masterO =new HtmlFormCheckbox ("master- " . $ identifier , $ masterItem );
116+ }
117+ if ($ notAllChecked ){
118+ $ masterO ->getDataField ()->addClass ("_notAllChecked " );
119+ }
92120 $ masterO ->getHtmlCk ()->addToProperty ("class " , "master " );
93121 $ masterO ->setClass ("item " );
94122 $ this ->addItem ($ masterO );
@@ -98,7 +126,7 @@ public function addCheckedList($items=array(), $masterItem=NULL, $values=array()
98126 foreach ( $ items as $ val => $ caption ) {
99127 $ itemO =new HtmlFormCheckbox ($ identifier . "- " . $ i ++, $ caption , $ val , "child " );
100128 if (\array_search ($ val , $ values ) !== false ) {
101- $ itemO ->getField ()->setProperty ("checked " , "" );
129+ $ itemO ->getDataField ()->setProperty ("checked " , "" );
102130 }
103131 $ itemO ->setClass ("item " );
104132 $ fields []=$ itemO ;
0 commit comments