@@ -20,7 +20,7 @@ |
||
20 | 20 | $this->params["onUnchecked"]="%function(){".$value."}%"; |
21 | 21 | } |
22 | 22 | |
23 | - public function setOnChange($value){ |
|
23 | + public function setOnChange($value) { |
|
24 | 24 | $this->params["onChange"]="%function(){".$value."}%"; |
25 | 25 | } |
26 | 26 | //TODO other events implementation |
@@ -26,23 +26,23 @@ discard block |
||
26 | 26 | * @property boolean $_edition |
27 | 27 | * @property mixed _modelInstance |
28 | 28 | */ |
29 | -trait FieldAsTrait{ |
|
29 | +trait FieldAsTrait { |
|
30 | 30 | |
31 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
32 | - abstract public function setValueFunction($index,$callback); |
|
31 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
32 | + abstract public function setValueFunction($index, $callback); |
|
33 | 33 | abstract protected function _getFieldName($index); |
34 | 34 | abstract protected function _getFieldCaption($index); |
35 | - abstract protected function _buttonAsSubmit(HtmlButton &$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
35 | + abstract protected function _buttonAsSubmit(HtmlButton&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @param HtmlFormField $element |
39 | 39 | * @param array $attributes |
40 | 40 | */ |
41 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
42 | - if(isset($attributes["jsCallback"])){ |
|
41 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
42 | + if (isset($attributes["jsCallback"])) { |
|
43 | 43 | $callback=$attributes["jsCallback"]; |
44 | - if(\is_callable($callback)){ |
|
45 | - $callback($element,$this->_modelInstance,$index); |
|
44 | + if (\is_callable($callback)) { |
|
45 | + $callback($element, $this->_modelInstance, $index); |
|
46 | 46 | unset($attributes["jsCallback"]); |
47 | 47 | } |
48 | 48 | } |
@@ -52,43 +52,43 @@ discard block |
||
52 | 52 | $element->fromArray($attributes); |
53 | 53 | } |
54 | 54 | |
55 | - private function _getLabelField($caption,$icon=NULL){ |
|
56 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
55 | + private function _getLabelField($caption, $icon=NULL) { |
|
56 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
57 | 57 | return $label; |
58 | 58 | } |
59 | 59 | |
60 | 60 | |
61 | - protected function _addRules($element,&$attributes){ |
|
62 | - if(isset($attributes["rules"])){ |
|
61 | + protected function _addRules($element, &$attributes) { |
|
62 | + if (isset($attributes["rules"])) { |
|
63 | 63 | $rules=$attributes["rules"]; |
64 | - if(\is_array($rules)){ |
|
64 | + if (\is_array($rules)) { |
|
65 | 65 | $element->addRules($rules); |
66 | 66 | } |
67 | - else{ |
|
67 | + else { |
|
68 | 68 | $element->addRule($rules); |
69 | 69 | } |
70 | 70 | unset($attributes["rules"]); |
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - protected function _prepareFormFields(&$field,$name,&$attributes){ |
|
74 | + protected function _prepareFormFields(&$field, $name, &$attributes) { |
|
75 | 75 | $field->setName($name); |
76 | 76 | $this->_addRules($field, $attributes); |
77 | 77 | return $field; |
78 | 78 | } |
79 | 79 | |
80 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
81 | - $this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){ |
|
80 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
81 | + $this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){ |
|
82 | 82 | $caption=$this->_getFieldCaption($index); |
83 | 83 | $name=$this->_getFieldName($index); |
84 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
85 | - if(isset($attributes["name"])){ |
|
84 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
85 | + if (isset($attributes["name"])) { |
|
86 | 86 | $name=$attributes["name"]; |
87 | 87 | unset($attributes["name"]); |
88 | 88 | } |
89 | - $element=$elementCallback($id,$name,$value,$caption); |
|
90 | - if(\is_array($attributes)){ |
|
91 | - $this->_applyAttributes($element, $attributes,$index); |
|
89 | + $element=$elementCallback($id, $name, $value, $caption); |
|
90 | + if (\is_array($attributes)) { |
|
91 | + $this->_applyAttributes($element, $attributes, $index); |
|
92 | 92 | } |
93 | 93 | $element->setDisabled(!$this->_edition); |
94 | 94 | return $element; |
@@ -97,175 +97,175 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | |
100 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
101 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
102 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
100 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
101 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
102 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
103 | 103 | return $pb; |
104 | 104 | }); |
105 | 105 | return $this; |
106 | 106 | } |
107 | 107 | |
108 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
109 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
110 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
108 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
109 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
110 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
111 | 111 | return $rating; |
112 | 112 | }); |
113 | 113 | return $this; |
114 | 114 | } |
115 | 115 | |
116 | - public function fieldAsLabel($index,$icon=NULL){ |
|
117 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
118 | - $lbl=$this->_getLabelField($caption,$icon); |
|
116 | + public function fieldAsLabel($index, $icon=NULL) { |
|
117 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
118 | + $lbl=$this->_getLabelField($caption, $icon); |
|
119 | 119 | return $lbl; |
120 | 120 | }); |
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 | |
124 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
125 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
126 | - $header=new HtmlHeader($id,$niveau,$value); |
|
127 | - if(isset($icon)) |
|
124 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
125 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
126 | + $header=new HtmlHeader($id, $niveau, $value); |
|
127 | + if (isset($icon)) |
|
128 | 128 | $header->asIcon($icon, $value); |
129 | 129 | return $header; |
130 | - }, $index,$attributes,"header"); |
|
130 | + }, $index, $attributes, "header"); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
134 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
135 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
136 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
134 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
135 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
136 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
137 | 137 | return $image; |
138 | 138 | }); |
139 | 139 | return $this; |
140 | 140 | } |
141 | 141 | |
142 | - public function fieldAsFlag($index){ |
|
143 | - $this->setValueFunction($index,function($flag){ |
|
144 | - $flag=new HtmlFlag($this->_getFieldIdentifier("flag"),$flag); |
|
142 | + public function fieldAsFlag($index) { |
|
143 | + $this->setValueFunction($index, function($flag) { |
|
144 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
145 | 145 | return $flag; |
146 | 146 | }); |
147 | 147 | return $this; |
148 | 148 | } |
149 | 149 | |
150 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
151 | - return $this->_fieldAs(function($id,$name,$value){ |
|
152 | - $img=new HtmlImage($id,$value); |
|
150 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
151 | + return $this->_fieldAs(function($id, $name, $value) { |
|
152 | + $img=new HtmlImage($id, $value); |
|
153 | 153 | $img->asAvatar(); |
154 | 154 | return $img; |
155 | - }, $index,$attributes,"avatar"); |
|
155 | + }, $index, $attributes, "avatar"); |
|
156 | 156 | } |
157 | 157 | |
158 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
159 | - return $this->_fieldAs(function($id,$name,$value) use($attributes){ |
|
160 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
158 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
159 | + return $this->_fieldAs(function($id, $name, $value) use($attributes){ |
|
160 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
161 | 161 | return $this->_prepareFormFields($input, $name, $attributes); |
162 | - }, $index,$attributes,"radio"); |
|
162 | + }, $index, $attributes, "radio"); |
|
163 | 163 | } |
164 | 164 | |
165 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
166 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
167 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
168 | - }, $index,$attributes,"radios"); |
|
165 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
166 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
167 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
168 | + }, $index, $attributes, "radios"); |
|
169 | 169 | } |
170 | 170 | |
171 | - public function fieldAsInput($index,$attributes=NULL){ |
|
172 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
173 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
171 | + public function fieldAsInput($index, $attributes=NULL) { |
|
172 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
173 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
174 | 174 | return $this->_prepareFormFields($input, $name, $attributes); |
175 | - }, $index,$attributes,"input"); |
|
175 | + }, $index, $attributes, "input"); |
|
176 | 176 | } |
177 | 177 | |
178 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
179 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
180 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
178 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
179 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
180 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
181 | 181 | return $this->_prepareFormFields($textarea, $name, $attributes); |
182 | - }, $index,$attributes,"textarea"); |
|
182 | + }, $index, $attributes, "textarea"); |
|
183 | 183 | } |
184 | 184 | |
185 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
186 | - if(!\is_array($attributes)){ |
|
185 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
186 | + if (!\is_array($attributes)) { |
|
187 | 187 | $attributes=[]; |
188 | 188 | } |
189 | 189 | $attributes["imputType"]="hidden"; |
190 | - return $this->fieldAsInput($index,$attributes); |
|
190 | + return $this->fieldAsInput($index, $attributes); |
|
191 | 191 | } |
192 | 192 | |
193 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
194 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($attributes){ |
|
195 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
193 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
194 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($attributes){ |
|
195 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
196 | 196 | $input->setChecked(JString::isBooleanTrue($value)); |
197 | 197 | return $this->_prepareFormFields($input, $name, $attributes); |
198 | - }, $index,$attributes,"ck"); |
|
198 | + }, $index, $attributes, "ck"); |
|
199 | 199 | } |
200 | 200 | |
201 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
202 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple,$attributes){ |
|
203 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
204 | - $dd->asSelect($name,$multiple); |
|
201 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
202 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple, $attributes){ |
|
203 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
204 | + $dd->asSelect($name, $multiple); |
|
205 | 205 | return $this->_prepareFormFields($dd, $name, $attributes); |
206 | - }, $index,$attributes,"dd"); |
|
206 | + }, $index, $attributes, "dd"); |
|
207 | 207 | } |
208 | 208 | |
209 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
210 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
211 | - $mess= new HtmlMessage("message-".$id,$caption); |
|
209 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
210 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
211 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
212 | 212 | $mess->addHeader($value); |
213 | 213 | return $mess; |
214 | - }, $index,$attributes,"message"); |
|
214 | + }, $index, $attributes, "message"); |
|
215 | 215 | } |
216 | 216 | |
217 | - public function fieldAsLink($index,$attributes=NULL){ |
|
218 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
219 | - $lnk= new HtmlLink("message-".$id,"#",$caption); |
|
217 | + public function fieldAsLink($index, $attributes=NULL) { |
|
218 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
219 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
220 | 220 | return $lnk; |
221 | - }, $index,$attributes,"link"); |
|
221 | + }, $index, $attributes, "link"); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /**Change fields type |
225 | 225 | * @param array $types an array or associative array $type=>$attributes |
226 | 226 | */ |
227 | - public function fieldsAs(array $types){ |
|
227 | + public function fieldsAs(array $types) { |
|
228 | 228 | $i=0; |
229 | - if(JArray::isAssociative($types)){ |
|
230 | - foreach ($types as $type=>$attributes){ |
|
231 | - if(\is_int($type)) |
|
232 | - $this->fieldAs($i++,$attributes,[]); |
|
233 | - else{ |
|
234 | - $type=preg_replace('/\d/', '', $type ); |
|
235 | - $this->fieldAs($i++,$type,$attributes); |
|
229 | + if (JArray::isAssociative($types)) { |
|
230 | + foreach ($types as $type=>$attributes) { |
|
231 | + if (\is_int($type)) |
|
232 | + $this->fieldAs($i++, $attributes, []); |
|
233 | + else { |
|
234 | + $type=preg_replace('/\d/', '', $type); |
|
235 | + $this->fieldAs($i++, $type, $attributes); |
|
236 | 236 | } |
237 | 237 | } |
238 | - }else{ |
|
239 | - foreach ($types as $type){ |
|
240 | - $this->fieldAs($i++,$type); |
|
238 | + } else { |
|
239 | + foreach ($types as $type) { |
|
240 | + $this->fieldAs($i++, $type); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
245 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
246 | 246 | $method="fieldAs".\ucfirst($type); |
247 | - if(\method_exists($this, $method)){ |
|
248 | - if(!\is_array($attributes)){ |
|
247 | + if (\method_exists($this, $method)) { |
|
248 | + if (!\is_array($attributes)) { |
|
249 | 249 | $attributes=[$index]; |
250 | - }else{ |
|
250 | + } else { |
|
251 | 251 | \array_unshift($attributes, $index); |
252 | 252 | } |
253 | - \call_user_func_array([$this,$method], $attributes); |
|
253 | + \call_user_func_array([$this, $method], $attributes); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
258 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
259 | - $button=new HtmlButton($id,$caption,$cssStyle); |
|
260 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
257 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
258 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
259 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
260 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
261 | 261 | return $button; |
262 | - }, $index,$attributes,"submit"); |
|
262 | + }, $index, $attributes, "submit"); |
|
263 | 263 | } |
264 | 264 | |
265 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
266 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
267 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
265 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
266 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
267 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
268 | 268 | return $button; |
269 | - }, $index,$attributes,"button"); |
|
269 | + }, $index, $attributes, "button"); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | \ No newline at end of file |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | $this->setLabel($label); |
20 | 20 | } |
21 | 21 | |
22 | - public function setChecked($value=true){ |
|
23 | - if($value===true){ |
|
22 | + public function setChecked($value=true) { |
|
23 | + if ($value===true) { |
|
24 | 24 | $this->getField()->setProperty("checked", "checked"); |
25 | - }else{ |
|
25 | + } else { |
|
26 | 26 | $this->getField()->removeProperty("checked"); |
27 | 27 | } |
28 | 28 | return $this; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox |
85 | 85 | */ |
86 | 86 | public function attachEvent($selector, $action=NULL) { |
87 | - if (isset($action)||\is_numeric($action)===true) { |
|
87 | + if (isset($action) || \is_numeric($action)===true) { |
|
88 | 88 | $js='$("#%identifier%").checkbox("attach events", "'.$selector.'", "'.$action.'");'; |
89 | 89 | } else { |
90 | 90 | $js='$("#%identifier%").checkbox("attach events", "'.$selector.'");'; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function attachEvents($events=array()) { |
102 | 102 | if (\is_array($events)) { |
103 | - foreach ( $events as $action => $selector ) { |
|
103 | + foreach ($events as $action => $selector) { |
|
104 | 104 | $this->attachEvent($selector, $action); |
105 | 105 | } |
106 | 106 | } |
@@ -111,23 +111,23 @@ discard block |
||
111 | 111 | return $this->addToProperty("class", "fitted"); |
112 | 112 | } |
113 | 113 | |
114 | - public function setOnChecked($jsCode){ |
|
114 | + public function setOnChecked($jsCode) { |
|
115 | 115 | $this->_params["onChecked"]=$jsCode; |
116 | 116 | return $this; |
117 | 117 | } |
118 | 118 | |
119 | - public function setOnUnchecked($jsCode){ |
|
119 | + public function setOnUnchecked($jsCode) { |
|
120 | 120 | $this->_params["onUnchecked"]=$jsCode; |
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 | |
124 | - public function setOnChange($jsCode){ |
|
124 | + public function setOnChange($jsCode) { |
|
125 | 125 | $this->_params["onChange"]=$jsCode; |
126 | 126 | return $this; |
127 | 127 | } |
128 | 128 | |
129 | 129 | public function run(JsUtils $js) { |
130 | - $this->_bsComponent=$js->semantic()->checkbox("#" . $this->identifier, $this->_params); |
|
130 | + $this->_bsComponent=$js->semantic()->checkbox("#".$this->identifier, $this->_params); |
|
131 | 131 | return parent::run($js); |
132 | 132 | } |
133 | 133 | } |
134 | 134 | \ No newline at end of file |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(JsUtils $js=NULL) { |
21 | 21 | parent::__construct($js); |
22 | - $this->events=array (); |
|
22 | + $this->events=array(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | protected function compileEvents() { |
26 | - foreach ( $this->events as $event => $jsCode ) { |
|
26 | + foreach ($this->events as $event => $jsCode) { |
|
27 | 27 | $itemSelector=JString::getValueBetween($event); |
28 | 28 | //echo $itemSelector.":::".$jsCode."<br>"; |
29 | - if($event=="execute"){ |
|
29 | + if ($event=="execute") { |
|
30 | 30 | $this->jquery_code_for_compile []=$jsCode; |
31 | - }else if($event=="beforeExecute"){ |
|
31 | + } else if ($event=="beforeExecute") { |
|
32 | 32 | \array_unshift($this->jquery_code_for_compile, $jsCode); |
33 | - }else{ |
|
33 | + } else { |
|
34 | 34 | $selector=$this->_createSelector($itemSelector, $this->attachTo); |
35 | 35 | $this->jquery_code_for_compile []="$( \"".$selector."\" ).on(\"".$event."\" , function( event, data ) {".$jsCode."});"; |
36 | 36 | } |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - protected function _createSelector($itemSelector,$selector){ |
|
41 | - if(!isset($itemSelector)) |
|
40 | + protected function _createSelector($itemSelector, $selector) { |
|
41 | + if (!isset($itemSelector)) |
|
42 | 42 | $itemSelector=$this->itemSelector; |
43 | - if(isset($itemSelector) && $itemSelector!=="") |
|
43 | + if (isset($itemSelector) && $itemSelector!=="") |
|
44 | 44 | $selector.=" ".$itemSelector; |
45 | 45 | return $selector; |
46 | 46 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $result=implode("\n", $this->jquery_code_for_compile); |
50 | 50 | $result=str_ireplace("\"%", "", $result); |
51 | 51 | $result=str_ireplace("%\"", "", $result); |
52 | - $result=str_replace(array ( |
|
52 | + $result=str_replace(array( |
|
53 | 53 | "\\n", |
54 | 54 | "\\r", |
55 | 55 | "\\t" |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | public function getScript() { |
61 | 61 | $allParams=$this->params; |
62 | - $this->jquery_code_for_compile=array (); |
|
62 | + $this->jquery_code_for_compile=array(); |
|
63 | 63 | $this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).");"; |
64 | 64 | $this->compileEvents(); |
65 | 65 | return $this->compileJQueryCode(); |
@@ -2,63 +2,63 @@ |
||
2 | 2 | namespace Ajax\service; |
3 | 3 | class JString { |
4 | 4 | |
5 | - public static function contains($hay,$needle){ |
|
6 | - return strpos($hay, $needle) !== false; |
|
5 | + public static function contains($hay, $needle) { |
|
6 | + return strpos($hay, $needle)!==false; |
|
7 | 7 | } |
8 | 8 | public static function startswith($hay, $needle) { |
9 | - return substr($hay, 0, strlen($needle)) === $needle; |
|
9 | + return substr($hay, 0, strlen($needle))===$needle; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public static function endswith($hay, $needle) { |
13 | - return substr($hay, -strlen($needle)) === $needle; |
|
13 | + return substr($hay, -strlen($needle))===$needle; |
|
14 | 14 | } |
15 | 15 | |
16 | - public static function isNull($s){ |
|
16 | + public static function isNull($s) { |
|
17 | 17 | return (!isset($s) || NULL===$s || ""===$s); |
18 | 18 | } |
19 | - public static function isNotNull($s){ |
|
19 | + public static function isNotNull($s) { |
|
20 | 20 | return (isset($s) && NULL!==$s && ""!==$s); |
21 | 21 | } |
22 | 22 | |
23 | - public static function isBoolean($value){ |
|
23 | + public static function isBoolean($value) { |
|
24 | 24 | return \is_bool($value) || $value==1 || $value==0; |
25 | 25 | } |
26 | 26 | |
27 | - public static function isBooleanTrue($value){ |
|
27 | + public static function isBooleanTrue($value) { |
|
28 | 28 | return $value==1 || $value; |
29 | 29 | } |
30 | 30 | |
31 | - public static function isBooleanFalse($value){ |
|
31 | + public static function isBooleanFalse($value) { |
|
32 | 32 | return $value==0 || !$value; |
33 | 33 | } |
34 | 34 | |
35 | - public static function camelCaseToSeparated($input,$separator=" "){ |
|
35 | + public static function camelCaseToSeparated($input, $separator=" ") { |
|
36 | 36 | return strtolower(preg_replace('/(?<!^)[A-Z]/', $separator.'$0', $input)); |
37 | 37 | } |
38 | 38 | |
39 | - public static function replaceAtFirst($subject,$from, $to){ |
|
40 | - $from = '/\A'.preg_quote($from, '/').'/'; |
|
39 | + public static function replaceAtFirst($subject, $from, $to) { |
|
40 | + $from='/\A'.preg_quote($from, '/').'/'; |
|
41 | 41 | return \preg_replace($from, $to, $subject, 1); |
42 | 42 | } |
43 | 43 | |
44 | - public static function replaceAtLast($subject,$from, $to){ |
|
45 | - $from = '/'.preg_quote($from, '/').'\z/'; |
|
44 | + public static function replaceAtLast($subject, $from, $to) { |
|
45 | + $from='/'.preg_quote($from, '/').'\z/'; |
|
46 | 46 | return \preg_replace($from, $to, $subject, 1); |
47 | 47 | } |
48 | 48 | |
49 | - public static function replaceAtFirstAndLast($subject,$fromFirst,$toFirst,$fromLast,$toLast){ |
|
49 | + public static function replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast) { |
|
50 | 50 | $s=self::replaceAtFirst($subject, $fromFirst, $toFirst); |
51 | 51 | return self::replaceAtLast($s, $fromLast, $toLast); |
52 | 52 | } |
53 | 53 | |
54 | - public static function getValueBetween(&$str,$before="{{",$after="}}"){ |
|
54 | + public static function getValueBetween(&$str, $before="{{", $after="}}") { |
|
55 | 55 | $matches=[]; |
56 | 56 | $result=null; |
57 | 57 | $_before=\preg_quote($before); |
58 | 58 | $_after=\preg_quote($after); |
59 | - if(\preg_match('/'.$_before.'(.*?)'.$_after.'/s', $str, $matches)===1){ |
|
59 | + if (\preg_match('/'.$_before.'(.*?)'.$_after.'/s', $str, $matches)===1) { |
|
60 | 60 | $result=$matches[1]; |
61 | - $str=\str_replace($before.$result.$after,"", $str); |
|
61 | + $str=\str_replace($before.$result.$after, "", $str); |
|
62 | 62 | } |
63 | 63 | return $result; |
64 | 64 | } |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | |
28 | 28 | public function __construct($identifier, $rowCount, $colCount) { |
29 | 29 | parent::__construct($identifier, "table", "ui table"); |
30 | - $this->content=array (); |
|
30 | + $this->content=array(); |
|
31 | 31 | $this->setRowCount($rowCount, $colCount); |
32 | - $this->_variations=[ Variation::CELLED,Variation::PADDED,Variation::COMPACT ]; |
|
33 | - $this->_compileParts=["thead","tbody","tfoot"]; |
|
32 | + $this->_variations=[Variation::CELLED, Variation::PADDED, Variation::COMPACT]; |
|
33 | + $this->_compileParts=["thead", "tbody", "tfoot"]; |
|
34 | 34 | $this->_afterCompileEvents=[]; |
35 | 35 | } |
36 | 36 | |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * @return HtmlTableContent |
49 | 49 | */ |
50 | 50 | public function getPart($key) { |
51 | - if (\array_key_exists($key, $this->content) === false) { |
|
51 | + if (\array_key_exists($key, $this->content)===false) { |
|
52 | 52 | $this->content[$key]=new HtmlTableContent("", $key); |
53 | - if ($key !== "tbody") { |
|
53 | + if ($key!=="tbody") { |
|
54 | 54 | $this->content[$key]->setRowCount(1, $this->_colCount); |
55 | 55 | } |
56 | 56 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return boolean |
96 | 96 | */ |
97 | 97 | public function hasPart($key) { |
98 | - return \array_key_exists($key, $this->content) === true; |
|
98 | + return \array_key_exists($key, $this->content)===true; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | private function colAlign($colIndex, $function) { |
202 | 202 | if (\is_array($colIndex)) { |
203 | - foreach ( $colIndex as $cIndex ) { |
|
203 | + foreach ($colIndex as $cIndex) { |
|
204 | 204 | $this->colAlign($cIndex, $function); |
205 | 205 | } |
206 | 206 | } else { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
240 | 240 | */ |
241 | 241 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
242 | - if(\sizeof($this->_compileParts)<3){ |
|
242 | + if (\sizeof($this->_compileParts)<3) { |
|
243 | 243 | $this->_template="%content%"; |
244 | 244 | $this->refresh(); |
245 | 245 | } |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | |
250 | 250 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
251 | 251 | if ($this->propertyContains("class", "sortable")) { |
252 | - $this->addEvent("execute", "$('#" . $this->identifier . "').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
252 | + $this->addEvent("execute", "$('#".$this->identifier."').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
253 | 253 | } |
254 | - if(isset($this->_activeRowSelector)){ |
|
254 | + if (isset($this->_activeRowSelector)) { |
|
255 | 255 | $this->_activeRowSelector->compile(); |
256 | 256 | } |
257 | 257 | } |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | public function fromDatabaseObject($object, $function) { |
266 | 266 | $result=$function($object); |
267 | 267 | if (\is_array($result)) { |
268 | - $result= $this->addRow($function($object)); |
|
268 | + $result=$this->addRow($function($object)); |
|
269 | 269 | } else { |
270 | - $result= $this->getBody()->_addRow($result); |
|
270 | + $result=$this->getBody()->_addRow($result); |
|
271 | 271 | } |
272 | - if(isset($this->_afterCompileEvents["onNewRow"])){ |
|
273 | - if(\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
274 | - $this->_afterCompileEvents["onNewRow"]($result,$object); |
|
272 | + if (isset($this->_afterCompileEvents["onNewRow"])) { |
|
273 | + if (\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
274 | + $this->_afterCompileEvents["onNewRow"]($result, $object); |
|
275 | 275 | } |
276 | 276 | return $result; |
277 | 277 | } |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | return $this; |
286 | 286 | } |
287 | 287 | |
288 | - public function refresh(){ |
|
288 | + public function refresh() { |
|
289 | 289 | $this->_footer=$this->getFooter(); |
290 | 290 | $this->addEvent("execute", '$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");'); |
291 | 291 | } |
292 | 292 | |
293 | - public function run(JsUtils $js){ |
|
294 | - $result= parent::run($js); |
|
295 | - if(isset($this->_footer)) |
|
293 | + public function run(JsUtils $js) { |
|
294 | + $result=parent::run($js); |
|
295 | + if (isset($this->_footer)) |
|
296 | 296 | $this->_footer->run($js); |
297 | 297 | return $result; |
298 | 298 | } |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | return $this; |
309 | 309 | } |
310 | 310 | |
311 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
312 | - $this->_activeRowSelector=new ActiveRow($this,$class,$event,$multiple); |
|
311 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
312 | + $this->_activeRowSelector=new ActiveRow($this, $class, $event, $multiple); |
|
313 | 313 | return $this; |
314 | 314 | } |
315 | 315 | } |
316 | 316 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace Ajax\semantic\html\collections\table\traits; |
3 | 3 | |
4 | -trait TableTrait{ |
|
4 | +trait TableTrait { |
|
5 | 5 | /** |
6 | 6 | * @return HtmlTable |
7 | 7 | */ |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | abstract public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false); |
10 | 10 | abstract public function getOn($event, $url, $responseElement="", $parameters=array()); |
11 | 11 | |
12 | - protected function addToPropertyTable($property,$value){ |
|
12 | + protected function addToPropertyTable($property, $value) { |
|
13 | 13 | return $this->getTable()->addToProperty($property, $value); |
14 | 14 | } |
15 | 15 | |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | public function setBasic($very=false) { |
21 | 21 | $table=$this->getTable(); |
22 | 22 | if ($very) |
23 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
24 | - return $table->addToPropertyCtrl("class", "basic", array ("basic" )); |
|
23 | + $table->addToPropertyCtrl("class", "very", array("very")); |
|
24 | + return $table->addToPropertyCtrl("class", "basic", array("basic")); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function setCompact($very=false) { |
28 | 28 | $table=$this->getTable(); |
29 | 29 | if ($very) |
30 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
31 | - return $table->addToPropertyCtrl("class", "compact", array ("compact" )); |
|
30 | + $table->addToPropertyCtrl("class", "very", array("very")); |
|
31 | + return $table->addToPropertyCtrl("class", "compact", array("compact")); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function setCollapsing() { |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | return $this->addToPropertyTable("class", "striped"); |
68 | 68 | } |
69 | 69 | |
70 | - public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false){ |
|
71 | - $this->onRowClick($jsCode,$stopPropagation,$preventDefault); |
|
70 | + public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false) { |
|
71 | + $this->onRowClick($jsCode, $stopPropagation, $preventDefault); |
|
72 | 72 | } |
73 | 73 | |
74 | - public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){ |
|
75 | - $this->getTable()->addEvent($event."{{tr}}",$jsCode,$stopPropagation,$preventDefault); |
|
74 | + public function onRow($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
|
75 | + $this->getTable()->addEvent($event."{{tr}}", $jsCode, $stopPropagation, $preventDefault); |
|
76 | 76 | } |
77 | 77 | |
78 | - public function getOnRow($event, $url, $responseElement="", $parameters=array()){ |
|
79 | - $parameters=\array_merge($parameters,["stopPropagation"=>false,"preventDefault"=>false]); |
|
80 | - return $this->getTable()->getOn($event."{{tbody tr}}", $url,$responseElement,$parameters); |
|
78 | + public function getOnRow($event, $url, $responseElement="", $parameters=array()) { |
|
79 | + $parameters=\array_merge($parameters, ["stopPropagation"=>false, "preventDefault"=>false]); |
|
80 | + return $this->getTable()->getOn($event."{{tbody tr}}", $url, $responseElement, $parameters); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param string $event |
22 | 22 | * @param boolean $multiple |
23 | 23 | */ |
24 | - public function __construct($table,$class="active",$event="click",$multiple=false){ |
|
24 | + public function __construct($table, $class="active", $event="click", $multiple=false) { |
|
25 | 25 | $this->table=$table; |
26 | 26 | $this->class=$class; |
27 | 27 | $this->event=$event; |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | return $this; |
56 | 56 | } |
57 | 57 | |
58 | - public function compile(){ |
|
58 | + public function compile() { |
|
59 | 59 | $multiple=""; |
60 | - if(!$this->multiple){ |
|
60 | + if (!$this->multiple) { |
|
61 | 61 | $multiple="$(this).closest('tbody').children('tr').removeClass('".$this->class."');"; |
62 | 62 | } |
63 | - $this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');",false,false); |
|
63 | + $this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');", false, false); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | } |
67 | 67 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | */ |
25 | 25 | class DataTable extends Widget { |
26 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
26 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
27 | 27 | protected $_searchField; |
28 | 28 | protected $_urls; |
29 | 29 | protected $_pagination; |
@@ -39,35 +39,35 @@ discard block |
||
39 | 39 | protected $_sortable; |
40 | 40 | |
41 | 41 | |
42 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
43 | - parent::__construct($identifier, $model,$modelInstance); |
|
44 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
42 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
43 | + parent::__construct($identifier, $model, $modelInstance); |
|
44 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
45 | 45 | $this->_urls=[]; |
46 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
46 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
47 | 47 | $this->_emptyMessage->setIcon("info circle"); |
48 | 48 | } |
49 | 49 | |
50 | - public function run(JsUtils $js){ |
|
51 | - if($this->_hasCheckboxes && isset($js)){ |
|
50 | + public function run(JsUtils $js) { |
|
51 | + if ($this->_hasCheckboxes && isset($js)) { |
|
52 | 52 | $this->_runCheckboxes($js); |
53 | 53 | } |
54 | - if($this->_visibleHover){ |
|
55 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
56 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
54 | + if ($this->_visibleHover) { |
|
55 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
56 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
57 | 57 | } |
58 | - if(\is_array($this->_deleteBehavior)) |
|
59 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
60 | - if(\is_array($this->_editBehavior)) |
|
61 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
58 | + if (\is_array($this->_deleteBehavior)) |
|
59 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
60 | + if (\is_array($this->_editBehavior)) |
|
61 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
62 | 62 | return parent::run($js); |
63 | 63 | } |
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
68 | - if(isset($this->_urls[$op])){ |
|
69 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
70 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
67 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
68 | + if (isset($this->_urls[$op])) { |
|
69 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
70 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -80,137 +80,137 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
84 | - if(!$this->_generated){ |
|
83 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
84 | + if (!$this->_generated) { |
|
85 | 85 | $this->_instanceViewer->setInstance($this->_model); |
86 | 86 | $captions=$this->_instanceViewer->getCaptions(); |
87 | 87 | |
88 | 88 | $table=$this->content["table"]; |
89 | 89 | |
90 | - if($this->_hasCheckboxes){ |
|
90 | + if ($this->_hasCheckboxes) { |
|
91 | 91 | $this->_generateMainCheckbox($captions); |
92 | 92 | } |
93 | 93 | |
94 | 94 | $table->setRowCount(0, \sizeof($captions)); |
95 | - $this->_generateHeader($table,$captions); |
|
95 | + $this->_generateHeader($table, $captions); |
|
96 | 96 | |
97 | - if(isset($this->_compileParts)) |
|
97 | + if (isset($this->_compileParts)) |
|
98 | 98 | $table->setCompileParts($this->_compileParts); |
99 | 99 | |
100 | - if(isset($this->_searchField) && isset($js)){ |
|
101 | - if(isset($this->_urls["refresh"])) |
|
102 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
100 | + if (isset($this->_searchField) && isset($js)) { |
|
101 | + if (isset($this->_urls["refresh"])) |
|
102 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $this->_generateContent($table); |
106 | 106 | |
107 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
107 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
108 | 108 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
109 | 109 | } |
110 | 110 | |
111 | - if(isset($this->_toolbar)){ |
|
111 | + if (isset($this->_toolbar)) { |
|
112 | 112 | $this->_setToolbarPosition($table, $captions); |
113 | 113 | } |
114 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
115 | - $this->_generatePagination($table,$js); |
|
114 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
115 | + $this->_generatePagination($table, $js); |
|
116 | 116 | } |
117 | 117 | |
118 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
118 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
119 | 119 | $this->_compileForm(); |
120 | 120 | |
121 | 121 | $this->_generated=true; |
122 | 122 | } |
123 | - return parent::compile($js,$view); |
|
123 | + return parent::compile($js, $view); |
|
124 | 124 | } |
125 | 125 | |
126 | - protected function _generateHeader(HtmlTable $table,$captions){ |
|
126 | + protected function _generateHeader(HtmlTable $table, $captions) { |
|
127 | 127 | $table->setHeaderValues($captions); |
128 | - if(isset($this->_sortable)){ |
|
128 | + if (isset($this->_sortable)) { |
|
129 | 129 | $table->setSortable($this->_sortable); |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | |
134 | 134 | |
135 | - protected function _generateContent($table){ |
|
135 | + protected function _generateContent($table) { |
|
136 | 136 | $objects=$this->_modelInstance; |
137 | - if(isset($this->_pagination)){ |
|
137 | + if (isset($this->_pagination)) { |
|
138 | 138 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
139 | 139 | } |
140 | 140 | InstanceViewer::setIndex(0); |
141 | 141 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
142 | 142 | return $this->_generateRow($instance, $table); |
143 | 143 | }); |
144 | - if($table->getRowCount()==0){ |
|
144 | + if ($table->getRowCount()==0) { |
|
145 | 145 | $result=$table->addRow(); |
146 | 146 | $result->mergeRow(); |
147 | 147 | $result->setValues([$this->_emptyMessage]); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - protected function _generateRow($instance,&$table,$checkedClass=null){ |
|
151 | + protected function _generateRow($instance, &$table, $checkedClass=null) { |
|
152 | 152 | $this->_instanceViewer->setInstance($instance); |
153 | 153 | InstanceViewer::$index++; |
154 | - $values= $this->_instanceViewer->getValues(); |
|
154 | + $values=$this->_instanceViewer->getValues(); |
|
155 | 155 | $id=$this->_instanceViewer->getIdentifier(); |
156 | - if($this->_hasCheckboxes){ |
|
157 | - $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,""); |
|
156 | + if ($this->_hasCheckboxes) { |
|
157 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
158 | 158 | $ck->setOnChange("event.stopPropagation();"); |
159 | 159 | $field=$ck->getField(); |
160 | - $field->setProperty("value",$id); |
|
160 | + $field->setProperty("value", $id); |
|
161 | 161 | $field->setProperty("name", "selection[]"); |
162 | - if(isset($checkedClass)) |
|
162 | + if (isset($checkedClass)) |
|
163 | 163 | $field->setClass($checkedClass); |
164 | 164 | \array_unshift($values, $ck); |
165 | 165 | } |
166 | 166 | $result=$table->newRow(); |
167 | 167 | $result->setIdentifier($this->identifier."-tr-".$id); |
168 | - $result->setProperty("data-ajax",$id); |
|
168 | + $result->setProperty("data-ajax", $id); |
|
169 | 169 | $result->setValues($values); |
170 | - $result->addToProperty("class",$this->_rowClass); |
|
170 | + $result->addToProperty("class", $this->_rowClass); |
|
171 | 171 | return $result; |
172 | 172 | } |
173 | 173 | |
174 | - protected function _generatePagination($table,$js=NULL){ |
|
175 | - if(isset($this->_toolbar)){ |
|
176 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
174 | + protected function _generatePagination($table, $js=NULL) { |
|
175 | + if (isset($this->_toolbar)) { |
|
176 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
177 | 177 | $this->_toolbar->setFloated("left"); |
178 | 178 | } |
179 | 179 | $footer=$table->getFooter(); |
180 | 180 | $footer->mergeCol(); |
181 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
181 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
182 | 182 | $menu->floatRight(); |
183 | 183 | $menu->setActiveItem($this->_pagination->getPage()-1); |
184 | 184 | $footer->addValues($menu); |
185 | - $this->_associatePaginationBehavior($menu,$js); |
|
185 | + $this->_associatePaginationBehavior($menu, $js); |
|
186 | 186 | } |
187 | 187 | |
188 | - protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){ |
|
189 | - if(isset($this->_urls["refresh"])){ |
|
190 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
188 | + protected function _associatePaginationBehavior(HtmlMenu $menu, JsUtils $js=NULL) { |
|
189 | + if (isset($this->_urls["refresh"])) { |
|
190 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - protected function _getFieldName($index){ |
|
194 | + protected function _getFieldName($index) { |
|
195 | 195 | return parent::_getFieldName($index)."[]"; |
196 | 196 | } |
197 | 197 | |
198 | - protected function _getFieldCaption($index){ |
|
198 | + protected function _getFieldCaption($index) { |
|
199 | 199 | return null; |
200 | 200 | } |
201 | 201 | |
202 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
203 | - switch ($this->_toolbarPosition){ |
|
202 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
203 | + switch ($this->_toolbarPosition) { |
|
204 | 204 | case PositionInTable::BEFORETABLE: |
205 | 205 | case PositionInTable::AFTERTABLE: |
206 | - if(isset($this->_compileParts)===false){ |
|
206 | + if (isset($this->_compileParts)===false) { |
|
207 | 207 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
208 | 208 | } |
209 | 209 | break; |
210 | 210 | case PositionInTable::HEADER: |
211 | 211 | case PositionInTable::FOOTER: |
212 | 212 | case PositionInTable::BODY: |
213 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
213 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
214 | 214 | break; |
215 | 215 | } |
216 | 216 | } |
@@ -222,23 +222,23 @@ discard block |
||
222 | 222 | * @param callable $callback function called after the field compilation |
223 | 223 | * @return DataTable |
224 | 224 | */ |
225 | - public function afterCompile($index,$callback){ |
|
226 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
225 | + public function afterCompile($index, $callback) { |
|
226 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
227 | 227 | return $this; |
228 | 228 | } |
229 | 229 | |
230 | - private function addToolbarRow($part,$table,$captions){ |
|
230 | + private function addToolbarRow($part, $table, $captions) { |
|
231 | 231 | $hasPart=$table->hasPart($part); |
232 | - if($hasPart){ |
|
232 | + if ($hasPart) { |
|
233 | 233 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
234 | - }else{ |
|
234 | + } else { |
|
235 | 235 | $row=$table->getPart($part)->getRow(0); |
236 | 236 | } |
237 | 237 | $row->mergeCol(); |
238 | 238 | $row->setValues([$this->_toolbar]); |
239 | 239 | } |
240 | 240 | |
241 | - public function getHtmlComponent(){ |
|
241 | + public function getHtmlComponent() { |
|
242 | 242 | return $this->content["table"]; |
243 | 243 | } |
244 | 244 | |
@@ -252,12 +252,12 @@ discard block |
||
252 | 252 | * @return DataTable |
253 | 253 | */ |
254 | 254 | public function setUrls($urls) { |
255 | - if(\is_array($urls)){ |
|
256 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
257 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
258 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
259 | - }else{ |
|
260 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
255 | + if (\is_array($urls)) { |
|
256 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
257 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
258 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
259 | + } else { |
|
260 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
261 | 261 | } |
262 | 262 | return $this; |
263 | 263 | } |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param number $pages_visibles The number of visible pages in the Pagination component |
271 | 271 | * @return DataTable |
272 | 272 | */ |
273 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
274 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
273 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
274 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
275 | 275 | return $this; |
276 | 276 | } |
277 | 277 | |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * @param number $pages_visibles The number of visible pages in the Pagination component |
283 | 283 | * @return DataTable |
284 | 284 | */ |
285 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
286 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
285 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
286 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
287 | 287 | return $this; |
288 | 288 | } |
289 | 289 | |
@@ -293,20 +293,20 @@ discard block |
||
293 | 293 | * @param array $compileParts |
294 | 294 | * @return DataTable |
295 | 295 | */ |
296 | - public function refresh($compileParts=["tbody"]){ |
|
296 | + public function refresh($compileParts=["tbody"]) { |
|
297 | 297 | $this->_compileParts=$compileParts; |
298 | 298 | return $this; |
299 | 299 | } |
300 | 300 | |
301 | 301 | |
302 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
302 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
303 | 303 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
304 | 304 | } |
305 | 305 | |
306 | - public function getSearchField(){ |
|
307 | - if(isset($this->_searchField)===false){ |
|
308 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
309 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
306 | + public function getSearchField() { |
|
307 | + if (isset($this->_searchField)===false) { |
|
308 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
309 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
310 | 310 | } |
311 | 311 | return $this->_searchField; |
312 | 312 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | return $this; |
323 | 323 | } |
324 | 324 | |
325 | - public function asForm(){ |
|
325 | + public function asForm() { |
|
326 | 326 | return $this->getForm(); |
327 | 327 | } |
328 | 328 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | |
331 | 331 | protected function getTargetSelector() { |
332 | 332 | $result=$this->_targetSelector; |
333 | - if(!isset($result)) |
|
333 | + if (!isset($result)) |
|
334 | 334 | $result="#".$this->identifier; |
335 | 335 | return $result; |
336 | 336 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | } |
347 | 347 | |
348 | 348 | public function getRefreshSelector() { |
349 | - if(isset($this->_refreshSelector)) |
|
349 | + if (isset($this->_refreshSelector)) |
|
350 | 350 | return $this->_refreshSelector; |
351 | 351 | return "#".$this->identifier." tbody"; |
352 | 352 | } |
@@ -360,9 +360,9 @@ discard block |
||
360 | 360 | * {@inheritDoc} |
361 | 361 | * @see \Ajax\common\Widget::show() |
362 | 362 | */ |
363 | - public function show($modelInstance){ |
|
364 | - if(\is_array($modelInstance)){ |
|
365 | - if(\is_array(array_values($modelInstance)[0])) |
|
363 | + public function show($modelInstance) { |
|
364 | + if (\is_array($modelInstance)) { |
|
365 | + if (\is_array(array_values($modelInstance)[0])) |
|
366 | 366 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
367 | 367 | } |
368 | 368 | $this->_modelInstance=$modelInstance; |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | return $this; |
398 | 398 | } |
399 | 399 | |
400 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
401 | - $this->getTable()->setActiveRowSelector($class,$event,$multiple); |
|
400 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
401 | + $this->getTable()->setActiveRowSelector($class, $event, $multiple); |
|
402 | 402 | return $this; |
403 | 403 | } |
404 | 404 |