1
1
<?php
2
-
3
2
namespace Ajax \semantic \html \modules \checkbox ;
4
3
5
4
use Ajax \semantic \html \base \HtmlSemDoubleElement ;
6
5
use Ajax \semantic \html \base \constants \CheckboxType ;
7
6
use Ajax \JsUtils ;
8
7
9
8
abstract class AbstractCheckbox extends HtmlSemDoubleElement {
10
- protected $ _params =[];
11
9
12
- public function __construct ($ identifier , $ name =NULL , $ label =NULL , $ value =NULL , $ inputType ="checkbox " , $ type ="checkbox " ) {
13
- parent ::__construct ("ck- " .$ identifier , "div " , "ui " .$ type );
14
- $ this ->_identifier =$ identifier ;
15
- $ field =new \Ajax \common \html \html5 \HtmlInput ($ identifier , $ inputType , $ value );
10
+ protected $ _params = [];
11
+
12
+ public function __construct ($ identifier , $ name = NULL , $ label = NULL , $ value = NULL , $ inputType = "checkbox " , $ type = "checkbox " ) {
13
+ parent ::__construct ("ck- " . $ identifier , "div " , "ui " . $ type );
14
+ $ this ->_identifier = $ identifier ;
15
+ $ field = new \Ajax \common \html \html5 \HtmlInput ($ identifier , $ inputType , $ value );
16
16
$ field ->setProperty ("name " , $ name );
17
17
$ this ->setField ($ field );
18
18
if (isset ($ label ))
19
- $ this ->setLabel ($ label ,$ value );
19
+ $ this ->setLabel ($ label , $ value );
20
+ $ this ->setLibraryId ($ identifier );
20
21
}
21
22
22
- public function setChecked ($ value= true ){
23
- if ($ value ===true ){
23
+ public function setChecked ($ value = true ) {
24
+ if ($ value === true ) {
24
25
$ this ->getField ()->setProperty ("checked " , "checked " );
25
- }else {
26
+ } else {
26
27
$ this ->getField ()->removeProperty ("checked " );
27
28
}
28
29
return $ this ;
@@ -32,24 +33,26 @@ public function setType($checkboxType) {
32
33
return $ this ->addToPropertyCtrl ("class " , $ checkboxType , CheckboxType::getConstants ());
33
34
}
34
35
35
- public function setLabel ($ label ,$ value= null ) {
36
- $ labelO= $ label ;
36
+ public function setLabel ($ label , $ value = null ) {
37
+ $ labelO = $ label ;
37
38
if (\is_string ($ label )) {
38
- $ labelO= new HtmlSemDoubleElement ("" , "label " , "" );
39
+ $ labelO = new HtmlSemDoubleElement ("" , "label " , "" );
39
40
$ labelO ->setContent ($ label );
40
- $ labelO ->setProperty ("for " , $ this ->getField ()->getIdentifier ());
41
- if (isset ($ value ))
41
+ $ labelO ->setProperty ("for " , $ this ->getField ()
42
+ ->getIdentifier ());
43
+ if (isset ($ value ))
42
44
$ labelO ->setProperty ("data-value " , $ value );
43
45
}
44
- $ this ->content ["label " ]= $ labelO ;
46
+ $ this ->content ["label " ] = $ labelO ;
45
47
}
46
48
47
49
public function setField ($ field ) {
48
- $ this ->content ["field " ]= $ field ;
50
+ $ this ->content ["field " ] = $ field ;
49
51
}
50
52
51
53
/**
52
54
* Returns the label or null
55
+ *
53
56
* @return mixed
54
57
*/
55
58
public function getLabel () {
@@ -59,6 +62,7 @@ public function getLabel() {
59
62
60
63
/**
61
64
* Return the field
65
+ *
62
66
* @return mixed
63
67
*/
64
68
public function getField () {
@@ -69,9 +73,9 @@ public function getField() {
69
73
* puts the label before or behind
70
74
*/
71
75
public function swapLabel () {
72
- $ label= $ this ->getLabel ();
76
+ $ label = $ this ->getLabel ();
73
77
unset($ this ->content ["label " ]);
74
- $ this ->content ["label " ]= $ label ;
78
+ $ this ->content ["label " ] = $ label ;
75
79
}
76
80
77
81
public function setReadonly () {
@@ -81,28 +85,33 @@ public function setReadonly() {
81
85
82
86
/**
83
87
* Attach $this to $selector and fire $action
84
- * @param string $selector jquery selector of the associated element
85
- * @param string $action action to execute : check, uncheck or NULL for toggle
88
+ *
89
+ * @param string $selector
90
+ * jquery selector of the associated element
91
+ * @param string $action
92
+ * action to execute : check, uncheck or NULL for toggle
86
93
* @return AbstractCheckbox
87
94
*/
88
- public function attachEvent ($ selector , $ action= NULL ) {
89
- if (isset ($ action )|| \is_numeric ($ action )===true ) {
90
- $ js= '$("#%identifier%").checkbox("attach events", " ' . $ selector. '", " ' . $ action. '"); ' ;
95
+ public function attachEvent ($ selector , $ action = NULL ) {
96
+ if (isset ($ action ) || \is_numeric ($ action ) === true ) {
97
+ $ js = '$("#%identifier%").checkbox("attach events", " ' . $ selector . '", " ' . $ action . '"); ' ;
91
98
} else {
92
- $ js= '$("#%identifier%").checkbox("attach events", " ' . $ selector. '"); ' ;
99
+ $ js = '$("#%identifier%").checkbox("attach events", " ' . $ selector . '"); ' ;
93
100
}
94
- $ js= \str_replace ("%identifier% " , $ this ->identifier , $ js );
101
+ $ js = \str_replace ("%identifier% " , $ this ->identifier , $ js );
95
102
return $ this ->executeOnRun ($ js );
96
103
}
97
104
98
105
/**
99
106
* Attach $this to an array of $action=>$selector
100
- * @param array $events associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
107
+ *
108
+ * @param array $events
109
+ * associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
101
110
* @return AbstractCheckbox
102
111
*/
103
- public function attachEvents ($ events= array ()) {
112
+ public function attachEvents ($ events = array ()) {
104
113
if (\is_array ($ events )) {
105
- foreach ( $ events as $ action => $ selector ) {
114
+ foreach ($ events as $ action => $ selector ) {
106
115
$ this ->attachEvent ($ selector , $ action );
107
116
}
108
117
}
@@ -113,24 +122,24 @@ public function setFitted() {
113
122
return $ this ->addToProperty ("class " , "fitted " );
114
123
}
115
124
116
- public function setOnChecked ($ jsCode ){
117
- $ this ->_params ["onChecked " ]= $ jsCode ;
125
+ public function setOnChecked ($ jsCode ) {
126
+ $ this ->_params ["onChecked " ] = $ jsCode ;
118
127
return $ this ;
119
128
}
120
129
121
- public function setOnUnchecked ($ jsCode ){
122
- $ this ->_params ["onUnchecked " ]= $ jsCode ;
130
+ public function setOnUnchecked ($ jsCode ) {
131
+ $ this ->_params ["onUnchecked " ] = $ jsCode ;
123
132
return $ this ;
124
133
}
125
134
126
- public function setOnChange ($ jsCode ){
127
- $ this ->_params ["onChange " ]= $ jsCode ;
135
+ public function setOnChange ($ jsCode ) {
136
+ $ this ->_params ["onChange " ] = $ jsCode ;
128
137
return $ this ;
129
138
}
130
139
131
140
public function run (JsUtils $ js ) {
132
- if (! isset ($ this ->_bsComponent ))
133
- $ this ->_bsComponent = $ js ->semantic ()->checkbox ("# " . $ this ->identifier , $ this ->_params );
141
+ if (! isset ($ this ->_bsComponent ))
142
+ $ this ->_bsComponent = $ js ->semantic ()->checkbox ("# " . $ this ->identifier , $ this ->_params );
134
143
return parent ::run ($ js );
135
144
}
136
145
}
0 commit comments