@@ -29,23 +29,23 @@ discard block |
||
| 29 | 29 | * @property boolean $_edition |
| 30 | 30 | * @property mixed _modelInstance |
| 31 | 31 | */ |
| 32 | -trait FieldAsTrait{ |
|
| 32 | +trait FieldAsTrait { |
|
| 33 | 33 | |
| 34 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
| 35 | - abstract public function setValueFunction($index,$callback); |
|
| 34 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
| 35 | + abstract public function setValueFunction($index, $callback); |
|
| 36 | 36 | abstract protected function _getFieldName($index); |
| 37 | 37 | abstract protected function _getFieldCaption($index); |
| 38 | - abstract protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
| 38 | + abstract protected function _buttonAsSubmit(BaseHtml&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * @param HtmlFormField $element |
| 42 | 42 | * @param array $attributes |
| 43 | 43 | */ |
| 44 | - protected function _applyAttributes(BaseHtml $element,&$attributes,$index){ |
|
| 45 | - if(isset($attributes["jsCallback"])){ |
|
| 44 | + protected function _applyAttributes(BaseHtml $element, &$attributes, $index) { |
|
| 45 | + if (isset($attributes["jsCallback"])) { |
|
| 46 | 46 | $callback=$attributes["jsCallback"]; |
| 47 | - if(\is_callable($callback)){ |
|
| 48 | - $callback($element,$this->_modelInstance,$index); |
|
| 47 | + if (\is_callable($callback)) { |
|
| 48 | + $callback($element, $this->_modelInstance, $index); |
|
| 49 | 49 | unset($attributes["jsCallback"]); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -55,43 +55,43 @@ discard block |
||
| 55 | 55 | $element->fromArray($attributes); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 59 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 58 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 59 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 60 | 60 | return $label; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
| 64 | - protected function _addRules(HtmlFormField $element,&$attributes){ |
|
| 65 | - if(isset($attributes["rules"])){ |
|
| 64 | + protected function _addRules(HtmlFormField $element, &$attributes) { |
|
| 65 | + if (isset($attributes["rules"])) { |
|
| 66 | 66 | $rules=$attributes["rules"]; |
| 67 | - if(\is_array($rules)){ |
|
| 67 | + if (\is_array($rules)) { |
|
| 68 | 68 | $element->addRules($rules); |
| 69 | 69 | } |
| 70 | - else{ |
|
| 70 | + else { |
|
| 71 | 71 | $element->addRule($rules); |
| 72 | 72 | } |
| 73 | 73 | unset($attributes["rules"]); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - protected function _prepareFormFields(HtmlFormField &$field,$name,&$attributes){ |
|
| 77 | + protected function _prepareFormFields(HtmlFormField&$field, $name, &$attributes) { |
|
| 78 | 78 | $field->setName($name); |
| 79 | 79 | $this->_addRules($field, $attributes); |
| 80 | 80 | return $field; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
| 84 | - $this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){ |
|
| 83 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
| 84 | + $this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){ |
|
| 85 | 85 | $caption=$this->_getFieldCaption($index); |
| 86 | 86 | $name=$this->_getFieldName($index); |
| 87 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
| 88 | - if(isset($attributes["name"])){ |
|
| 87 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
| 88 | + if (isset($attributes["name"])) { |
|
| 89 | 89 | $name=$attributes["name"]; |
| 90 | 90 | unset($attributes["name"]); |
| 91 | 91 | } |
| 92 | - $element=$elementCallback($id,$name,$value,$caption); |
|
| 93 | - if(\is_array($attributes)){ |
|
| 94 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 92 | + $element=$elementCallback($id, $name, $value, $caption); |
|
| 93 | + if (\is_array($attributes)) { |
|
| 94 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 95 | 95 | } |
| 96 | 96 | $element->setDisabled(!$this->_edition); |
| 97 | 97 | return $element; |
@@ -100,188 +100,188 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
| 104 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
| 105 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
| 103 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 104 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
| 105 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 106 | 106 | return $pb; |
| 107 | 107 | }); |
| 108 | 108 | return $this; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
| 112 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
| 113 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
| 111 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 112 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
| 113 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 114 | 114 | return $rating; |
| 115 | 115 | }); |
| 116 | 116 | return $this; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - public function fieldAsLabel($index,$icon=NULL,$attributes=NULL){ |
|
| 120 | - return $this->_fieldAs(function($id,$name,$value) use($icon){ |
|
| 121 | - $lbl=new HtmlLabel($id,$value); |
|
| 122 | - if(isset($icon)) |
|
| 119 | + public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) { |
|
| 120 | + return $this->_fieldAs(function($id, $name, $value) use($icon){ |
|
| 121 | + $lbl=new HtmlLabel($id, $value); |
|
| 122 | + if (isset($icon)) |
|
| 123 | 123 | $lbl->addIcon($icon); |
| 124 | 124 | return $lbl; |
| 125 | - }, $index,$attributes,"label"); |
|
| 125 | + }, $index, $attributes, "label"); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
| 129 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
| 130 | - $header=new HtmlHeader($id,$niveau,$value); |
|
| 131 | - if(isset($icon)) |
|
| 128 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
| 129 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
| 130 | + $header=new HtmlHeader($id, $niveau, $value); |
|
| 131 | + if (isset($icon)) |
|
| 132 | 132 | $header->asIcon($icon, $value); |
| 133 | 133 | return $header; |
| 134 | - }, $index,$attributes,"header"); |
|
| 134 | + }, $index, $attributes, "header"); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
| 138 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
| 139 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
| 140 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 138 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
| 139 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
| 140 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
| 141 | 141 | return $image; |
| 142 | 142 | }); |
| 143 | 143 | return $this; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function fieldAsFlag($index){ |
|
| 147 | - $this->setValueFunction($index,function($flag){ |
|
| 148 | - $flag=new HtmlFlag($this->_getFieldIdentifier("flag"),$flag); |
|
| 146 | + public function fieldAsFlag($index) { |
|
| 147 | + $this->setValueFunction($index, function($flag) { |
|
| 148 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
| 149 | 149 | return $flag; |
| 150 | 150 | }); |
| 151 | 151 | return $this; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
| 155 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 156 | - $img=new HtmlImage($id,$value); |
|
| 154 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 155 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 156 | + $img=new HtmlImage($id, $value); |
|
| 157 | 157 | $img->asAvatar(); |
| 158 | 158 | return $img; |
| 159 | - }, $index,$attributes,"avatar"); |
|
| 159 | + }, $index, $attributes, "avatar"); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 163 | - return $this->_fieldAs(function($id,$name,$value) use($attributes){ |
|
| 164 | - $input= new HtmlFormRadio($id,$name,$value,$value); |
|
| 162 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 163 | + return $this->_fieldAs(function($id, $name, $value) use($attributes){ |
|
| 164 | + $input=new HtmlFormRadio($id, $name, $value, $value); |
|
| 165 | 165 | return $this->_prepareFormFields($input, $name, $attributes); |
| 166 | - }, $index,$attributes,"radio"); |
|
| 166 | + }, $index, $attributes, "radio"); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
| 170 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
| 171 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
| 172 | - }, $index,$attributes,"radios"); |
|
| 169 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
| 170 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
| 171 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
| 172 | + }, $index, $attributes, "radios"); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 176 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
| 177 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
| 175 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 176 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
| 177 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 178 | 178 | return $this->_prepareFormFields($input, $name, $attributes); |
| 179 | - }, $index,$attributes,"input"); |
|
| 179 | + }, $index, $attributes, "input"); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
| 183 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
| 184 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
| 182 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 183 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
| 184 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
| 185 | 185 | return $this->_prepareFormFields($textarea, $name, $attributes); |
| 186 | - }, $index,$attributes,"textarea"); |
|
| 186 | + }, $index, $attributes, "textarea"); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - public function fieldAsElement($index,$tagName="div",$baseClass="",$attributes=NULL){ |
|
| 190 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes,$tagName,$baseClass){ |
|
| 191 | - $div=new HtmlSemDoubleElement($id,$tagName,$baseClass); |
|
| 189 | + public function fieldAsElement($index, $tagName="div", $baseClass="", $attributes=NULL) { |
|
| 190 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass){ |
|
| 191 | + $div=new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
| 192 | 192 | $div->setContent(\htmlentities($value)); |
| 193 | - $textarea=new HtmlFormField("field-".$id, $div,$caption); |
|
| 193 | + $textarea=new HtmlFormField("field-".$id, $div, $caption); |
|
| 194 | 194 | return $this->_prepareFormFields($textarea, $name, $attributes); |
| 195 | - }, $index,$attributes,"element"); |
|
| 195 | + }, $index, $attributes, "element"); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
| 199 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
| 200 | - if(!\is_array($attributes)){ |
|
| 199 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
| 200 | + if (!\is_array($attributes)) { |
|
| 201 | 201 | $attributes=[]; |
| 202 | 202 | } |
| 203 | 203 | $attributes["inputType"]="hidden"; |
| 204 | - return $this->fieldAsInput($index,$attributes); |
|
| 204 | + return $this->fieldAsInput($index, $attributes); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 208 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($attributes){ |
|
| 209 | - if($caption===null || $caption==="") |
|
| 207 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 208 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($attributes){ |
|
| 209 | + if ($caption===null || $caption==="") |
|
| 210 | 210 | $caption=""; |
| 211 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
| 211 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
| 212 | 212 | $input->setChecked(JString::isBooleanTrue($value)); |
| 213 | 213 | return $this->_prepareFormFields($input, $name, $attributes); |
| 214 | - }, $index,$attributes,"ck"); |
|
| 214 | + }, $index, $attributes, "ck"); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 218 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple,$attributes){ |
|
| 219 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
| 220 | - $dd->asSelect($name,$multiple); |
|
| 217 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 218 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple, $attributes){ |
|
| 219 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
| 220 | + $dd->asSelect($name, $multiple); |
|
| 221 | 221 | return $this->_prepareFormFields($dd, $name, $attributes); |
| 222 | - }, $index,$attributes,"dd"); |
|
| 222 | + }, $index, $attributes, "dd"); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
| 226 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 227 | - $mess= new HtmlMessage("message-".$id,$caption); |
|
| 225 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
| 226 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 227 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
| 228 | 228 | $mess->addHeader($value); |
| 229 | 229 | return $mess; |
| 230 | - }, $index,$attributes,"message"); |
|
| 230 | + }, $index, $attributes, "message"); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - public function fieldAsLink($index,$attributes=NULL){ |
|
| 234 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 235 | - $lnk= new HtmlLink("message-".$id,"#",$caption); |
|
| 233 | + public function fieldAsLink($index, $attributes=NULL) { |
|
| 234 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 235 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
| 236 | 236 | return $lnk; |
| 237 | - }, $index,$attributes,"link"); |
|
| 237 | + }, $index, $attributes, "link"); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /**Change fields type |
| 241 | 241 | * @param array $types an array or associative array $type=>$attributes |
| 242 | 242 | */ |
| 243 | - public function fieldsAs(array $types){ |
|
| 243 | + public function fieldsAs(array $types) { |
|
| 244 | 244 | $i=0; |
| 245 | - if(JArray::isAssociative($types)){ |
|
| 246 | - foreach ($types as $type=>$attributes){ |
|
| 247 | - if(\is_int($type)) |
|
| 248 | - $this->fieldAs($i++,$attributes,[]); |
|
| 249 | - else{ |
|
| 250 | - $type=preg_replace('/\d/', '', $type ); |
|
| 251 | - $this->fieldAs($i++,$type,$attributes); |
|
| 245 | + if (JArray::isAssociative($types)) { |
|
| 246 | + foreach ($types as $type=>$attributes) { |
|
| 247 | + if (\is_int($type)) |
|
| 248 | + $this->fieldAs($i++, $attributes, []); |
|
| 249 | + else { |
|
| 250 | + $type=preg_replace('/\d/', '', $type); |
|
| 251 | + $this->fieldAs($i++, $type, $attributes); |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | - }else{ |
|
| 255 | - foreach ($types as $type){ |
|
| 256 | - $this->fieldAs($i++,$type); |
|
| 254 | + } else { |
|
| 255 | + foreach ($types as $type) { |
|
| 256 | + $this->fieldAs($i++, $type); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
| 261 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
| 262 | 262 | $method="fieldAs".\ucfirst($type); |
| 263 | - if(\method_exists($this, $method)){ |
|
| 264 | - if(!\is_array($attributes)){ |
|
| 263 | + if (\method_exists($this, $method)) { |
|
| 264 | + if (!\is_array($attributes)) { |
|
| 265 | 265 | $attributes=[$index]; |
| 266 | - }else{ |
|
| 266 | + } else { |
|
| 267 | 267 | \array_unshift($attributes, $index); |
| 268 | 268 | } |
| 269 | - \call_user_func_array([$this,$method], $attributes); |
|
| 269 | + \call_user_func_array([$this, $method], $attributes); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
| 274 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
| 275 | - $button=new HtmlButton($id,$caption,$cssStyle); |
|
| 276 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
| 273 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 274 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
| 275 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
| 276 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
| 277 | 277 | return $button; |
| 278 | - }, $index,$attributes,"submit"); |
|
| 278 | + }, $index, $attributes, "submit"); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 282 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
| 283 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 281 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 282 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
| 283 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 284 | 284 | return $button; |
| 285 | - }, $index,$attributes,"button"); |
|
| 285 | + }, $index, $attributes, "button"); |
|
| 286 | 286 | } |
| 287 | 287 | } |
@@ -19,46 +19,46 @@ discard block |
||
| 19 | 19 | * @property string $identifier |
| 20 | 20 | */ |
| 21 | 21 | trait FieldsTrait { |
| 22 | - abstract public function addFields($fields=NULL,$label=NULL); |
|
| 22 | + abstract public function addFields($fields=NULL, $label=NULL); |
|
| 23 | 23 | abstract public function addItem($item); |
| 24 | 24 | |
| 25 | - protected function createItem($value){ |
|
| 26 | - if(\is_array($value)){ |
|
| 27 | - $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
|
| 25 | + protected function createItem($value) { |
|
| 26 | + if (\is_array($value)) { |
|
| 27 | + $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id", ""), JArray::getDefaultValue($value, "label", null), JArray::getDefaultValue($value, "type", "text"), JArray::getDefaultValue($value, "value", ""), JArray::getDefaultValue($value, "placeholder", JArray::getDefaultValue($value, "label", null))); |
|
| 28 | 28 | return $itemO; |
| 29 | - }elseif(\is_object($value)){ |
|
| 29 | + }elseif (\is_object($value)) { |
|
| 30 | 30 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
| 31 | 31 | return $itemO; |
| 32 | - }else |
|
| 32 | + } else |
|
| 33 | 33 | return new HtmlFormInput($value); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - protected function createCondition($value){ |
|
| 36 | + protected function createCondition($value) { |
|
| 37 | 37 | return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function addInputs($inputs,$fieldslabel=null){ |
|
| 40 | + public function addInputs($inputs, $fieldslabel=null) { |
|
| 41 | 41 | $fields=array(); |
| 42 | - foreach ($inputs as $input){ |
|
| 42 | + foreach ($inputs as $input) { |
|
| 43 | 43 | \extract($input); |
| 44 | - $f=new HtmlFormInput("",""); |
|
| 44 | + $f=new HtmlFormInput("", ""); |
|
| 45 | 45 | $f->fromArray($input); |
| 46 | 46 | $fields[]=$f; |
| 47 | 47 | } |
| 48 | - return $this->addFields($fields,$fieldslabel); |
|
| 48 | + return $this->addFields($fields, $fieldslabel); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){ |
|
| 51 | + public function addFieldRule($index, $type, $prompt=NULL, $value=NULL) { |
|
| 52 | 52 | $field=$this->getItem($index); |
| 53 | - if(isset($field)){ |
|
| 54 | - $field->addRule($type,$prompt,$value); |
|
| 53 | + if (isset($field)) { |
|
| 54 | + $field->addRule($type, $prompt, $value); |
|
| 55 | 55 | } |
| 56 | 56 | return $this; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function addFieldRules($index,$rules){ |
|
| 59 | + public function addFieldRules($index, $rules) { |
|
| 60 | 60 | $field=$this->getItem($index); |
| 61 | - if(isset($field)){ |
|
| 61 | + if (isset($field)) { |
|
| 62 | 62 | $field->addRules($rules); |
| 63 | 63 | } |
| 64 | 64 | return $this; |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * @param boolean $multiple |
| 73 | 73 | * @return HtmlDoubleElement |
| 74 | 74 | */ |
| 75 | - public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){ |
|
| 76 | - return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple)); |
|
| 75 | + public function addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false) { |
|
| 76 | + return $this->addItem(new HtmlFormDropdown($identifier, $items, $label, $value, $multiple)); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @param string $placeholder |
| 85 | 85 | * @return HtmlFormInput |
| 86 | 86 | */ |
| 87 | - public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){ |
|
| 88 | - return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder)); |
|
| 87 | + public function addInput($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL) { |
|
| 88 | + return $this->addItem(new HtmlFormInput($identifier, $label, $type, $value, $placeholder)); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -96,28 +96,28 @@ discard block |
||
| 96 | 96 | * @param int $rows |
| 97 | 97 | * @return HtmlTextarea |
| 98 | 98 | */ |
| 99 | - public function addTextarea($identifier, $label,$value=NULL,$placeholder=NULL,$rows=5){ |
|
| 100 | - return $this->addItem(new HtmlFormTextarea($identifier,$label,$value,$placeholder,$rows)); |
|
| 99 | + public function addTextarea($identifier, $label, $value=NULL, $placeholder=NULL, $rows=5) { |
|
| 100 | + return $this->addItem(new HtmlFormTextarea($identifier, $label, $value, $placeholder, $rows)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - public function addPassword($identifier, $label=NULL){ |
|
| 104 | - return $this->addItem(new HtmlFormInput($identifier,$label,"password","","")); |
|
| 103 | + public function addPassword($identifier, $label=NULL) { |
|
| 104 | + return $this->addItem(new HtmlFormInput($identifier, $label, "password", "", "")); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){ |
|
| 108 | - return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick)); |
|
| 107 | + public function addButton($identifier, $value, $cssStyle=NULL, $onClick=NULL) { |
|
| 108 | + return $this->addItem(new HtmlButton($identifier, $value, $cssStyle, $onClick)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){ |
|
| 112 | - return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type)); |
|
| 111 | + public function addCheckbox($identifier, $label=NULL, $value=NULL, $type=NULL) { |
|
| 112 | + return $this->addItem(new HtmlFormCheckbox($identifier, $label, $value, $type)); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function addRadio($identifier, $name,$label=NULL,$value=NULL){ |
|
| 116 | - return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value)); |
|
| 115 | + public function addRadio($identifier, $name, $label=NULL, $value=NULL) { |
|
| 116 | + return $this->addItem(new HtmlFormRadio($identifier, $name, $label, $value)); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - public function addElement($identifier,$content,$label,$tagName="div",$baseClass=""){ |
|
| 120 | - $div=new HtmlSemDoubleElement($identifier,$tagName,$baseClass,$content); |
|
| 121 | - return $this->addItem(new HtmlFormField("field-".$identifier, $div,$label)); |
|
| 119 | + public function addElement($identifier, $content, $label, $tagName="div", $baseClass="") { |
|
| 120 | + $div=new HtmlSemDoubleElement($identifier, $tagName, $baseClass, $content); |
|
| 121 | + return $this->addItem(new HtmlFormField("field-".$identifier, $div, $label)); |
|
| 122 | 122 | } |
| 123 | 123 | } |
@@ -16,19 +16,19 @@ discard block |
||
| 16 | 16 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
| 17 | 17 | |
| 18 | 18 | abstract public function getUrl($url); |
| 19 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
| 19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 20 | 20 | |
| 21 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 22 | - if(JString::isNull($params)){$params="{}";} |
|
| 21 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 22 | + if (JString::isNull($params)) {$params="{}"; } |
|
| 23 | 23 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 24 | 24 | $retour=$this->_getAjaxUrl($url, $attr); |
| 25 | 25 | $responseElement=$this->_getResponseElement($responseElement); |
| 26 | 26 | $retour.="var self=this;\n"; |
| 27 | - if($hasLoader===true){ |
|
| 27 | + if ($hasLoader===true) { |
|
| 28 | 28 | $this->addLoading($retour, $responseElement); |
| 29 | 29 | } |
| 30 | 30 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
| 31 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 31 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 32 | 32 | if ($immediatly) |
| 33 | 33 | $this->jquery_code_for_compile[]=$retour; |
| 34 | 34 | return $retour; |
@@ -36,33 +36,33 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - protected function _getAjaxUrl($url,$attr){ |
|
| 39 | + protected function _getAjaxUrl($url, $attr) { |
|
| 40 | 40 | $url=$this->_correctAjaxUrl($url); |
| 41 | 41 | $retour="url='".$url."';"; |
| 42 | 42 | $slash="/"; |
| 43 | - if(JString::endswith($url, "/")===true) |
|
| 43 | + if (JString::endswith($url, "/")===true) |
|
| 44 | 44 | $slash=""; |
| 45 | - if(JString::isNotNull($attr)){ |
|
| 45 | + if (JString::isNotNull($attr)) { |
|
| 46 | 46 | if ($attr==="value") |
| 47 | 47 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 48 | 48 | elseif ($attr==="html") |
| 49 | 49 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 50 | - elseif($attr!==null && $attr!=="") |
|
| 50 | + elseif ($attr!==null && $attr!=="") |
|
| 51 | 51 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
| 52 | 52 | } |
| 53 | 53 | return $retour; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
| 57 | - $retour="";$call=null; |
|
| 56 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
| 57 | + $retour=""; $call=null; |
|
| 58 | 58 | if ($responseElement!=="") { |
| 59 | - if(isset($ajaxTransition)){ |
|
| 59 | + if (isset($ajaxTransition)) { |
|
| 60 | 60 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 61 | - }elseif(isset($this->ajaxTransition)){ |
|
| 61 | + }elseif (isset($this->ajaxTransition)) { |
|
| 62 | 62 | $call=$this->ajaxTransition; |
| 63 | 63 | } |
| 64 | - if(\is_callable($call)) |
|
| 65 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 64 | + if (\is_callable($call)) |
|
| 65 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 66 | 66 | else |
| 67 | 67 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
| 68 | 68 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | return $retour; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - protected function _getResponseElement($responseElement){ |
|
| 73 | + protected function _getResponseElement($responseElement) { |
|
| 74 | 74 | if ($responseElement!=="") { |
| 75 | 75 | $responseElement=Javascript::prep_value($responseElement); |
| 76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | protected function _correctAjaxUrl($url) { |
| 81 | 81 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
| 82 | 82 | $url=substr($url, 0, strlen($url)-1); |
| 83 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
| 83 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 84 | 84 | $url=$this->getUrl($url); |
| 85 | 85 | } |
| 86 | 86 | return $url; |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - protected function setAjaxDataCall($params){ |
|
| 101 | + protected function setAjaxDataCall($params) { |
|
| 102 | 102 | $result=null; |
| 103 | - if(!\is_callable($params)){ |
|
| 104 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
| 105 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
| 103 | + if (!\is_callable($params)) { |
|
| 104 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
| 105 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
| 106 | 106 | }; |
| 107 | 107 | } |
| 108 | 108 | return $result; |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 123 | 123 | * @param string|callable $ajaxTransition |
| 124 | 124 | */ |
| 125 | - private function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 126 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
| 125 | + private function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 126 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 137 | 137 | * @param string|callable $ajaxTransition |
| 138 | 138 | */ |
| 139 | - public function get($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 140 | - return $this->_get($url,$params,$responseElement,$jsCallback,null,$hasLoader,$jqueryDone,$ajaxTransition,true); |
|
| 139 | + public function get($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 140 | + return $this->_get($url, $params, $responseElement, $jsCallback, null, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $context |
| 151 | 151 | * @param boolean $immediatly |
| 152 | 152 | */ |
| 153 | - private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
| 153 | + private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
| 154 | 154 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 155 | 155 | $retour=$this->_getAjaxUrl($url, $attr); |
| 156 | 156 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @param string $context |
| 174 | 174 | * @param boolean $immediatly |
| 175 | 175 | */ |
| 176 | - public function json($url, $method="get", $params="{}", $jsCallback=NULL,$context="document",$immediatly=false) { |
|
| 177 | - return $this->_json($url,$method,$params,$jsCallback,NULL,$context,$immediatly); |
|
| 176 | + public function json($url, $method="get", $params="{}", $jsCallback=NULL, $context="document", $immediatly=false) { |
|
| 177 | + return $this->_json($url, $method, $params, $jsCallback, NULL, $context, $immediatly); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param string $url the request address |
| 185 | 185 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
| 186 | 186 | */ |
| 187 | - public function jsonOn($event,$element, $url,$parameters=array()) { |
|
| 187 | + public function jsonOn($event, $element, $url, $parameters=array()) { |
|
| 188 | 188 | $preventDefault=true; |
| 189 | 189 | $stopPropagation=true; |
| 190 | 190 | $jsCallback=null; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $params="{}"; |
| 195 | 195 | $immediatly=true; |
| 196 | 196 | extract($parameters); |
| 197 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 197 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | * @param string $jsCallback javascript code to execute after the request |
| 206 | 206 | * @param string $context jquery DOM element, array container. |
| 207 | 207 | */ |
| 208 | - public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL,$context=NULL) { |
|
| 209 | - return $this->json($url, $method, $params, $jsCallback, $context,false); |
|
| 208 | + public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL, $context=NULL) { |
|
| 209 | + return $this->json($url, $method, $params, $jsCallback, $context, false); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -219,22 +219,22 @@ discard block |
||
| 219 | 219 | * @param string $rowClass the css class for the new element |
| 220 | 220 | * @param boolean $immediatly |
| 221 | 221 | */ |
| 222 | - private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$attr="id",$immediatly=false) { |
|
| 222 | + private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $attr="id", $immediatly=false) { |
|
| 223 | 223 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 224 | 224 | $retour=$this->_getAjaxUrl($url, $attr); |
| 225 | - if($context===null){ |
|
| 225 | + if ($context===null) { |
|
| 226 | 226 | $parent="$('".$maskSelector."').parent()"; |
| 227 | - $newElm = "$('#'+newId)"; |
|
| 228 | - }else{ |
|
| 227 | + $newElm="$('#'+newId)"; |
|
| 228 | + } else { |
|
| 229 | 229 | $parent=$context; |
| 230 | - $newElm = $context.".find('#'+newId)"; |
|
| 230 | + $newElm=$context.".find('#'+newId)"; |
|
| 231 | 231 | } |
| 232 | 232 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
| 233 | 233 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
| 234 | 234 | $retour.=$parent.".find('._json').remove();"; |
| 235 | 235 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
| 236 | 236 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
| 237 | - $retour.= $appendTo; |
|
| 237 | + $retour.=$appendTo; |
|
| 238 | 238 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
| 239 | 239 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 240 | 240 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @param string $context jquery DOM element, array container. |
| 254 | 254 | * @param boolean $immediatly |
| 255 | 255 | */ |
| 256 | - public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$immediatly=false) { |
|
| 257 | - return $this->_jsonArray($maskSelector, $url,$method,$params,$jsCallback,$rowClass,$context,NULL,$immediatly); |
|
| 256 | + public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $immediatly=false) { |
|
| 257 | + return $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, NULL, $immediatly); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | * @param string $rowClass the css class for the new element |
| 268 | 268 | * @param string $context jquery DOM element, array container. |
| 269 | 269 | */ |
| 270 | - public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL) { |
|
| 271 | - return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback,$rowClass,$context,false); |
|
| 270 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL) { |
|
| 271 | + return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, false); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -278,18 +278,18 @@ discard block |
||
| 278 | 278 | * @param string $url the request url |
| 279 | 279 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
| 280 | 280 | */ |
| 281 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$parameters=array()) { |
|
| 281 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
| 282 | 282 | $preventDefault=true; |
| 283 | 283 | $stopPropagation=true; |
| 284 | 284 | $jsCallback=null; |
| 285 | 285 | $attr="id"; |
| 286 | 286 | $method="get"; |
| 287 | - $context = null; |
|
| 287 | + $context=null; |
|
| 288 | 288 | $params="{}"; |
| 289 | 289 | $immediatly=true; |
| 290 | 290 | $rowClass="_json"; |
| 291 | 291 | extract($parameters); |
| 292 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $rowClass, $context,$attr), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 292 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, $attr), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 304 | 304 | * @param string|callable $ajaxTransition |
| 305 | 305 | */ |
| 306 | - public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL,$attr="id",$jqueryDone="html",$ajaxTransition=null) { |
|
| 307 | - return $this->_get($url, $params,$responseElement,$jsCallback,$attr,false,$jqueryDone,$ajaxTransition); |
|
| 306 | + public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $jqueryDone="html", $ajaxTransition=null) { |
|
| 307 | + return $this->_get($url, $params, $responseElement, $jsCallback, $attr, false, $jqueryDone, $ajaxTransition); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $ajaxTransition=null; |
| 328 | 328 | $params="{}"; |
| 329 | 329 | extract($parameters); |
| 330 | - return $this->_add_event($element, $this->_get($url, $params,$responseElement,$jsCallback,$attr, $hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 330 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - private function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 346 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
| 345 | + private function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 346 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 357 | 357 | * @param string|callable $ajaxTransition |
| 358 | 358 | */ |
| 359 | - public function post($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 360 | - return $this->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
| 359 | + public function post($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 360 | + return $this->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 373 | 373 | * @param string|callable $ajaxTransition |
| 374 | 374 | */ |
| 375 | - public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 376 | - return $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
| 375 | + public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 376 | + return $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $jqueryDone="html"; |
| 397 | 397 | $ajaxTransition=null; |
| 398 | 398 | extract($parameters); |
| 399 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 399 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - private function _postForm($url, $form, $responseElement, $params=null,$validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 415 | + private function _postForm($url, $form, $responseElement, $params=null, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 416 | 416 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 417 | 417 | $retour=$this->_getAjaxUrl($url, $attr); |
| 418 | 418 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
| 419 | - if(isset($params)){ |
|
| 419 | + if (isset($params)) { |
|
| 420 | 420 | $retour.="params+='&'+$.param(".$params.");\n"; |
| 421 | 421 | } |
| 422 | 422 | $responseElement=$this->_getResponseElement($responseElement); |
| 423 | 423 | $retour.="var self=this;\n"; |
| 424 | - if($hasLoader===true){ |
|
| 424 | + if ($hasLoader===true) { |
|
| 425 | 425 | $this->addLoading($retour, $responseElement); |
| 426 | 426 | } |
| 427 | 427 | $retour.="$.post(url,params).done(function( data ) {\n"; |
| 428 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 428 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 429 | 429 | |
| 430 | 430 | if ($validation) { |
| 431 | 431 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 450 | 450 | * @param string|callable $ajaxTransition |
| 451 | 451 | */ |
| 452 | - public function postForm($url, $form, $responseElement, $params=NULL,$validation=false, $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 453 | - return $this->_postForm($url, $form, $responseElement, $params,$validation, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
| 452 | + public function postForm($url, $form, $responseElement, $params=NULL, $validation=false, $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 453 | + return $this->_postForm($url, $form, $responseElement, $params, $validation, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -467,8 +467,8 @@ discard block |
||
| 467 | 467 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 468 | 468 | * @param string|callable $ajaxTransition |
| 469 | 469 | */ |
| 470 | - public function postFormDeferred($url, $form, $responseElement, $params=NULL,$validation=false, $jsCallback=NULL,$attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 471 | - return $this->_postForm($url, $form, $responseElement, $params,$validation, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
| 470 | + public function postFormDeferred($url, $form, $responseElement, $params=NULL, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 471 | + return $this->_postForm($url, $form, $responseElement, $params, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | $jqueryDone="html"; |
| 494 | 494 | $ajaxTransition=null; |
| 495 | 495 | extract($parameters); |
| 496 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement,$params, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 496 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $params, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -29,27 +29,27 @@ |
||
| 29 | 29 | $rowClass="_json"; |
| 30 | 30 | extract($this->parameters); |
| 31 | 31 | $result=$this->_eventPreparing($preventDefault, $stopPropagation); |
| 32 | - switch($this->method) { |
|
| 32 | + switch ($this->method) { |
|
| 33 | 33 | case "get": |
| 34 | - $result.=$js->getDeferred($url, $responseElement, $params, $jsCallback, $attr,$jqueryDone,$ajaxTransition); |
|
| 34 | + $result.=$js->getDeferred($url, $responseElement, $params, $jsCallback, $attr, $jqueryDone, $ajaxTransition); |
|
| 35 | 35 | break; |
| 36 | 36 | case "post": |
| 37 | - $result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition); |
|
| 37 | + $result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition); |
|
| 38 | 38 | break; |
| 39 | 39 | case "postForm": |
| 40 | - $result.=$js->postFormDeferred($url, $form, $responseElement, $params,$validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition); |
|
| 40 | + $result.=$js->postFormDeferred($url, $form, $responseElement, $params, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition); |
|
| 41 | 41 | break; |
| 42 | 42 | case "json": |
| 43 | - $result.=$js->jsonDeferred($url,$method,$params,$jsCallback); |
|
| 43 | + $result.=$js->jsonDeferred($url, $method, $params, $jsCallback); |
|
| 44 | 44 | break; |
| 45 | 45 | case "jsonArray": |
| 46 | - $result.=$js->jsonArrayDeferred($modelSelector, $url,$method,$params,$jsCallback,$rowClass); |
|
| 46 | + $result.=$js->jsonArrayDeferred($modelSelector, $url, $method, $params, $jsCallback, $rowClass); |
|
| 47 | 47 | break; |
| 48 | 48 | } |
| 49 | 49 | return $result; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - protected function _eventPreparing($preventDefault,$stopPropagation){ |
|
| 52 | + protected function _eventPreparing($preventDefault, $stopPropagation) { |
|
| 53 | 53 | $result=""; |
| 54 | 54 | if ($preventDefault===true) { |
| 55 | 55 | $result.=Javascript::$preventDefault; |