@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | trait FieldAsTrait { |
| 39 | 39 | |
| 40 | - abstract protected function _getFieldIdentifier($prefix, $name = ""); |
|
| 40 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
| 41 | 41 | |
| 42 | 42 | abstract public function setValueFunction($index, $callback); |
| 43 | 43 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | abstract protected function _getFieldCaption($index); |
| 47 | 47 | |
| 48 | - abstract protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement = NULL, $parameters = NULL); |
|
| 48 | + abstract protected function _buttonAsSubmit(BaseHtml&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
| 49 | 49 | |
| 50 | 50 | private $_speProperties; |
| 51 | 51 | |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | * @param HtmlFormField $element |
| 55 | 55 | * @param array $attributes |
| 56 | 56 | */ |
| 57 | - protected function _applyAttributes(BaseHtml $element, &$attributes, $index, $instance = null) { |
|
| 57 | + protected function _applyAttributes(BaseHtml $element, &$attributes, $index, $instance=null) { |
|
| 58 | 58 | if (isset($attributes["jsCallback"])) { |
| 59 | - $callback = $attributes["jsCallback"]; |
|
| 59 | + $callback=$attributes["jsCallback"]; |
|
| 60 | 60 | if (\is_callable($callback)) { |
| 61 | 61 | $callback($element, $instance, $index, InstanceViewer::$index); |
| 62 | 62 | } |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | $element->fromArray($attributes); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - private function _getLabelField($caption, $icon = NULL) { |
|
| 71 | - $label = new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 70 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 71 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 72 | 72 | return $label; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | protected function _addRules(HtmlFormField $element, &$attributes) { |
| 76 | 76 | if (isset($attributes["rules"])) { |
| 77 | - $this->_hasRules = true; |
|
| 78 | - $rules = $attributes["rules"]; |
|
| 77 | + $this->_hasRules=true; |
|
| 78 | + $rules=$attributes["rules"]; |
|
| 79 | 79 | if (\is_array($rules)) { |
| 80 | 80 | $element->addRules($rules); |
| 81 | 81 | } else { |
@@ -85,30 +85,30 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - protected function _prepareFormFields(HtmlFormField &$field, $name, &$attributes) { |
|
| 88 | + protected function _prepareFormFields(HtmlFormField&$field, $name, &$attributes) { |
|
| 89 | 89 | $field->setName($name); |
| 90 | 90 | $this->_addRules($field, $attributes); |
| 91 | 91 | return $field; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $prefix = null) { |
|
| 95 | - $this->setValueFunction($index, function ($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) { |
|
| 96 | - $caption = $this->_getFieldCaption($index); |
|
| 97 | - $name = $this->_getFieldName($index); |
|
| 98 | - $id = $this->_getFieldIdentifier($prefix, $name); |
|
| 94 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
| 95 | + $this->setValueFunction($index, function($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) { |
|
| 96 | + $caption=$this->_getFieldCaption($index); |
|
| 97 | + $name=$this->_getFieldName($index); |
|
| 98 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
| 99 | 99 | if (isset($attributes["name"])) { |
| 100 | - $name = $attributes["name"]; |
|
| 100 | + $name=$attributes["name"]; |
|
| 101 | 101 | unset($attributes["name"]); |
| 102 | 102 | } |
| 103 | - $element = $elementCallback($id, $name, $value, $caption); |
|
| 103 | + $element=$elementCallback($id, $name, $value, $caption); |
|
| 104 | 104 | if (isset($this->_speProperties[$index])) { |
| 105 | - $attributes ??= []; |
|
| 106 | - $attributes += $this->_speProperties[$index]; |
|
| 105 | + $attributes??=[]; |
|
| 106 | + $attributes+=$this->_speProperties[$index]; |
|
| 107 | 107 | } |
| 108 | 108 | if (\is_array($attributes)) { |
| 109 | 109 | $this->_applyAttributes($element, $attributes, $index, $instance); |
| 110 | 110 | } |
| 111 | - $element->setDisabled(! $this->_edition); |
|
| 111 | + $element->setDisabled(!$this->_edition); |
|
| 112 | 112 | return $element; |
| 113 | 113 | }); |
| 114 | 114 | return $this; |
@@ -124,48 +124,48 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function setPropertyValues($property, $indexValues) { |
| 126 | 126 | foreach ($indexValues as $index => $value) { |
| 127 | - $ind = $this->_getIndex($index); |
|
| 128 | - $this->_speProperties[$ind][$property] = $value; |
|
| 127 | + $ind=$this->_getIndex($index); |
|
| 128 | + $this->_speProperties[$ind][$property]=$value; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - public function fieldAsProgress($index, $label = NULL, $attributes = array()) { |
|
| 133 | - $this->setValueFunction($index, function ($value) use ($label, $attributes) { |
|
| 134 | - $pb = new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 132 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 133 | + $this->setValueFunction($index, function($value) use ($label, $attributes) { |
|
| 134 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 135 | 135 | return $pb; |
| 136 | 136 | }); |
| 137 | 137 | return $this; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public function fieldAsRating($index, $max = 5, $icon = "") { |
|
| 141 | - $this->setValueFunction($index, function ($value) use ($max, $icon) { |
|
| 142 | - $rating = new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 140 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 141 | + $this->setValueFunction($index, function($value) use ($max, $icon) { |
|
| 142 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 143 | 143 | return $rating; |
| 144 | 144 | }); |
| 145 | 145 | return $this; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - public function fieldAsLabel($index, $icon = NULL, $attributes = NULL) { |
|
| 149 | - return $this->_fieldAs(function ($id, $name, $value) use ($icon) { |
|
| 150 | - $lbl = new HtmlLabel($id, $value); |
|
| 148 | + public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) { |
|
| 149 | + return $this->_fieldAs(function($id, $name, $value) use ($icon) { |
|
| 150 | + $lbl=new HtmlLabel($id, $value); |
|
| 151 | 151 | if (isset($icon)) |
| 152 | 152 | $lbl->addIcon($icon); |
| 153 | 153 | return $lbl; |
| 154 | 154 | }, $index, $attributes, "label"); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - public function fieldAsHeader($index, $niveau = 1, $icon = NULL, $attributes = NULL) { |
|
| 158 | - return $this->_fieldAs(function ($id, $name, $value) use ($niveau, $icon) { |
|
| 159 | - $header = new HtmlHeader($id, $niveau, $value); |
|
| 157 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
| 158 | + return $this->_fieldAs(function($id, $name, $value) use ($niveau, $icon) { |
|
| 159 | + $header=new HtmlHeader($id, $niveau, $value); |
|
| 160 | 160 | if (isset($icon)) |
| 161 | 161 | $header->asIcon($icon, $value); |
| 162 | 162 | return $header; |
| 163 | 163 | }, $index, $attributes, "header"); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - public function fieldAsImage($index, $size = Size::MINI, $circular = false) { |
|
| 167 | - $this->setValueFunction($index, function ($img) use ($size, $circular) { |
|
| 168 | - $image = new HtmlImage($this->_getFieldIdentifier("image"), $img); |
|
| 166 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
| 167 | + $this->setValueFunction($index, function($img) use ($size, $circular) { |
|
| 168 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); |
|
| 169 | 169 | $image->setSize($size); |
| 170 | 170 | if ($circular) |
| 171 | 171 | $image->setCircular(); |
@@ -175,65 +175,65 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function fieldAsFlag($index) { |
| 178 | - $this->setValueFunction($index, function ($flag) { |
|
| 179 | - $flag = new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
| 178 | + $this->setValueFunction($index, function($flag) { |
|
| 179 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
| 180 | 180 | return $flag; |
| 181 | 181 | }); |
| 182 | 182 | return $this; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | public function fieldAsIcon($index) { |
| 186 | - $this->setValueFunction($index, function ($icon) { |
|
| 187 | - $icon = new HtmlIcon($this->_getFieldIdentifier("icon"), $icon); |
|
| 186 | + $this->setValueFunction($index, function($icon) { |
|
| 187 | + $icon=new HtmlIcon($this->_getFieldIdentifier("icon"), $icon); |
|
| 188 | 188 | return $icon; |
| 189 | 189 | }); |
| 190 | 190 | return $this; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - public function fieldAsAvatar($index, $attributes = NULL) { |
|
| 194 | - return $this->_fieldAs(function ($id, $name, $value) { |
|
| 195 | - $img = new HtmlImage($id, $value); |
|
| 193 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 194 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 195 | + $img=new HtmlImage($id, $value); |
|
| 196 | 196 | $img->asAvatar(); |
| 197 | 197 | return $img; |
| 198 | 198 | }, $index, $attributes, "avatar"); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - public function fieldAsRadio($index, $attributes = NULL) { |
|
| 202 | - return $this->_fieldAs(function ($id, $name, $value) use ($attributes) { |
|
| 203 | - $input = new HtmlFormRadio($id, $name, $value, $value); |
|
| 201 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 202 | + return $this->_fieldAs(function($id, $name, $value) use ($attributes) { |
|
| 203 | + $input=new HtmlFormRadio($id, $name, $value, $value); |
|
| 204 | 204 | return $this->_prepareFormFields($input, $name, $attributes); |
| 205 | 205 | }, $index, $attributes, "radio"); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - public function fieldAsRadios($index, $elements = [], $attributes = NULL) { |
|
| 209 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($elements) { |
|
| 208 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
| 209 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements) { |
|
| 210 | 210 | return HtmlFormFields::radios($name, $elements, $caption, $value); |
| 211 | 211 | }, $index, $attributes, "radios"); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - public function fieldAsList($index, $classNames = "", $attributes = NULL) { |
|
| 215 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($classNames) { |
|
| 216 | - $result = new HtmlList($name, $value); |
|
| 214 | + public function fieldAsList($index, $classNames="", $attributes=NULL) { |
|
| 215 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($classNames) { |
|
| 216 | + $result=new HtmlList($name, $value); |
|
| 217 | 217 | $result->addClass($classNames); |
| 218 | 218 | return $result; |
| 219 | 219 | }, $index, $attributes, "list"); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - public function fieldAsInput($index, $attributes = NULL) { |
|
| 223 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 224 | - $input = new HtmlFormInput($id, $caption, "text", $value); |
|
| 222 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 223 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 224 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 225 | 225 | return $this->_prepareFormFields($input, $name, $attributes); |
| 226 | 226 | }, $index, $attributes, "input"); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - public function fieldAsLabeledInput($index, $attributes = NULL) { |
|
| 230 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 231 | - $input = new HtmlFormInput($id, '', 'text', $value, $caption); |
|
| 232 | - $required = ''; |
|
| 229 | + public function fieldAsLabeledInput($index, $attributes=NULL) { |
|
| 230 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 231 | + $input=new HtmlFormInput($id, '', 'text', $value, $caption); |
|
| 232 | + $required=''; |
|
| 233 | 233 | if (isset($attributes['rules'])) { |
| 234 | - $rules = json_encode($attributes['rules']); |
|
| 235 | - if (strpos($rules, 'empty') !== false) { |
|
| 236 | - $required = 'required'; |
|
| 234 | + $rules=json_encode($attributes['rules']); |
|
| 235 | + if (strpos($rules, 'empty')!==false) { |
|
| 236 | + $required='required'; |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | $input->getField() |
@@ -244,80 +244,80 @@ discard block |
||
| 244 | 244 | }, $index, $attributes, 'input'); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - public function fieldAsDataList($index, ?array $items = [], $attributes = NULL) { |
|
| 248 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $items) { |
|
| 249 | - $input = new HtmlFormInput($id, $caption, "text", $value); |
|
| 247 | + public function fieldAsDataList($index, ?array $items=[], $attributes=NULL) { |
|
| 248 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $items) { |
|
| 249 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 250 | 250 | $input->getField() |
| 251 | 251 | ->addDataList($items); |
| 252 | 252 | return $this->_prepareFormFields($input, $name, $attributes); |
| 253 | 253 | }, $index, $attributes, "input"); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - public function fieldAsFile($index, $attributes = NULL) { |
|
| 256 | + public function fieldAsFile($index, $attributes=NULL) { |
|
| 257 | 257 | if (isset($this->_form)) { |
| 258 | 258 | $this->_form->setProperty('enctype', 'multipart/form-data'); |
| 259 | 259 | } |
| 260 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 261 | - $input = new HtmlFormInput($id, $caption); |
|
| 260 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 261 | + $input=new HtmlFormInput($id, $caption); |
|
| 262 | 262 | $input->asFile(); |
| 263 | 263 | return $this->_prepareFormFields($input, $name, $attributes); |
| 264 | 264 | }, $index, $attributes, "input"); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - public function fieldAsTextarea($index, $attributes = NULL) { |
|
| 268 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 269 | - $textarea = new HtmlFormTextarea($id, $caption, $value); |
|
| 267 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 268 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 269 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
| 270 | 270 | return $this->_prepareFormFields($textarea, $name, $attributes); |
| 271 | 271 | }, $index, $attributes, "textarea"); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - public function fieldAsElement($index, $tagName = "div", $baseClass = "", $attributes = NULL) { |
|
| 275 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) { |
|
| 276 | - $div = new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
| 274 | + public function fieldAsElement($index, $tagName="div", $baseClass="", $attributes=NULL) { |
|
| 275 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) { |
|
| 276 | + $div=new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
| 277 | 277 | $div->setContent(\htmlentities($value)); |
| 278 | - $textarea = new HtmlFormField("field-" . $id, $div, $caption); |
|
| 278 | + $textarea=new HtmlFormField("field-".$id, $div, $caption); |
|
| 279 | 279 | return $this->_prepareFormFields($textarea, $name, $attributes); |
| 280 | 280 | }, $index, $attributes, "element"); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - public function fieldAsHidden($index, $attributes = NULL) { |
|
| 284 | - if (! \is_array($attributes)) { |
|
| 285 | - $attributes = []; |
|
| 283 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
| 284 | + if (!\is_array($attributes)) { |
|
| 285 | + $attributes=[]; |
|
| 286 | 286 | } |
| 287 | - $attributes["inputType"] = "hidden"; |
|
| 288 | - $attributes["style"] = "display:none;"; |
|
| 287 | + $attributes["inputType"]="hidden"; |
|
| 288 | + $attributes["style"]="display:none;"; |
|
| 289 | 289 | return $this->fieldAsInput($index, $attributes); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - public function fieldAsCheckbox($index, $attributes = NULL) { |
|
| 293 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 294 | - if ($caption === null || $caption === "") |
|
| 295 | - $caption = ""; |
|
| 296 | - $input = new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
| 292 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 293 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 294 | + if ($caption===null || $caption==="") |
|
| 295 | + $caption=""; |
|
| 296 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
| 297 | 297 | $input->setChecked(JString::isBooleanTrue($value)); |
| 298 | 298 | return $this->_prepareFormFields($input, $name, $attributes); |
| 299 | 299 | }, $index, $attributes, "ck"); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - public function fieldAsDropDown($index, $elements = [], $multiple = false, $attributes = NULL) { |
|
| 303 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($elements, $multiple, $attributes) { |
|
| 304 | - $dd = new HtmlFormDropdown($id, $elements, $caption, $value ?? ''); |
|
| 302 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 303 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements, $multiple, $attributes) { |
|
| 304 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value ?? ''); |
|
| 305 | 305 | $dd->asSelect($name, $multiple); |
| 306 | 306 | return $this->_prepareFormFields($dd, $name, $attributes); |
| 307 | 307 | }, $index, $attributes, "dd"); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - public function fieldAsMessage($index, $attributes = NULL) { |
|
| 311 | - return $this->_fieldAs(function ($id, $name, $value, $caption) { |
|
| 312 | - $mess = new HtmlMessage("message-" . $id, $caption); |
|
| 310 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
| 311 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 312 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
| 313 | 313 | $mess->addHeader($value); |
| 314 | 314 | return $mess; |
| 315 | 315 | }, $index, $attributes, "message"); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - public function fieldAsLink($index, $attributes = NULL) { |
|
| 319 | - return $this->_fieldAs(function ($id, $name, $value, $caption) { |
|
| 320 | - $lnk = new HtmlLink("message-" . $id, "#", $caption); |
|
| 318 | + public function fieldAsLink($index, $attributes=NULL) { |
|
| 319 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 320 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
| 321 | 321 | return $lnk; |
| 322 | 322 | }, $index, $attributes, "link"); |
| 323 | 323 | } |
@@ -329,28 +329,28 @@ discard block |
||
| 329 | 329 | * an array or associative array $type=>$attributes |
| 330 | 330 | */ |
| 331 | 331 | public function fieldsAs(array $types) { |
| 332 | - $i = 0; |
|
| 332 | + $i=0; |
|
| 333 | 333 | if (JArray::isAssociative($types)) { |
| 334 | 334 | foreach ($types as $type => $attributes) { |
| 335 | 335 | if (\is_int($type)) |
| 336 | - $this->fieldAs($i ++, $attributes, []); |
|
| 336 | + $this->fieldAs($i++, $attributes, []); |
|
| 337 | 337 | else { |
| 338 | - $type = preg_replace('/\d/', '', $type); |
|
| 339 | - $this->fieldAs($i ++, $type, $attributes); |
|
| 338 | + $type=preg_replace('/\d/', '', $type); |
|
| 339 | + $this->fieldAs($i++, $type, $attributes); |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | } else { |
| 343 | 343 | foreach ($types as $type) { |
| 344 | - $this->fieldAs($i ++, $type); |
|
| 344 | + $this->fieldAs($i++, $type); |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - public function fieldAs($index, $type, $attributes = NULL) { |
|
| 350 | - $method = "fieldAs" . \ucfirst($type); |
|
| 349 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
| 350 | + $method="fieldAs".\ucfirst($type); |
|
| 351 | 351 | if (\method_exists($this, $method)) { |
| 352 | - if (! \is_array($attributes)) { |
|
| 353 | - $attributes = [ |
|
| 352 | + if (!\is_array($attributes)) { |
|
| 353 | + $attributes=[ |
|
| 354 | 354 | $index |
| 355 | 355 | ]; |
| 356 | 356 | } else { |
@@ -363,39 +363,39 @@ discard block |
||
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - public function fieldAsSubmit($index, $cssStyle = NULL, $url = NULL, $responseElement = NULL, $attributes = NULL) { |
|
| 367 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) { |
|
| 368 | - $button = new HtmlButton($id, $caption, $cssStyle); |
|
| 366 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 367 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) { |
|
| 368 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
| 369 | 369 | $this->_buttonAsSubmit($button, "click", $url, $responseElement, $attributes["ajax"] ?? []); |
| 370 | 370 | return $button; |
| 371 | 371 | }, $index, $attributes, "submit"); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - public function fieldAsButton($index, $cssStyle = NULL, $attributes = NULL) { |
|
| 375 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($cssStyle) { |
|
| 376 | - $button = new HtmlButton($id, $value, $cssStyle); |
|
| 374 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 375 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle) { |
|
| 376 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 377 | 377 | return $button; |
| 378 | 378 | }, $index, $attributes, "button"); |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - public function fieldAsDataTable($index, $model, $instances = null, $fields = [], $attributes = NULL) { |
|
| 382 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($model, $instances, $fields, $index) { |
|
| 383 | - $dt = new DataTable($id, $model, $instances); |
|
| 381 | + public function fieldAsDataTable($index, $model, $instances=null, $fields=[], $attributes=NULL) { |
|
| 382 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($model, $instances, $fields, $index) { |
|
| 383 | + $dt=new DataTable($id, $model, $instances); |
|
| 384 | 384 | $dt->setNamePrefix($index); |
| 385 | 385 | $dt->setFields($fields); |
| 386 | 386 | $dt->setEdition(true); |
| 387 | - $dt->addDeleteButton(false, [], function ($bt) use ($index) { |
|
| 387 | + $dt->addDeleteButton(false, [], function($bt) use ($index) { |
|
| 388 | 388 | $bt->addClass('mini circular') |
| 389 | - ->wrap('<input value="" class="_status" type="hidden" name="' . $index . '._status[]">'); |
|
| 389 | + ->wrap('<input value="" class="_status" type="hidden" name="'.$index.'._status[]">'); |
|
| 390 | 390 | }); |
| 391 | - if ($caption != null) { |
|
| 391 | + if ($caption!=null) { |
|
| 392 | 392 | $dt->setFormCaption($caption); |
| 393 | 393 | } |
| 394 | - $dt->onPreCompile(function () use (&$dt) { |
|
| 394 | + $dt->onPreCompile(function() use (&$dt) { |
|
| 395 | 395 | $dt->getHtmlComponent() |
| 396 | 396 | ->colRightFromRight(0); |
| 397 | 397 | }); |
| 398 | - $dt->wrap('<input type="hidden" name="' . $index . '">'); |
|
| 398 | + $dt->wrap('<input type="hidden" name="'.$index.'">'); |
|
| 399 | 399 | return $dt; |
| 400 | 400 | }, $index, $attributes, "dataTable"); |
| 401 | 401 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function __construct($identifier) { |
| 24 | 24 | parent::__construct($identifier, "tr", ""); |
| 25 | - $this->_states = [ |
|
| 25 | + $this->_states=[ |
|
| 26 | 26 | State::ACTIVE, |
| 27 | 27 | State::POSITIVE, |
| 28 | 28 | State::NEGATIVE, |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function setColCount($colCount) { |
| 36 | - $count = $this->count(); |
|
| 37 | - for ($i = $count; $i < $colCount; $i ++) { |
|
| 38 | - $item = $this->addItem(NULL); |
|
| 36 | + $count=$this->count(); |
|
| 37 | + for ($i=$count; $i<$colCount; $i++) { |
|
| 38 | + $item=$this->addItem(NULL); |
|
| 39 | 39 | $item->setTagName($this->_tdTagName); |
| 40 | 40 | } |
| 41 | 41 | return $this; |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * @see \Ajax\common\html\HtmlCollection::createItem() |
| 53 | 53 | */ |
| 54 | 54 | protected function createItem($value) { |
| 55 | - $count = $this->count(); |
|
| 56 | - $td = new HtmlTD("", $value, $this->_tdTagName); |
|
| 55 | + $count=$this->count(); |
|
| 56 | + $td=new HtmlTD("", $value, $this->_tdTagName); |
|
| 57 | 57 | $td->setContainer($this->_container, $this->_row, $count); |
| 58 | 58 | return $td; |
| 59 | 59 | } |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | return parent::getItem($index); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function setTdTagName($tagName = "td") { |
|
| 70 | - $this->_tdTagName = $tagName; |
|
| 69 | + public function setTdTagName($tagName="td") { |
|
| 70 | + $this->_tdTagName=$tagName; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @param int $row |
| 78 | 78 | */ |
| 79 | 79 | public function setContainer($container, $row) { |
| 80 | - $this->_container = $container; |
|
| 81 | - $this->_row = $row; |
|
| 80 | + $this->_container=$container; |
|
| 81 | + $this->_row=$row; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @param mixed $values |
| 88 | 88 | */ |
| 89 | - public function setValues($values = array()) { |
|
| 90 | - return $this->_addOrSetValues($values, function (HtmlTD &$cell, $value) { |
|
| 89 | + public function setValues($values=array()) { |
|
| 90 | + return $this->_addOrSetValues($values, function(HtmlTD&$cell, $value) { |
|
| 91 | 91 | $cell->setValue($value); |
| 92 | 92 | }); |
| 93 | 93 | } |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @param mixed $values |
| 99 | 99 | */ |
| 100 | - public function addValues($values = array()) { |
|
| 101 | - return $this->_addOrSetValues($values, function (HtmlTD &$cell, $value) { |
|
| 100 | + public function addValues($values=array()) { |
|
| 101 | + return $this->_addOrSetValues($values, function(HtmlTD&$cell, $value) { |
|
| 102 | 102 | $cell->addValue($value); |
| 103 | 103 | }); |
| 104 | 104 | } |
@@ -109,18 +109,18 @@ discard block |
||
| 109 | 109 | * @param mixed $values |
| 110 | 110 | */ |
| 111 | 111 | protected function _addOrSetValues($values, $callback) { |
| 112 | - $count = $this->count(); |
|
| 113 | - if (! \is_array($values)) { |
|
| 114 | - $values = \array_fill(0, $count, $values); |
|
| 112 | + $count=$this->count(); |
|
| 113 | + if (!\is_array($values)) { |
|
| 114 | + $values=\array_fill(0, $count, $values); |
|
| 115 | 115 | } else { |
| 116 | - if (JArray::isAssociative($values) === true) { |
|
| 117 | - $values = \array_values($values); |
|
| 116 | + if (JArray::isAssociative($values)===true) { |
|
| 117 | + $values=\array_values($values); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | - $count = \min(\sizeof($values), $count); |
|
| 120 | + $count=\min(\sizeof($values), $count); |
|
| 121 | 121 | |
| 122 | - for ($i = 0; $i < $count; $i ++) { |
|
| 123 | - $cell = $this->content[$i]; |
|
| 122 | + for ($i=0; $i<$count; $i++) { |
|
| 123 | + $cell=$this->content[$i]; |
|
| 124 | 124 | $callback($cell, $values[$i]); |
| 125 | 125 | } |
| 126 | 126 | return $this; |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | return $this; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - public function mergeCol($colIndex = 0) { |
|
| 141 | + public function mergeCol($colIndex=0) { |
|
| 142 | 142 | return $this->getItem($colIndex)->mergeCol(); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - public function mergeRow($colIndex = 0) { |
|
| 146 | - $row = $this->getItem($colIndex); |
|
| 145 | + public function mergeRow($colIndex=0) { |
|
| 146 | + $row=$this->getItem($colIndex); |
|
| 147 | 147 | if (isset($row)) { |
| 148 | 148 | $this->getItem($colIndex)->mergeRow(); |
| 149 | 149 | } |
@@ -151,31 +151,31 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | public function getColPosition($colIndex) { |
| 154 | - if ($this->_container->_isMerged() !== true) |
|
| 154 | + if ($this->_container->_isMerged()!==true) |
|
| 155 | 155 | return $colIndex; |
| 156 | - $pos = 0; |
|
| 157 | - $rows = $this->_container->getContent(); |
|
| 158 | - for ($i = 0; $i < $this->_row; $i ++) { |
|
| 159 | - $max = \min($colIndex, $rows[$i]->count()); |
|
| 160 | - for ($j = 0; $j < $max; $j ++) { |
|
| 161 | - $rowspan = $rows[$i]->getItem($j)->getRowspan(); |
|
| 162 | - if ($rowspan + $i > $this->_row) |
|
| 163 | - $pos ++; |
|
| 156 | + $pos=0; |
|
| 157 | + $rows=$this->_container->getContent(); |
|
| 158 | + for ($i=0; $i<$this->_row; $i++) { |
|
| 159 | + $max=\min($colIndex, $rows[$i]->count()); |
|
| 160 | + for ($j=0; $j<$max; $j++) { |
|
| 161 | + $rowspan=$rows[$i]->getItem($j)->getRowspan(); |
|
| 162 | + if ($rowspan+$i>$this->_row) |
|
| 163 | + $pos++; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | - if ($pos > $colIndex) |
|
| 166 | + if ($pos>$colIndex) |
|
| 167 | 167 | return NULL; |
| 168 | - $count = $this->count(); |
|
| 169 | - for ($i = 0; $i < $count; $i ++) { |
|
| 170 | - $pos += $this->content[$i]->getColspan(); |
|
| 171 | - if ($pos >= $colIndex + 1) |
|
| 168 | + $count=$this->count(); |
|
| 169 | + for ($i=0; $i<$count; $i++) { |
|
| 170 | + $pos+=$this->content[$i]->getColspan(); |
|
| 171 | + if ($pos>=$colIndex+1) |
|
| 172 | 172 | return $i; |
| 173 | 173 | } |
| 174 | 174 | return null; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function conditionalCellFormat($callback, $format) { |
| 178 | - $cells = $this->content; |
|
| 178 | + $cells=$this->content; |
|
| 179 | 179 | foreach ($cells as $cell) { |
| 180 | 180 | $cell->conditionalCellFormat($callback, $format); |
| 181 | 181 | } |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | public function containsStr($needle) { |
| 193 | - $cells = $this->content; |
|
| 193 | + $cells=$this->content; |
|
| 194 | 194 | foreach ($cells as $cell) { |
| 195 | - if (\strpos($cell->getContent(), $needle) !== false) |
|
| 195 | + if (\strpos($cell->getContent(), $needle)!==false) |
|
| 196 | 196 | return true; |
| 197 | 197 | } |
| 198 | 198 | return false; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | public function applyCells($callback) { |
| 207 | - $cells = $this->content; |
|
| 207 | + $cells=$this->content; |
|
| 208 | 208 | foreach ($cells as $cell) { |
| 209 | 209 | $cell->apply($callback); |
| 210 | 210 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | public function toRowspanned($colIndex) { |
| 220 | - $cell = $this->getItem($colIndex); |
|
| 220 | + $cell=$this->getItem($colIndex); |
|
| 221 | 221 | $cell->addClass('rowspanned'); |
| 222 | 222 | $cell->setContent(''); |
| 223 | 223 | return $this; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @author jc |
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | -trait FormTrait{ |
|
| 18 | +trait FormTrait { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @return HtmlForm |
@@ -23,23 +23,23 @@ discard block |
||
| 23 | 23 | abstract protected function getForm(); |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - protected function addCompoValidation(Form $compo,HtmlFormField $field){ |
|
| 26 | + protected function addCompoValidation(Form $compo, HtmlFormField $field) { |
|
| 27 | 27 | $validation=$field->getValidation(); |
| 28 | - if(isset($validation)){ |
|
| 28 | + if (isset($validation)) { |
|
| 29 | 29 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
| 30 | 30 | $compo->addFieldValidation($validation); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - protected function addExtraCompoValidation(Form $compo,FieldValidation $validation){ |
|
| 34 | + protected function addExtraCompoValidation(Form $compo, FieldValidation $validation) { |
|
| 35 | 35 | $compo->addFieldValidation($validation); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){ |
|
| 38 | + protected function _runValidationParams(Form&$compo, JsUtils $js=NULL) { |
|
| 39 | 39 | $form=$this->getForm(); |
| 40 | 40 | $params=$form->getValidationParams(); |
| 41 | - if(isset($params["_ajaxSubmit"])){ |
|
| 42 | - $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"],$js); |
|
| 41 | + if (isset($params["_ajaxSubmit"])) { |
|
| 42 | + $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"], $js); |
|
| 43 | 43 | $this->onSuccess($compilation); |
| 44 | 44 | $form->removeValidationParam("_ajaxSubmit"); |
| 45 | 45 | } |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | $form->addEventsOnRun($js); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - protected function _compileAjaxSubmit($ajaxSubmit,JsUtils $js=null){ |
|
| 51 | + protected function _compileAjaxSubmit($ajaxSubmit, JsUtils $js=null) { |
|
| 52 | 52 | $compilation=""; |
| 53 | - if(\is_array($ajaxSubmit)){ |
|
| 54 | - foreach ($ajaxSubmit as $ajaxSubmitItem){ |
|
| 53 | + if (\is_array($ajaxSubmit)) { |
|
| 54 | + foreach ($ajaxSubmit as $ajaxSubmitItem) { |
|
| 55 | 55 | $compilation.=$ajaxSubmitItem->compile($js); |
| 56 | 56 | } |
| 57 | - }elseif($ajaxSubmit instanceof AjaxCall){ |
|
| 57 | + }elseif ($ajaxSubmit instanceof AjaxCall) { |
|
| 58 | 58 | $compilation=$ajaxSubmit->compile($js); |
| 59 | 59 | } |
| 60 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
| 60 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
| 61 | 61 | return $compilation; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | return $this; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function setAttached($value=true){ |
|
| 73 | + public function setAttached($value=true) { |
|
| 74 | 74 | $form=$this->getForm(); |
| 75 | - if($value) |
|
| 76 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
| 75 | + if ($value) |
|
| 76 | + $form->addToPropertyCtrl("class", "attached", array("attached")); |
|
| 77 | 77 | return $form; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function addErrorMessage(){ |
|
| 80 | + public function addErrorMessage() { |
|
| 81 | 81 | return $this->getForm()->addContent((new HtmlMessage(""))->setError()); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -93,48 +93,48 @@ discard block |
||
| 93 | 93 | * @param array $parameters |
| 94 | 94 | * @return HtmlForm |
| 95 | 95 | */ |
| 96 | - public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){ |
|
| 96 | + public function submitOn($event, $identifierOrElement, $url, $responseElement, $parameters=NULL) { |
|
| 97 | 97 | $form=$this->getForm(); |
| 98 | - if($identifierOrElement instanceof BaseHtml) |
|
| 98 | + if ($identifierOrElement instanceof BaseHtml) |
|
| 99 | 99 | $elem=$identifierOrElement; |
| 100 | 100 | else |
| 101 | 101 | $elem=$form->getElementById($identifierOrElement, $form->getContent()); |
| 102 | - if(isset($elem)){ |
|
| 103 | - $this->_buttonAsSubmit($elem, $event,$url,$responseElement,$parameters); |
|
| 102 | + if (isset($elem)) { |
|
| 103 | + $this->_buttonAsSubmit($elem, $event, $url, $responseElement, $parameters); |
|
| 104 | 104 | } |
| 105 | 105 | return $form; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function submitOnClick($identifier,$url,$responseElement,$parameters=NULL){ |
|
| 109 | - return $this->submitOn("click", $identifier, $url, $responseElement,$parameters); |
|
| 108 | + public function submitOnClick($identifier, $url, $responseElement, $parameters=NULL) { |
|
| 109 | + return $this->submitOn("click", $identifier, $url, $responseElement, $parameters); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
| 113 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
| 114 | - return $this->_buttonAsSubmit($bt, "click",$url,$responseElement,$parameters); |
|
| 112 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
| 113 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
| 114 | + return $this->_buttonAsSubmit($bt, "click", $url, $responseElement, $parameters); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL){ |
|
| 117 | + protected function _buttonAsSubmit(BaseHtml&$button, $event, $url, $responseElement=NULL, $parameters=NULL) { |
|
| 118 | 118 | $form=$this->getForm(); |
| 119 | - if(isset($url) && isset($responseElement)){ |
|
| 120 | - $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true); |
|
| 121 | - $this->setSubmitParams($url,$responseElement,$parameters); |
|
| 119 | + if (isset($url) && isset($responseElement)) { |
|
| 120 | + $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');", true, true); |
|
| 121 | + $this->setSubmitParams($url, $responseElement, $parameters); |
|
| 122 | 122 | } |
| 123 | 123 | return $button; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function setSubmitParams($url,$responseElement=NULL,$parameters=NULL){ |
|
| 126 | + public function setSubmitParams($url, $responseElement=NULL, $parameters=NULL) { |
|
| 127 | 127 | $form=$this->getForm(); |
| 128 | - $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
|
| 129 | - if(\is_array($parameters)){ |
|
| 130 | - $params=\array_merge($params,$parameters); |
|
| 128 | + $params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true]; |
|
| 129 | + if (\is_array($parameters)) { |
|
| 130 | + $params=\array_merge($params, $parameters); |
|
| 131 | 131 | } |
| 132 | 132 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
| 133 | 133 | return $this; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
| 137 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
| 136 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
| 137 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
| 138 | 138 | $bt->setProperty("type", "reset"); |
| 139 | 139 | return $bt; |
| 140 | 140 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param string $jsCode |
| 145 | 145 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 146 | 146 | */ |
| 147 | - public function onValid($jsCode){ |
|
| 147 | + public function onValid($jsCode) { |
|
| 148 | 148 | $form=$this->getForm(); |
| 149 | 149 | $form->addValidationParam("onValid", "%function(){".$jsCode."}%"); |
| 150 | 150 | return $form; |
@@ -155,35 +155,35 @@ discard block |
||
| 155 | 155 | * @param string $jsCode can use event and fields parameters |
| 156 | 156 | * @return HtmlForm |
| 157 | 157 | */ |
| 158 | - public function onSuccess($jsCode){ |
|
| 158 | + public function onSuccess($jsCode) { |
|
| 159 | 159 | $form=$this->getForm(); |
| 160 | - $form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%"); |
|
| 160 | + $form->addValidationParam("onSuccess", $jsCode, "%function(event,fields){", "}%"); |
|
| 161 | 161 | return $form; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - public function addExtraFieldRules($fieldname,$rules){ |
|
| 164 | + public function addExtraFieldRules($fieldname, $rules) { |
|
| 165 | 165 | $form=$this->getForm(); |
| 166 | 166 | $fv=$form->getExtraFieldValidation($fieldname); |
| 167 | - foreach ($rules as $rule){ |
|
| 167 | + foreach ($rules as $rule) { |
|
| 168 | 168 | $fv->addRule($rule); |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function addExtraFieldRule($fieldname,$type,$prompt=NULL,$value=NULL){ |
|
| 172 | + public function addExtraFieldRule($fieldname, $type, $prompt=NULL, $value=NULL) { |
|
| 173 | 173 | $form=$this->getForm(); |
| 174 | 174 | $fv=$form->getExtraFieldValidation($fieldname); |
| 175 | - $fv->addRule($type,$prompt,$value); |
|
| 175 | + $fv->addRule($type, $prompt, $value); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - public function setOptional($fieldname,$optional=true){ |
|
| 178 | + public function setOptional($fieldname, $optional=true) { |
|
| 179 | 179 | $form=$this->getForm(); |
| 180 | 180 | $fv=$form->getExtraFieldValidation($fieldname); |
| 181 | 181 | $fv->setOptional($optional); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function setActionTarget(string $action, string $target){ |
|
| 184 | + public function setActionTarget(string $action, string $target) { |
|
| 185 | 185 | $form=$this->getForm(); |
| 186 | - $form->setProperty('data-target',$target); |
|
| 187 | - $form->setProperty('action',$action); |
|
| 186 | + $form->setProperty('data-target', $target); |
|
| 187 | + $form->setProperty('action', $action); |
|
| 188 | 188 | } |
| 189 | 189 | } |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | * @return HtmlMenu |
| 42 | 42 | */ |
| 43 | 43 | public function setType($type="") { |
| 44 | - return $this->addToPropertyCtrl("class", $type, array ("","item","text" )); |
|
| 44 | + return $this->addToPropertyCtrl("class", $type, array("", "item", "text")); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function setActiveItem($index) { |
| 48 | 48 | $item=$this->getItem($index); |
| 49 | - if ($item !== null) { |
|
| 49 | + if ($item!==null) { |
|
| 50 | 50 | $item->addToProperty("class", "active"); |
| 51 | 51 | } |
| 52 | 52 | return $this; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | private function getItemToInsert($item) { |
| 56 | 56 | if ($item instanceof HtmlInput || $item instanceof HtmlImg || $item instanceof HtmlIcon || $item instanceof HtmlButtonGroups || $item instanceof HtmlButton || $item instanceof HtmlLabel) { |
| 57 | - $itemO=new HtmlMenuItem("item-" . $this->identifier . "-" . \sizeof($this->content) , $item); |
|
| 57 | + $itemO=new HtmlMenuItem("item-".$this->identifier."-".\sizeof($this->content), $item); |
|
| 58 | 58 | $itemO->addClass("no-active"); |
| 59 | 59 | $item=$itemO; |
| 60 | 60 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | private function afterInsert($item) { |
| 65 | 65 | if (!$item instanceof HtmlMenu && $item->propertyContains("class", "header")===false) |
| 66 | - $item->addToPropertyCtrl("class", "item", array ("item" )); |
|
| 66 | + $item->addToPropertyCtrl("class", "item", array("item")); |
|
| 67 | 67 | else { |
| 68 | 68 | $this->setSecondary(); |
| 69 | 69 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | public function addItem($item) { |
| 80 | 80 | $number=$item; |
| 81 | 81 | $item=parent::addItem($this->getItemToInsert($item)); |
| 82 | - if(\is_int($number)) |
|
| 82 | + if (\is_int($number)) |
|
| 83 | 83 | $item->setProperty("data-page", $number); |
| 84 | 84 | return $this->afterInsert($item); |
| 85 | 85 | } |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | public function generateMenuAsItem($menu, $header=null) { |
| 99 | 99 | $count=$this->count(); |
| 100 | - $item=new HtmlSemDoubleElement("item-" . $this->identifier . "-" . $count, "div"); |
|
| 100 | + $item=new HtmlSemDoubleElement("item-".$this->identifier."-".$count, "div"); |
|
| 101 | 101 | if (isset($header)) { |
| 102 | - $headerItem=new HtmlSemDoubleElement("item-header-" . $this->identifier . "-" . $count, "div", "header"); |
|
| 102 | + $headerItem=new HtmlSemDoubleElement("item-header-".$this->identifier."-".$count, "div", "header"); |
|
| 103 | 103 | $headerItem->setContent($header); |
| 104 | 104 | $item->addContent($headerItem); |
| 105 | 105 | $this->_itemHeader=$headerItem; |
| 106 | 106 | } |
| 107 | - if(\is_array($menu)){ |
|
| 108 | - $menu=new HtmlMenu("menu-" . $this->identifier . "-" . $count,$menu); |
|
| 107 | + if (\is_array($menu)) { |
|
| 108 | + $menu=new HtmlMenu("menu-".$this->identifier."-".$count, $menu); |
|
| 109 | 109 | } |
| 110 | 110 | $menu->setClass("menu"); |
| 111 | 111 | $item->addContent($menu); |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | * @param String|HtmlDoubleElement $caption |
| 118 | 118 | * @return \Ajax\common\html\HtmlDoubleElement |
| 119 | 119 | */ |
| 120 | - public function addHeader($caption){ |
|
| 121 | - if(!($caption instanceof HtmlDoubleElement)){ |
|
| 122 | - $header=new HtmlDoubleElement('','div'); |
|
| 120 | + public function addHeader($caption) { |
|
| 121 | + if (!($caption instanceof HtmlDoubleElement)) { |
|
| 122 | + $header=new HtmlDoubleElement('', 'div'); |
|
| 123 | 123 | $header->setContent($caption); |
| 124 | - }else{ |
|
| 124 | + } else { |
|
| 125 | 125 | $header=$caption; |
| 126 | 126 | } |
| 127 | 127 | $header->addClass('item header'); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $value=new HtmlSemDoubleElement($identifier, "a", "browse item", $value); |
| 138 | 138 | $value->addContent(new HtmlIcon("", "dropdown")); |
| 139 | 139 | $value=$this->addItem($value); |
| 140 | - $popup=new HtmlPopup($value, "popup-" . $this->identifier . "-" . $this->count(), $content); |
|
| 140 | + $popup=new HtmlPopup($value, "popup-".$this->identifier."-".$this->count(), $content); |
|
| 141 | 141 | $popup->setFlowing()->setPosition("bottom left")->setOn("click"); |
| 142 | 142 | $this->wrap("", $popup); |
| 143 | 143 | return $popup; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | public function addDropdownAsItem($value, $items=NULL) { |
| 147 | 147 | $dd=$value; |
| 148 | 148 | if (\is_string($value)) { |
| 149 | - $dd=new HtmlDropdown("dropdown-" . $this->identifier . "-" . $this->count(), $value, $items); |
|
| 149 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$this->count(), $value, $items); |
|
| 150 | 150 | } |
| 151 | 151 | $this->addItem($dd); |
| 152 | 152 | return $dd; |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | * @see HtmlCollection::createItem() |
| 160 | 160 | */ |
| 161 | 161 | protected function createItem($value) { |
| 162 | - $itemO=new HtmlMenuItem($this->identifier."-item-" . \sizeof($this->content),""); |
|
| 162 | + $itemO=new HtmlMenuItem($this->identifier."-item-".\sizeof($this->content), ""); |
|
| 163 | 163 | $itemO->setTagName("a"); |
| 164 | 164 | $itemO->setContent($value); |
| 165 | 165 | return $itemO; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | public function setSecondary($value=true) { |
| 169 | - if($value) |
|
| 169 | + if ($value) |
|
| 170 | 170 | $this->addToProperty("class", "secondary"); |
| 171 | 171 | else |
| 172 | 172 | $this->removePropertyValue("class", "secondary"); |
@@ -174,28 +174,28 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | public function setVertical() { |
| 177 | - return $this->addToPropertyCtrl("class", "vertical", array ("vertical" )); |
|
| 177 | + return $this->addToPropertyCtrl("class", "vertical", array("vertical")); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function setPosition($value="right") { |
| 181 | - return $this->addToPropertyCtrl("class", $value, array ("right","left" )); |
|
| 181 | + return $this->addToPropertyCtrl("class", $value, array("right", "left")); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public function setPointing($value=Direction::NONE) { |
| 185 | - return $this->addToPropertyCtrl("class", $value . " pointing", Direction::getConstantValues("pointing")); |
|
| 185 | + return $this->addToPropertyCtrl("class", $value." pointing", Direction::getConstantValues("pointing")); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function asTab($vertical=false) { |
| 189 | - $this->apply(function (HtmlDoubleElement &$item) { |
|
| 189 | + $this->apply(function(HtmlDoubleElement&$item) { |
|
| 190 | 190 | $item->setTagName("a"); |
| 191 | 191 | }); |
| 192 | - if ($vertical === true) |
|
| 192 | + if ($vertical===true) |
|
| 193 | 193 | $this->setVertical(); |
| 194 | 194 | return $this->addToProperty("class", "tabular"); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | public function asPagination() { |
| 198 | - $this->apply(function (HtmlDoubleElement &$item) { |
|
| 198 | + $this->apply(function(HtmlDoubleElement&$item) { |
|
| 199 | 199 | $item->setTagName("a"); |
| 200 | 200 | }); |
| 201 | 201 | return $this->addToProperty("class", "pagination"); |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public function setWidth($width) { |
| 234 | 234 | if (\is_int($width)) { |
| 235 | - $width=Wide::getConstants()["W" . $width]; |
|
| 235 | + $width=Wide::getConstants()["W".$width]; |
|
| 236 | 236 | } |
| 237 | 237 | $this->addToPropertyCtrl("class", $width, Wide::getConstants()); |
| 238 | - return $this->addToPropertyCtrl("class", "item", array ("item" )); |
|
| 238 | + return $this->addToPropertyCtrl("class", "item", array("item")); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | public function addImage($identifier, $src="", $alt="") { |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | return $this->_itemHeader; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - public function setHasContainer(){ |
|
| 254 | - return $this->wrapContent("<div class='ui container'>","</div>"); |
|
| 253 | + public function setHasContainer() { |
|
| 254 | + return $this->wrapContent("<div class='ui container'>", "</div>"); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - public function run(JsUtils $js){ |
|
| 258 | - if($this->identifier!=="" && !isset($this->_bsComponent)) |
|
| 259 | - $this->onClick('if(!$(this).hasClass("dropdown")&&!$(this).hasClass("no-active")){$(this).addClass("active").siblings().removeClass("active");}',false,false); |
|
| 260 | - $result= parent::run($js); |
|
| 257 | + public function run(JsUtils $js) { |
|
| 258 | + if ($this->identifier!=="" && !isset($this->_bsComponent)) |
|
| 259 | + $this->onClick('if(!$(this).hasClass("dropdown")&&!$(this).hasClass("no-active")){$(this).addClass("active").siblings().removeClass("active");}', false, false); |
|
| 260 | + $result=parent::run($js); |
|
| 261 | 261 | return $result->setItemSelector(">.item:not(.header)"); |
| 262 | 262 | } |
| 263 | 263 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @version 1.001 |
| 9 | 9 | * Generates a JSON Rule for the validation of a field |
| 10 | 10 | */ |
| 11 | -class Rule implements \JsonSerializable{ |
|
| 11 | +class Rule implements \JsonSerializable { |
|
| 12 | 12 | /** |
| 13 | 13 | * @var string |
| 14 | 14 | */ |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | private $value; |
| 25 | 25 | |
| 26 | - public function __construct($type,$prompt=NULL,$value=NULL){ |
|
| 26 | + public function __construct($type, $prompt=NULL, $value=NULL) { |
|
| 27 | 27 | $this->type=$type; |
| 28 | 28 | $this->prompt=$prompt; |
| 29 | 29 | $this->value=$value; |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | #[\ReturnTypeWillChange] |
| 60 | 60 | public function jsonSerialize() { |
| 61 | - $result= ["type"=>$this->type]; |
|
| 62 | - if(isset($this->prompt)) |
|
| 61 | + $result=["type"=>$this->type]; |
|
| 62 | + if (isset($this->prompt)) |
|
| 63 | 63 | $result["prompt"]=$this->prompt; |
| 64 | - if(isset($this->value)) |
|
| 64 | + if (isset($this->value)) |
|
| 65 | 65 | $result["value"]=$this->value; |
| 66 | 66 | return $result; |
| 67 | 67 | } |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * @param string $prompt |
| 73 | 73 | * @return \Ajax\semantic\components\validation\Rule |
| 74 | 74 | */ |
| 75 | - public static function match($name,$prompt=NULL){ |
|
| 76 | - return new Rule("match[".$name."]",$prompt); |
|
| 75 | + public static function match($name, $prompt=NULL){ |
|
| 76 | + return new Rule("match[".$name."]", $prompt); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param string $prompt |
| 83 | 83 | * @return \Ajax\semantic\components\validation\Rule |
| 84 | 84 | */ |
| 85 | - public static function different($name,$prompt=NULL){ |
|
| 86 | - return new Rule("different[".$name."]",$prompt); |
|
| 85 | + public static function different($name, $prompt=NULL) { |
|
| 86 | + return new Rule("different[".$name."]", $prompt); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -93,82 +93,82 @@ discard block |
||
| 93 | 93 | * @param string $prompt |
| 94 | 94 | * @return \Ajax\semantic\components\validation\Rule |
| 95 | 95 | */ |
| 96 | - public static function integer($min=NULL,$max=NULL,$prompt=NULL){ |
|
| 97 | - if(\is_int($min) && \is_int($max)) |
|
| 98 | - return new Rule("integer[{$min}..{$max}]",$prompt); |
|
| 99 | - return new Rule("integer",$prompt); |
|
| 96 | + public static function integer($min=NULL, $max=NULL, $prompt=NULL) { |
|
| 97 | + if (\is_int($min) && \is_int($max)) |
|
| 98 | + return new Rule("integer[{$min}..{$max}]", $prompt); |
|
| 99 | + return new Rule("integer", $prompt); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public static function decimal($prompt=NULL){ |
|
| 103 | - return new Rule("decimal",$prompt); |
|
| 102 | + public static function decimal($prompt=NULL) { |
|
| 103 | + return new Rule("decimal", $prompt); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - public static function number($prompt=NULL){ |
|
| 107 | - return new Rule("number",$prompt); |
|
| 106 | + public static function number($prompt=NULL) { |
|
| 107 | + return new Rule("number", $prompt); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public static function is($value,$prompt=NULL){ |
|
| 111 | - return new Rule("is[".$value."]",$prompt); |
|
| 110 | + public static function is($value, $prompt=NULL) { |
|
| 111 | + return new Rule("is[".$value."]", $prompt); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public static function isExactly($value,$prompt=NULL){ |
|
| 115 | - return new Rule("isExactly[".$value."]",$prompt); |
|
| 114 | + public static function isExactly($value, $prompt=NULL) { |
|
| 115 | + return new Rule("isExactly[".$value."]", $prompt); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public static function not($value,$prompt=NULL){ |
|
| 119 | - return new Rule("not[".$value."]",$prompt); |
|
| 118 | + public static function not($value, $prompt=NULL) { |
|
| 119 | + return new Rule("not[".$value."]", $prompt); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public static function notExactly($value,$prompt=NULL){ |
|
| 123 | - return new Rule("notExactly[".$value."]",$prompt); |
|
| 122 | + public static function notExactly($value, $prompt=NULL) { |
|
| 123 | + return new Rule("notExactly[".$value."]", $prompt); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public static function contains($value,$prompt=NULL){ |
|
| 127 | - return new Rule("contains[".$value."]",$prompt); |
|
| 126 | + public static function contains($value, $prompt=NULL) { |
|
| 127 | + return new Rule("contains[".$value."]", $prompt); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public static function containsExactly($value,$prompt=NULL){ |
|
| 131 | - return new Rule("containsExactly[".$value."]",$prompt); |
|
| 130 | + public static function containsExactly($value, $prompt=NULL) { |
|
| 131 | + return new Rule("containsExactly[".$value."]", $prompt); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - public static function doesntContain($value,$prompt=NULL){ |
|
| 135 | - return new Rule("doesntContain[".$value."]",$prompt); |
|
| 134 | + public static function doesntContain($value, $prompt=NULL) { |
|
| 135 | + return new Rule("doesntContain[".$value."]", $prompt); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public static function doesntContainExactly($value,$prompt=NULL){ |
|
| 139 | - return new Rule("doesntContainExactly[".$value."]",$prompt); |
|
| 138 | + public static function doesntContainExactly($value, $prompt=NULL) { |
|
| 139 | + return new Rule("doesntContainExactly[".$value."]", $prompt); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public static function minCount($value,$prompt=NULL){ |
|
| 143 | - return new Rule("minCount[".$value."]",$prompt); |
|
| 142 | + public static function minCount($value, $prompt=NULL) { |
|
| 143 | + return new Rule("minCount[".$value."]", $prompt); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public static function maxCount($value,$prompt=NULL){ |
|
| 147 | - return new Rule("maxCount[".$value."]",$prompt); |
|
| 146 | + public static function maxCount($value, $prompt=NULL) { |
|
| 147 | + return new Rule("maxCount[".$value."]", $prompt); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public static function exactCount($value,$prompt=NULL){ |
|
| 151 | - return new Rule("exactCount[".$value."]",$prompt); |
|
| 150 | + public static function exactCount($value, $prompt=NULL) { |
|
| 151 | + return new Rule("exactCount[".$value."]", $prompt); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - public static function email($prompt=NULL){ |
|
| 155 | - return new Rule("email",$prompt); |
|
| 154 | + public static function email($prompt=NULL) { |
|
| 155 | + return new Rule("email", $prompt); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - public static function url($prompt=NULL){ |
|
| 159 | - return new Rule("url",$prompt); |
|
| 158 | + public static function url($prompt=NULL) { |
|
| 159 | + return new Rule("url", $prompt); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public static function regExp($value,$prompt=NULL){ |
|
| 163 | - return new Rule("regExp",$prompt,$value); |
|
| 162 | + public static function regExp($value, $prompt=NULL) { |
|
| 163 | + return new Rule("regExp", $prompt, $value); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - public static function custom($name,$jsFunction){ |
|
| 167 | - return "$.fn.form.settings.rules.".$name." =".$jsFunction ; |
|
| 166 | + public static function custom($name, $jsFunction) { |
|
| 167 | + return "$.fn.form.settings.rules.".$name." =".$jsFunction; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - public static function ajax(JsUtils $js,$name,$url,$params,$jsCallback,$method="post",$parameters=[]){ |
|
| 171 | - $parameters=\array_merge(["async"=>false,"url"=>$url,"params"=>$params,"hasLoader"=>false,"jsCallback"=>$jsCallback,"dataType"=>"json","stopPropagation"=>false,"preventDefault"=>false,"responseElement"=>null],$parameters); |
|
| 170 | + public static function ajax(JsUtils $js, $name, $url, $params, $jsCallback, $method="post", $parameters=[]) { |
|
| 171 | + $parameters=\array_merge(["async"=>false, "url"=>$url, "params"=>$params, "hasLoader"=>false, "jsCallback"=>$jsCallback, "dataType"=>"json", "stopPropagation"=>false, "preventDefault"=>false, "responseElement"=>null], $parameters); |
|
| 172 | 172 | $ajax=new AjaxCall($method, $parameters); |
| 173 | 173 | return self::custom($name, "function(value,ruleValue){var result=true;".$ajax->compile($js)."return result;}"); |
| 174 | 174 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | trait JsUtilsActionsTrait { |
| 14 | 14 | |
| 15 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false); |
|
| 15 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * show or hide with effect |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | * defers the execution if set to false |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - protected function _showHideWithEffect($action, $element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 32 | - $element = Javascript::prep_element ( $element ); |
|
| 33 | - $speed = $this->_validate_speed ( $speed ); |
|
| 34 | - if ($callback != '') { |
|
| 35 | - $callback = ", function(){\n{$callback}\n}"; |
|
| 31 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
| 32 | + $element=Javascript::prep_element($element); |
|
| 33 | + $speed=$this->_validate_speed($speed); |
|
| 34 | + if ($callback!='') { |
|
| 35 | + $callback=", function(){\n{$callback}\n}"; |
|
| 36 | 36 | } |
| 37 | - $str = "$({$element}).{$action}({$speed}{$callback});"; |
|
| 37 | + $str="$({$element}).{$action}({$speed}{$callback});"; |
|
| 38 | 38 | if ($immediatly) |
| 39 | - $this->jquery_code_for_compile [] = $str; |
|
| 39 | + $this->jquery_code_for_compile []=$str; |
|
| 40 | 40 | return $str; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | private function _validate_speed($speed) { |
| 50 | - if (in_array ( $speed, array ( |
|
| 50 | + if (in_array($speed, array( |
|
| 51 | 51 | 'slow', |
| 52 | 52 | 'normal', |
| 53 | 53 | 'fast' |
| 54 | - ) )) { |
|
| 55 | - $speed = '"' . $speed . '"'; |
|
| 56 | - } elseif (preg_match ( "/[^0-9]/", $speed )) { |
|
| 57 | - $speed = ''; |
|
| 54 | + ))) { |
|
| 55 | + $speed='"'.$speed.'"'; |
|
| 56 | + } elseif (preg_match("/[^0-9]/", $speed)) { |
|
| 57 | + $speed=''; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $speed; |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | * @param boolean $immediatly |
| 70 | 70 | * delayed if false |
| 71 | 71 | */ |
| 72 | - public function _genericCallValue($jQueryCall, $element = 'this', $param = "", $immediatly = false) { |
|
| 73 | - $element = Javascript::prep_element ( $element ); |
|
| 74 | - if (isset ( $param )) { |
|
| 75 | - $param = Javascript::prep_value ( $param ); |
|
| 76 | - $str = "$({$element}).{$jQueryCall}({$param});"; |
|
| 72 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
| 73 | + $element=Javascript::prep_element($element); |
|
| 74 | + if (isset ($param)) { |
|
| 75 | + $param=Javascript::prep_value($param); |
|
| 76 | + $str="$({$element}).{$jQueryCall}({$param});"; |
|
| 77 | 77 | } else |
| 78 | - $str = "$({$element}).{$jQueryCall}();"; |
|
| 78 | + $str="$({$element}).{$jQueryCall}();"; |
|
| 79 | 79 | if ($immediatly) |
| 80 | - $this->jquery_code_for_compile [] = $str; |
|
| 80 | + $this->jquery_code_for_compile []=$str; |
|
| 81 | 81 | return $str; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | * delayed if false |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function _genericCallElement($jQueryCall, $to = 'this', $element = '', $immediatly = false) { |
|
| 95 | - $to = Javascript::prep_element ( $to ); |
|
| 96 | - $element = Javascript::prep_element ( $element ); |
|
| 97 | - $str = "$({$to}).{$jQueryCall}({$element});"; |
|
| 94 | + public function _genericCallElement($jQueryCall, $to='this', $element='', $immediatly=false) { |
|
| 95 | + $to=Javascript::prep_element($to); |
|
| 96 | + $element=Javascript::prep_element($element); |
|
| 97 | + $str="$({$to}).{$jQueryCall}({$element});"; |
|
| 98 | 98 | if ($immediatly) |
| 99 | - $this->jquery_code_for_compile [] = $str; |
|
| 99 | + $this->jquery_code_for_compile []=$str; |
|
| 100 | 100 | return $str; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | * defers the execution if set to false |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - public function addClass($element = 'this', $class = '', $immediatly = false) { |
|
| 114 | - return $this->_genericCallValue ( 'addClass', $element, $class, $immediatly ); |
|
| 113 | + public function addClass($element='this', $class='', $immediatly=false) { |
|
| 114 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * defers the execution if set to false |
| 124 | 124 | * @return string |
| 125 | 125 | */ |
| 126 | - public function after($to, $element, $immediatly = false) { |
|
| 127 | - return $this->_genericCallElement ( 'after', $to, $element, $immediatly ); |
|
| 126 | + public function after($to, $element, $immediatly=false) { |
|
| 127 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * defers the execution if set to false |
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | - public function before($to, $element, $immediatly = false) { |
|
| 140 | - return $this->_genericCallElement ( 'before', $to, $element, $immediatly ); |
|
| 139 | + public function before($to, $element, $immediatly=false) { |
|
| 140 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -149,15 +149,15 @@ discard block |
||
| 149 | 149 | * @param boolean $immediatly |
| 150 | 150 | * delayed if false |
| 151 | 151 | */ |
| 152 | - public function attr($element = 'this', $attributeName = 'id', $value = "", $immediatly = false) { |
|
| 153 | - $element = Javascript::prep_element ( $element ); |
|
| 154 | - if (isset ( $value )) { |
|
| 155 | - $value = Javascript::prep_value ( $value ); |
|
| 156 | - $str = "$({$element}).attr(\"$attributeName\",{$value});"; |
|
| 152 | + public function attr($element='this', $attributeName='id', $value="", $immediatly=false) { |
|
| 153 | + $element=Javascript::prep_element($element); |
|
| 154 | + if (isset ($value)) { |
|
| 155 | + $value=Javascript::prep_value($value); |
|
| 156 | + $str="$({$element}).attr(\"$attributeName\",{$value});"; |
|
| 157 | 157 | } else |
| 158 | - $str = "$({$element}).attr(\"$attributeName\");"; |
|
| 158 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
| 159 | 159 | if ($immediatly) |
| 160 | - $this->jquery_code_for_compile [] = $str; |
|
| 160 | + $this->jquery_code_for_compile []=$str; |
|
| 161 | 161 | return $str; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | * @param boolean $immediatly |
| 170 | 170 | * defers the execution if set to false |
| 171 | 171 | */ |
| 172 | - public function val($element = 'this', $value = '', $immediatly = false) { |
|
| 173 | - return $this->_genericCallValue ( 'val', $element, $value, $immediatly ); |
|
| 172 | + public function val($element='this', $value='', $immediatly=false) { |
|
| 173 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param boolean $immediatly |
| 182 | 182 | * defers the execution if set to false |
| 183 | 183 | */ |
| 184 | - public function html($element = 'this', $value = '', $immediatly = false) { |
|
| 185 | - return $this->_genericCallValue ( 'html', $element, $value, $immediatly ); |
|
| 184 | + public function html($element='this', $value='', $immediatly=false) { |
|
| 185 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -198,30 +198,30 @@ discard block |
||
| 198 | 198 | * defers the execution if set to false |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public function animate($element = 'this', $params = array (), $speed = '', $extra = '', $immediatly = false) { |
|
| 202 | - $element = Javascript::prep_element ( $element ); |
|
| 203 | - $speed = $this->_validate_speed ( $speed ); |
|
| 201 | + public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
|
| 202 | + $element=Javascript::prep_element($element); |
|
| 203 | + $speed=$this->_validate_speed($speed); |
|
| 204 | 204 | |
| 205 | - $animations = "\t\t\t"; |
|
| 206 | - if (\is_array ( $params )) { |
|
| 207 | - foreach ( $params as $param => $value ) { |
|
| 208 | - $animations .= $param . ': \'' . $value . '\', '; |
|
| 205 | + $animations="\t\t\t"; |
|
| 206 | + if (\is_array ($params)) { |
|
| 207 | + foreach ($params as $param => $value) { |
|
| 208 | + $animations.=$param.': \''.$value.'\', '; |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | - $animations = substr ( $animations, 0, - 2 ); // remove the last ", " |
|
| 211 | + $animations=substr($animations, 0, - 2); // remove the last ", " |
|
| 212 | 212 | |
| 213 | - if ($speed != '') { |
|
| 214 | - $speed = ', ' . $speed; |
|
| 213 | + if ($speed!='') { |
|
| 214 | + $speed=', '.$speed; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ($extra != '') { |
|
| 218 | - $extra = ', ' . $extra; |
|
| 217 | + if ($extra!='') { |
|
| 218 | + $extra=', '.$extra; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");"; |
|
| 221 | + $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
|
| 222 | 222 | |
| 223 | 223 | if ($immediatly) |
| 224 | - $this->jquery_code_for_compile [] = $str; |
|
| 224 | + $this->jquery_code_for_compile []=$str; |
|
| 225 | 225 | return $str; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * defers the execution if set to false |
| 235 | 235 | * @return string |
| 236 | 236 | */ |
| 237 | - public function append($to, $element, $immediatly = false) { |
|
| 238 | - return $this->_genericCallElement ( 'append', $to, $element, $immediatly ); |
|
| 237 | + public function append($to, $element, $immediatly=false) { |
|
| 238 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * defers the execution if set to false |
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | - public function prepend($to, $element, $immediatly = false) { |
|
| 251 | - return $this->_genericCallElement ( 'prepend', $to, $element, $immediatly ); |
|
| 250 | + public function prepend($to, $element, $immediatly=false) { |
|
| 251 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | * defers the execution if set to false |
| 265 | 265 | * @return string |
| 266 | 266 | */ |
| 267 | - public function fadeIn($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 268 | - return $this->_showHideWithEffect ( "fadeIn", $element, $speed, $callback, $immediatly ); |
|
| 267 | + public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 268 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * defers the execution if set to false |
| 282 | 282 | * @return string |
| 283 | 283 | */ |
| 284 | - public function fadeOut($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 285 | - return $this->_showHideWithEffect ( "fadeOut", $element, $speed, $callback, $immediatly ); |
|
| 284 | + public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 285 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * defers the execution if set to false |
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | - public function slideUp($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 302 | - return $this->_showHideWithEffect ( "slideUp", $element, $speed, $callback, $immediatly ); |
|
| 301 | + public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 302 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | * defers the execution if set to false |
| 314 | 314 | * @return string |
| 315 | 315 | */ |
| 316 | - public function removeClass($element = 'this', $class = '', $immediatly = false) { |
|
| 317 | - return $this->_genericCallValue ( 'removeClass', $element, $class, $immediatly ); |
|
| 316 | + public function removeClass($element='this', $class='', $immediatly=false) { |
|
| 317 | + return $this->_genericCallValue('removeClass', $element, $class, $immediatly); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -330,8 +330,8 @@ discard block |
||
| 330 | 330 | * defers the execution if set to false |
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | - public function slideDown($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 334 | - return $this->_showHideWithEffect ( "slideDown", $element, $speed, $callback, $immediatly ); |
|
| 333 | + public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 334 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * defers the execution if set to false |
| 348 | 348 | * @return string |
| 349 | 349 | */ |
| 350 | - public function slideToggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 351 | - return $this->_showHideWithEffect ( "slideToggle", $element, $speed, $callback, $immediatly ); |
|
| 350 | + public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 351 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * defers the execution if set to false |
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | - public function hide($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 368 | - return $this->_showHideWithEffect ( "hide", $element, $speed, $callback, $immediatly ); |
|
| 367 | + public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 368 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * defers the execution if set to false |
| 382 | 382 | * @return string |
| 383 | 383 | */ |
| 384 | - public function toggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 385 | - return $this->_showHideWithEffect ( "toggle", $element, $speed, $callback, $immediatly ); |
|
| 384 | + public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 385 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * defers the execution if set to false |
| 396 | 396 | * @return string |
| 397 | 397 | */ |
| 398 | - public function toggleClass($element = 'this', $class = '', $immediatly = false) { |
|
| 399 | - return $this->_genericCallValue ( 'toggleClass', $element, $class, $immediatly ); |
|
| 398 | + public function toggleClass($element='this', $class='', $immediatly=false) { |
|
| 399 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -407,12 +407,12 @@ discard block |
||
| 407 | 407 | * @param boolean $immediatly |
| 408 | 408 | * defers the execution if set to false |
| 409 | 409 | */ |
| 410 | - public function trigger($element = 'this', $event = 'click', $immediatly = false) { |
|
| 411 | - $element = Javascript::prep_element ( $element ); |
|
| 412 | - $str = "$({$element}).trigger(\"$event\");"; |
|
| 410 | + public function trigger($element='this', $event='click', $immediatly=false) { |
|
| 411 | + $element=Javascript::prep_element($element); |
|
| 412 | + $str="$({$element}).trigger(\"$event\");"; |
|
| 413 | 413 | |
| 414 | 414 | if ($immediatly) |
| 415 | - $this->jquery_code_for_compile [] = $str; |
|
| 415 | + $this->jquery_code_for_compile []=$str; |
|
| 416 | 416 | return $str; |
| 417 | 417 | } |
| 418 | 418 | |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * defers the execution if set to false |
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | - public function show($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 433 | - return $this->_showHideWithEffect ( "show", $element, $speed, $callback, $immediatly ); |
|
| 432 | + public function show($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 433 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -440,18 +440,18 @@ discard block |
||
| 440 | 440 | * @param array $options |
| 441 | 441 | * @return string |
| 442 | 442 | */ |
| 443 | - public function sortable($element, $options = array ()) { |
|
| 444 | - if (count ( $options ) > 0) { |
|
| 445 | - $sort_options = array (); |
|
| 446 | - foreach ( $options as $k => $v ) { |
|
| 447 | - $sort_options [] = "\n\t\t" . $k . ': ' . $v . ""; |
|
| 443 | + public function sortable($element, $options=array()) { |
|
| 444 | + if (count($options)>0) { |
|
| 445 | + $sort_options=array(); |
|
| 446 | + foreach ($options as $k => $v) { |
|
| 447 | + $sort_options []="\n\t\t".$k.': '.$v.""; |
|
| 448 | 448 | } |
| 449 | - $sort_options = implode ( ",", $sort_options ); |
|
| 449 | + $sort_options=implode(",", $sort_options); |
|
| 450 | 450 | } else { |
| 451 | - $sort_options = ''; |
|
| 451 | + $sort_options=''; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - return "$(" . Javascript::prep_element ( $element ) . ").sortable({" . $sort_options . "\n\t});"; |
|
| 454 | + return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});"; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -463,8 +463,8 @@ discard block |
||
| 463 | 463 | * plugin location |
| 464 | 464 | * @return string |
| 465 | 465 | */ |
| 466 | - public function tablesorter($table = '', $options = '') { |
|
| 467 | - $this->jquery_code_for_compile [] = "\t$(" . Javascript::prep_element ( $table ) . ").tablesorter($options);\n"; |
|
| 466 | + public function tablesorter($table='', $options='') { |
|
| 467 | + $this->jquery_code_for_compile []="\t$(".Javascript::prep_element($table).").tablesorter($options);\n"; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -476,14 +476,14 @@ discard block |
||
| 476 | 476 | * @param boolean $immediatly |
| 477 | 477 | * defers the execution if set to false |
| 478 | 478 | */ |
| 479 | - public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse = null, $immediatly = false) { |
|
| 480 | - $str = "if(" . $condition . "){" . $jsCodeIfTrue . "}"; |
|
| 481 | - if (isset ( $jsCodeIfFalse )) { |
|
| 482 | - $str .= "else{" . $jsCodeIfFalse . "}"; |
|
| 479 | + public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
|
| 480 | + $str="if(".$condition."){".$jsCodeIfTrue."}"; |
|
| 481 | + if (isset ($jsCodeIfFalse)) { |
|
| 482 | + $str.="else{".$jsCodeIfFalse."}"; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | if ($immediatly) |
| 486 | - $this->jquery_code_for_compile [] = $str; |
|
| 486 | + $this->jquery_code_for_compile []=$str; |
|
| 487 | 487 | return $str; |
| 488 | 488 | } |
| 489 | 489 | |
@@ -498,14 +498,14 @@ discard block |
||
| 498 | 498 | * @param boolean $immediatly |
| 499 | 499 | * @return string |
| 500 | 500 | */ |
| 501 | - private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) { |
|
| 502 | - $param = Javascript::prep_value ( $param ); |
|
| 503 | - $callback = ""; |
|
| 504 | - if ($jsCallback != "") |
|
| 505 | - $callback = ", function(event){\n{$jsCallback}\n}"; |
|
| 506 | - $script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n"; |
|
| 501 | + private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
|
| 502 | + $param=Javascript::prep_value($param); |
|
| 503 | + $callback=""; |
|
| 504 | + if ($jsCallback!="") |
|
| 505 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
| 506 | + $script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
|
| 507 | 507 | if ($immediatly) |
| 508 | - $this->jquery_code_for_compile [] = $script; |
|
| 508 | + $this->jquery_code_for_compile []=$script; |
|
| 509 | 509 | return $script; |
| 510 | 510 | } |
| 511 | 511 | |
@@ -522,8 +522,8 @@ discard block |
||
| 522 | 522 | * javascript code to execute after the jquery call |
| 523 | 523 | * @return mixed |
| 524 | 524 | */ |
| 525 | - public function doJQuery($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
| 526 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, true ); |
|
| 525 | + public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") { |
|
| 526 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * javascript code to execute after the jquery call |
| 540 | 540 | * @return mixed |
| 541 | 541 | */ |
| 542 | - public function doJQueryDeferred($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
| 543 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, false ); |
|
| 542 | + public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") { |
|
| 543 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -557,8 +557,8 @@ discard block |
||
| 557 | 557 | * @param boolean $immediatly |
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $preventDefault = false, $stopPropagation = false, $jsCallback = "", $immediatly = true) { |
|
| 561 | - return $this->_add_event ( $element, $this->_doJQuery ( $elementToModify, $jqueryCall, $param, $jsCallback ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
| 560 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
| 561 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | * @param array $parameters |
| 573 | 573 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true) |
| 574 | 574 | */ |
| 575 | - public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $parameters = array ()) { |
|
| 576 | - $jsCallback = ""; |
|
| 577 | - $stopPropagation = false; |
|
| 578 | - $preventDefault = false; |
|
| 579 | - $immediatly = true; |
|
| 580 | - extract ( $parameters ); |
|
| 581 | - return $this->_doJQueryOn ( $event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly ); |
|
| 575 | + public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) { |
|
| 576 | + $jsCallback=""; |
|
| 577 | + $stopPropagation=false; |
|
| 578 | + $preventDefault=false; |
|
| 579 | + $immediatly=true; |
|
| 580 | + extract($parameters); |
|
| 581 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * delayed if false |
| 591 | 591 | * @return String |
| 592 | 592 | */ |
| 593 | - public function exec($js, $immediatly = false) { |
|
| 594 | - $script = $js . "\n"; |
|
| 593 | + public function exec($js, $immediatly=false) { |
|
| 594 | + $script=$js."\n"; |
|
| 595 | 595 | if ($immediatly) |
| 596 | - $this->jquery_code_for_compile [] = $script; |
|
| 596 | + $this->jquery_code_for_compile []=$script; |
|
| 597 | 597 | return $script; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -607,8 +607,8 @@ discard block |
||
| 607 | 607 | * @return String |
| 608 | 608 | */ |
| 609 | 609 | public function execAtLast($js) { |
| 610 | - $script = $js . "\n"; |
|
| 611 | - $this->jquery_code_for_compile_at_last [] = $script; |
|
| 610 | + $script=$js."\n"; |
|
| 611 | + $this->jquery_code_for_compile_at_last []=$script; |
|
| 612 | 612 | return $script; |
| 613 | 613 | } |
| 614 | 614 | |
@@ -623,18 +623,18 @@ discard block |
||
| 623 | 623 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
| 624 | 624 | * @return String |
| 625 | 625 | */ |
| 626 | - public function execOn($event, $element, $js, $parameters = array ()) { |
|
| 627 | - $stopPropagation = false; |
|
| 628 | - $preventDefault = false; |
|
| 629 | - $immediatly = true; |
|
| 630 | - extract ( $parameters ); |
|
| 631 | - $script = $this->_add_event ( $element, $this->exec ( $js ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
| 626 | + public function execOn($event, $element, $js, $parameters=array()) { |
|
| 627 | + $stopPropagation=false; |
|
| 628 | + $preventDefault=false; |
|
| 629 | + $immediatly=true; |
|
| 630 | + extract($parameters); |
|
| 631 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 632 | 632 | return $script; |
| 633 | 633 | } |
| 634 | - public function setJsonToElement($json, $elementClass = "_element", $immediatly = true) { |
|
| 635 | - $retour = "var data={$json};" . "\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);" . "\n\tvar pk=data['pk'];var object=data['object'];" . "\n\tfor(var field in object){" . "\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){" . "\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){" . "\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }" . "\n\t});" . "\n}};\n"; |
|
| 636 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 637 | - return $this->exec ( $retour, $immediatly ); |
|
| 634 | + public function setJsonToElement($json, $elementClass="_element", $immediatly=true) { |
|
| 635 | + $retour="var data={$json};"."\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);"."\n\tvar pk=data['pk'];var object=data['object'];"."\n\tfor(var field in object){"."\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){"."\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){"."\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }"."\n\t});"."\n}};\n"; |
|
| 636 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 637 | + return $this->exec($retour, $immediatly); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -645,13 +645,13 @@ discard block |
||
| 645 | 645 | * @param array $parameters |
| 646 | 646 | * default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
| 647 | 647 | */ |
| 648 | - public function setDraggable($element, $parameters = [ ]) { |
|
| 649 | - $attr = "id"; |
|
| 650 | - $preventDefault = false; |
|
| 651 | - $stopPropagation = false; |
|
| 652 | - $immediatly = true; |
|
| 653 | - extract ( $parameters ); |
|
| 654 | - $script = $this->_add_event ( $element, Javascript::draggable ( $attr ), "dragstart", $preventDefault, $stopPropagation, $immediatly ); |
|
| 648 | + public function setDraggable($element, $parameters=[]) { |
|
| 649 | + $attr="id"; |
|
| 650 | + $preventDefault=false; |
|
| 651 | + $stopPropagation=false; |
|
| 652 | + $immediatly=true; |
|
| 653 | + extract($parameters); |
|
| 654 | + $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $preventDefault, $stopPropagation, $immediatly); |
|
| 655 | 655 | return $script; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -665,13 +665,13 @@ discard block |
||
| 665 | 665 | * @param string $jsCallback |
| 666 | 666 | * the js script to call when element is dropped |
| 667 | 667 | */ |
| 668 | - public function asDropZone($element, $jsCallback = "", $parameters = [ ]) { |
|
| 669 | - $stopPropagation = false; |
|
| 670 | - $immediatly = true; |
|
| 671 | - $jqueryDone = "append"; |
|
| 672 | - $script = $this->_add_event ( $element, '', "dragover", true, $stopPropagation, $immediatly ); |
|
| 673 | - extract ( $parameters ); |
|
| 674 | - $script .= $this->_add_event ( $element, Javascript::dropZone ( $jqueryDone, $jsCallback ), "drop", true, $stopPropagation, $immediatly ); |
|
| 668 | + public function asDropZone($element, $jsCallback="", $parameters=[]) { |
|
| 669 | + $stopPropagation=false; |
|
| 670 | + $immediatly=true; |
|
| 671 | + $jqueryDone="append"; |
|
| 672 | + $script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly); |
|
| 673 | + extract($parameters); |
|
| 674 | + $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly); |
|
| 675 | 675 | return $script; |
| 676 | 676 | } |
| 677 | 677 | |
@@ -688,16 +688,16 @@ discard block |
||
| 688 | 688 | * delayed if false |
| 689 | 689 | * @return string |
| 690 | 690 | */ |
| 691 | - public function interval($jsCode, $time, $globalName = null, $immediatly = true) { |
|
| 692 | - if (! Javascript::isFunction ( $jsCode )) { |
|
| 693 | - $jsCode = "function(){\n" . $jsCode . "\n}"; |
|
| 691 | + public function interval($jsCode, $time, $globalName=null, $immediatly=true) { |
|
| 692 | + if (!Javascript::isFunction($jsCode)) { |
|
| 693 | + $jsCode="function(){\n".$jsCode."\n}"; |
|
| 694 | 694 | } |
| 695 | - if (isset ( $globalName )) { |
|
| 696 | - $script = "if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
| 695 | + if (isset ($globalName)) { |
|
| 696 | + $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
| 697 | 697 | } else { |
| 698 | - $script = "setInterval({$jsCode},{$time});"; |
|
| 698 | + $script="setInterval({$jsCode},{$time});"; |
|
| 699 | 699 | } |
| 700 | - return $this->exec ( $script, $immediatly ); |
|
| 700 | + return $this->exec($script, $immediatly); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
@@ -709,8 +709,8 @@ discard block |
||
| 709 | 709 | * delayed if false |
| 710 | 710 | * @return string |
| 711 | 711 | */ |
| 712 | - public function clearInterval($globalName, $immediatly = true) { |
|
| 713 | - return $this->exec ( "if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly ); |
|
| 712 | + public function clearInterval($globalName, $immediatly=true) { |
|
| 713 | + return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -731,20 +731,20 @@ discard block |
||
| 731 | 731 | * delayed if false |
| 732 | 732 | * @return string |
| 733 | 733 | */ |
| 734 | - public function counter($counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true, $immediatly = true) { |
|
| 735 | - $stop = ""; |
|
| 734 | + public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) { |
|
| 735 | + $stop=""; |
|
| 736 | 736 | if ($countDown) { |
| 737 | - $stop = "if (--timer < " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
| 737 | + $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
| 738 | 738 | } else { |
| 739 | - if ($limit != 0) { |
|
| 740 | - $stop = "if (++timer > " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
| 739 | + if ($limit!=0) { |
|
| 740 | + $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
| 741 | 741 | } |
| 742 | 742 | } |
| 743 | - $global = ""; |
|
| 744 | - if (isset ( $globalName )) { |
|
| 745 | - $global = "\nwindow.{$globalName}=interval;"; |
|
| 743 | + $global=""; |
|
| 744 | + if (isset ($globalName)) { |
|
| 745 | + $global="\nwindow.{$globalName}=interval;"; |
|
| 746 | 746 | } |
| 747 | - $timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
| 747 | + $timer="var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
| 748 | 748 | var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};}; |
| 749 | 749 | var shHide=function(v,k,kBefore){if(v==0 && display.find(k).closest('.timer').is(':visible') && (!kBefore || !display.find(kBefore).closest('.timer').is(':visible'))){display.find(k).closest('.timer').hide();}else{sh(display.find(k),v);}}; |
| 750 | 750 | var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';}; |
@@ -760,12 +760,12 @@ discard block |
||
| 760 | 760 | minutes = d0(parseInt((timer%3600) / 60, 10)); |
| 761 | 761 | seconds = d0(parseInt(timer%60, 10)); |
| 762 | 762 | mainSh(days,hours,minutes,seconds); |
| 763 | - " . $stop . " |
|
| 763 | + " . $stop." |
|
| 764 | 764 | }, 1000); |
| 765 | - " . $global . " |
|
| 765 | + " . $global." |
|
| 766 | 766 | }"; |
| 767 | - $element = '$("' . $counterSelector . '")'; |
|
| 768 | - return $this->exec ( $timer . "\nstartTimer(" . $value . "," . $element . ");", $immediatly ); |
|
| 767 | + $element='$("'.$counterSelector.'")'; |
|
| 768 | + return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -787,8 +787,8 @@ discard block |
||
| 787 | 787 | * count down if true or elapse if false |
| 788 | 788 | * @return string |
| 789 | 789 | */ |
| 790 | - public function counterOn($element, $event, $counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true) { |
|
| 791 | - return $this->execOn ( $event, $element, $this->counter ( $counterSelector, $value, $limit, $globalName, $countDown, false ) ); |
|
| 790 | + public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) { |
|
| 791 | + return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false)); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | /** |
@@ -802,8 +802,8 @@ discard block |
||
| 802 | 802 | * the active href (if null, window.location.href is used) |
| 803 | 803 | * @return string |
| 804 | 804 | */ |
| 805 | - public function activateLink($target, $property = 'href', $href = null) { |
|
| 806 | - return $this->execAtLast ( $this->_activateLink ( $target, $property, $href ) ); |
|
| 805 | + public function activateLink($target, $property='href', $href=null) { |
|
| 806 | + return $this->execAtLast($this->_activateLink($target, $property, $href)); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -817,14 +817,14 @@ discard block |
||
| 817 | 817 | * the active href (if null, window.location.href is used) |
| 818 | 818 | * @return string |
| 819 | 819 | */ |
| 820 | - public function _activateLink($target, $property = 'href', $href = null) { |
|
| 821 | - $js = '$("' . $target . ' [' . $property . ']").removeClass("active");'; |
|
| 822 | - if (isset ( $href )) { |
|
| 823 | - $js .= 'var href="' . $href . '";'; |
|
| 820 | + public function _activateLink($target, $property='href', $href=null) { |
|
| 821 | + $js='$("'.$target.' ['.$property.']").removeClass("active");'; |
|
| 822 | + if (isset ($href)) { |
|
| 823 | + $js.='var href="'.$href.'";'; |
|
| 824 | 824 | } else { |
| 825 | - $js .= 'var href=window.location.href;'; |
|
| 825 | + $js.='var href=window.location.href;'; |
|
| 826 | 826 | } |
| 827 | - $js .= '$("' . $target . ' [' . $property . ']").each(function(){if(href.includes($(this).attr("' . $property . '"))) $(this).addClass("active");});'; |
|
| 827 | + $js.='$("'.$target.' ['.$property.']").each(function(){if(href.includes($(this).attr("'.$property.'"))) $(this).addClass("active");});'; |
|
| 828 | 828 | return $js; |
| 829 | 829 | } |
| 830 | 830 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | use Ajax\common\html\traits\BaseHooksTrait; |
| 21 | 21 | |
| 22 | 22 | abstract class Widget extends HtmlDoubleElement { |
| 23 | - use FieldAsTrait,FormTrait,BaseHooksTrait; |
|
| 23 | + use FieldAsTrait, FormTrait, BaseHooksTrait; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * |
@@ -66,27 +66,27 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | protected $_hasRules; |
| 68 | 68 | |
| 69 | - public function __construct($identifier, $model, $modelInstance = NULL) { |
|
| 69 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 70 | 70 | parent::__construct($identifier); |
| 71 | - $this->_template = "%wrapContentBefore%%content%%wrapContentAfter%"; |
|
| 71 | + $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
|
| 72 | 72 | $this->setModel($model); |
| 73 | 73 | if (isset($modelInstance)) { |
| 74 | 74 | if (\is_object($modelInstance)) { |
| 75 | - $this->_model = \get_class($modelInstance); |
|
| 75 | + $this->_model=\get_class($modelInstance); |
|
| 76 | 76 | } |
| 77 | 77 | $this->show($modelInstance); |
| 78 | 78 | } |
| 79 | - $this->_generated = false; |
|
| 79 | + $this->_generated=false; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | protected function _init($instanceViewer, $contentKey, $content, $edition) { |
| 83 | - $this->_instanceViewer = $instanceViewer; |
|
| 84 | - $this->content = [ |
|
| 83 | + $this->_instanceViewer=$instanceViewer; |
|
| 84 | + $this->content=[ |
|
| 85 | 85 | $contentKey => $content |
| 86 | 86 | ]; |
| 87 | - $this->_self = $content; |
|
| 88 | - $this->_toolbarPosition = PositionInTable::BEFORETABLE; |
|
| 89 | - $this->_edition = $edition; |
|
| 87 | + $this->_self=$content; |
|
| 88 | + $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
|
| 89 | + $this->_edition=$edition; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,16 +95,16 @@ discard block |
||
| 95 | 95 | * @return int|string|boolean |
| 96 | 96 | */ |
| 97 | 97 | protected function _getIndex($fieldName) { |
| 98 | - $index = $fieldName; |
|
| 98 | + $index=$fieldName; |
|
| 99 | 99 | if (\is_string($fieldName)) { |
| 100 | - $fields = $this->_instanceViewer->getVisibleProperties(); |
|
| 101 | - $index = \array_search($fieldName, $fields); |
|
| 100 | + $fields=$this->_instanceViewer->getVisibleProperties(); |
|
| 101 | + $index=\array_search($fieldName, $fields); |
|
| 102 | 102 | } |
| 103 | 103 | return $index; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - protected function _getFieldIdentifier($prefix, $name = "") { |
|
| 107 | - return $this->identifier . "-{$prefix}-" . $this->_instanceViewer->getIdentifier(); |
|
| 106 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
| 107 | + return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | protected function _getFieldName($index) { |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | return $this->_instanceViewer->getCaption($index); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - abstract protected function _setToolbarPosition($table, $captions = NULL); |
|
| 118 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
| 119 | 119 | |
| 120 | 120 | public function show($modelInstance) { |
| 121 | 121 | if (\is_array($modelInstance)) { |
| 122 | - $modelInstance = \json_decode(\json_encode($modelInstance), FALSE); |
|
| 122 | + $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
| 123 | 123 | } |
| 124 | - $this->_modelInstance = $modelInstance; |
|
| 124 | + $this->_modelInstance=$modelInstance; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | public function getModel() { |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | public function setModel($_model) { |
| 132 | - $this->_model = $_model; |
|
| 132 | + $this->_model=$_model; |
|
| 133 | 133 | return $this; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | public function setInstanceViewer($_instanceViewer) { |
| 141 | - $this->_instanceViewer = $_instanceViewer; |
|
| 141 | + $this->_instanceViewer=$_instanceViewer; |
|
| 142 | 142 | return $this; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | abstract public function getHtmlComponent(); |
| 146 | 146 | |
| 147 | - public function setAttached($value = true) { |
|
| 147 | + public function setAttached($value=true) { |
|
| 148 | 148 | return $this->getHtmlComponent()->setAttached($value); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * @return Widget |
| 160 | 160 | */ |
| 161 | 161 | public function afterCompile($index, $callback) { |
| 162 | - $index = $this->_getIndex($index); |
|
| 163 | - if ($index !== false) { |
|
| 162 | + $index=$this->_getIndex($index); |
|
| 163 | + if ($index!==false) { |
|
| 164 | 164 | $this->_instanceViewer->afterCompile($index, $callback); |
| 165 | 165 | } |
| 166 | 166 | return $this; |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | return $this; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - public function addField($field, $key = null) { |
|
| 188 | + public function addField($field, $key=null) { |
|
| 189 | 189 | $this->_instanceViewer->addField($field, $key); |
| 190 | 190 | return $this; |
| 191 | 191 | } |
@@ -199,10 +199,10 @@ discard block |
||
| 199 | 199 | return $this->_instanceViewer->visiblePropertiesCount(); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - public function addMessage($attributes = NULL, $fieldName = "message") { |
|
| 202 | + public function addMessage($attributes=NULL, $fieldName="message") { |
|
| 203 | 203 | $this->_instanceViewer->addField($fieldName); |
| 204 | - $count = $this->_instanceViewer->visiblePropertiesCount(); |
|
| 205 | - return $this->fieldAsMessage($count - 1, $attributes); |
|
| 204 | + $count=$this->_instanceViewer->visiblePropertiesCount(); |
|
| 205 | + return $this->fieldAsMessage($count-1, $attributes); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | public function addErrorMessage() { |
@@ -211,15 +211,15 @@ discard block |
||
| 211 | 211 | ], "message"); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - public function insertField($index, $field, $key = null) { |
|
| 215 | - $index = $this->_getIndex($index); |
|
| 214 | + public function insertField($index, $field, $key=null) { |
|
| 215 | + $index=$this->_getIndex($index); |
|
| 216 | 216 | $this->_instanceViewer->insertField($index, $field, $key); |
| 217 | 217 | return $this; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - public function insertInField($index, $field, $key = null) { |
|
| 221 | - $index = $this->_getIndex($index); |
|
| 222 | - if ($index !== false) { |
|
| 220 | + public function insertInField($index, $field, $key=null) { |
|
| 221 | + $index=$this->_getIndex($index); |
|
| 222 | + if ($index!==false) { |
|
| 223 | 223 | $this->_instanceViewer->insertInField($index, $field, $key); |
| 224 | 224 | } |
| 225 | 225 | return $this; |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | * @return Widget |
| 236 | 236 | */ |
| 237 | 237 | public function setValueFunction($index, $callback) { |
| 238 | - $index = $this->_getIndex($index); |
|
| 239 | - if ($index !== false) { |
|
| 238 | + $index=$this->_getIndex($index); |
|
| 239 | + if ($index!==false) { |
|
| 240 | 240 | $this->_instanceViewer->setValueFunction($index, $callback); |
| 241 | 241 | } |
| 242 | 242 | return $this; |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
| 253 | 253 | */ |
| 254 | 254 | public function getToolbar() { |
| 255 | - if (isset($this->_toolbar) === false) { |
|
| 256 | - $this->_toolbar = new HtmlMenu("toolbar-" . $this->identifier); |
|
| 255 | + if (isset($this->_toolbar)===false) { |
|
| 256 | + $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
|
| 257 | 257 | } |
| 258 | 258 | return $this->_toolbar; |
| 259 | 259 | } |
@@ -266,11 +266,11 @@ discard block |
||
| 266 | 266 | * function to call on $element |
| 267 | 267 | * @return \Ajax\common\html\HtmlDoubleElement |
| 268 | 268 | */ |
| 269 | - public function addInToolbar($element, $callback = NULL) { |
|
| 270 | - $tb = $this->getToolbar(); |
|
| 269 | + public function addInToolbar($element, $callback=NULL) { |
|
| 270 | + $tb=$this->getToolbar(); |
|
| 271 | 271 | if ($element instanceof BaseWidget) { |
| 272 | - if ($element->getIdentifier() === "") { |
|
| 273 | - $element->setIdentifier("tb-item-" . $this->identifier . "-" . $tb->count()); |
|
| 272 | + if ($element->getIdentifier()==="") { |
|
| 273 | + $element->setIdentifier("tb-item-".$this->identifier."-".$tb->count()); |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | if (isset($callback)) { |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | * function($element) |
| 290 | 290 | * @return \Ajax\common\html\HtmlDoubleElement |
| 291 | 291 | */ |
| 292 | - public function addItemInToolbar($caption, $icon = NULL, $callback = NULL) { |
|
| 293 | - $result = $this->addInToolbar($caption, $callback); |
|
| 292 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
| 293 | + $result=$this->addInToolbar($caption, $callback); |
|
| 294 | 294 | if (isset($icon) && method_exists($result, "addIcon")) |
| 295 | 295 | $result->addIcon($icon); |
| 296 | 296 | return $result; |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * function($element) |
| 304 | 304 | * @return \Ajax\common\Widget |
| 305 | 305 | */ |
| 306 | - public function addItemsInToolbar(array $items, $callback = NULL) { |
|
| 306 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
| 307 | 307 | if (JArray::isAssociative($items)) { |
| 308 | 308 | foreach ($items as $icon => $item) { |
| 309 | 309 | $this->addItemInToolbar($item, $icon, $callback); |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | * function($element) |
| 325 | 325 | * @return \Ajax\common\html\HtmlDoubleElement |
| 326 | 326 | */ |
| 327 | - public function addDropdownInToolbar($value, $items, $callback = NULL) { |
|
| 328 | - $dd = $value; |
|
| 327 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
| 328 | + $dd=$value; |
|
| 329 | 329 | if (\is_string($value)) { |
| 330 | - $dd = new HtmlDropdown("dropdown-" . $this->identifier . "-" . $value, $value, $items); |
|
| 330 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
| 331 | 331 | } |
| 332 | 332 | return $this->addInToolbar($dd, $callback); |
| 333 | 333 | } |
@@ -340,8 +340,8 @@ discard block |
||
| 340 | 340 | * function($element) |
| 341 | 341 | * @return \Ajax\common\html\HtmlDoubleElement |
| 342 | 342 | */ |
| 343 | - public function addButtonInToolbar($caption, $cssStyle = null, $callback = NULL) { |
|
| 344 | - $bt = new HtmlButton("bt-" . $caption, $caption, $cssStyle); |
|
| 343 | + public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) { |
|
| 344 | + $bt=new HtmlButton("bt-".$caption, $caption, $cssStyle); |
|
| 345 | 345 | return $this->addInToolbar($bt, $callback); |
| 346 | 346 | } |
| 347 | 347 | |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | * function($element) |
| 354 | 354 | * @return \Ajax\common\html\HtmlDoubleElement |
| 355 | 355 | */ |
| 356 | - public function addButtonsInToolbar(array $captions, $asIcon = false, $callback = NULL) { |
|
| 357 | - $bts = new HtmlButtonGroups("", $captions, $asIcon); |
|
| 356 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
| 357 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
| 358 | 358 | return $this->addInToolbar($bts, $callback); |
| 359 | 359 | } |
| 360 | 360 | |
@@ -366,14 +366,14 @@ discard block |
||
| 366 | 366 | * @param boolean $labeled |
| 367 | 367 | * @return \Ajax\common\html\HtmlDoubleElement |
| 368 | 368 | */ |
| 369 | - public function addLabelledIconButtonInToolbar($caption, $icon, $before = true, $labeled = false) { |
|
| 370 | - $bt = new HtmlButton("", $caption); |
|
| 369 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
| 370 | + $bt=new HtmlButton("", $caption); |
|
| 371 | 371 | $bt->addIcon($icon, $before, $labeled); |
| 372 | 372 | return $this->addInToolbar($bt); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - public function addSubmitInToolbar($identifier, $value, $cssStyle = NULL, $url = NULL, $responseElement = NULL, $parameters = NULL) { |
|
| 376 | - $button = new HtmlButton($identifier, $value, $cssStyle); |
|
| 375 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
| 376 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
| 377 | 377 | $this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters); |
| 378 | 378 | return $this->addInToolbar($button); |
| 379 | 379 | } |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | * @param boolean $_edition |
| 397 | 397 | * @return \Ajax\common\Widget |
| 398 | 398 | */ |
| 399 | - public function setEdition($_edition = true) { |
|
| 400 | - $this->_edition = $_edition; |
|
| 399 | + public function setEdition($_edition=true) { |
|
| 400 | + $this->_edition=$_edition; |
|
| 401 | 401 | return $this; |
| 402 | 402 | } |
| 403 | 403 | |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | * @param string|boolean $disable |
| 427 | 427 | * @return string |
| 428 | 428 | */ |
| 429 | - public function jsDisabled($disable = true) { |
|
| 430 | - return "$('#" . $this->identifier . " .ui.input,#" . $this->identifier . " .ui.dropdown,#" . $this->identifier . " .ui.checkbox').toggleClass('disabled'," . $disable . ");"; |
|
| 429 | + public function jsDisabled($disable=true) { |
|
| 430 | + return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | * function($element) |
| 438 | 438 | * @return \Ajax\common\html\HtmlDoubleElement |
| 439 | 439 | */ |
| 440 | - public function addEditButtonInToolbar($caption, $callback = NULL) { |
|
| 441 | - $bt = new HtmlButton($this->identifier . "-editBtn", $caption); |
|
| 440 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
| 441 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
| 442 | 442 | $bt->setToggle(); |
| 443 | 443 | $bt->setActive($this->_edition); |
| 444 | 444 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
@@ -446,18 +446,18 @@ discard block |
||
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | public function setToolbar(HtmlMenu $_toolbar) { |
| 449 | - $this->_toolbar = $_toolbar; |
|
| 449 | + $this->_toolbar=$_toolbar; |
|
| 450 | 450 | return $this; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | public function setToolbarPosition($_toolbarPosition) { |
| 454 | - $this->_toolbarPosition = $_toolbarPosition; |
|
| 454 | + $this->_toolbarPosition=$_toolbarPosition; |
|
| 455 | 455 | return $this; |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | public function getForm() { |
| 459 | - if (! isset($this->_form)) { |
|
| 460 | - $this->_form = new HtmlForm("frm-" . $this->identifier); |
|
| 459 | + if (!isset($this->_form)) { |
|
| 460 | + $this->_form=new HtmlForm("frm-".$this->identifier); |
|
| 461 | 461 | $this->setEdition(true); |
| 462 | 462 | } |
| 463 | 463 | return $this->_form; |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | protected function runForm(JsUtils $js) { |
| 474 | - $fields = $this->getContentInstances(HtmlFormField::class); |
|
| 474 | + $fields=$this->getContentInstances(HtmlFormField::class); |
|
| 475 | 475 | foreach ($fields as $field) { |
| 476 | 476 | $this->_form->addField($field); |
| 477 | 477 | } |
@@ -480,10 +480,10 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | protected function _compileForm() { |
| 482 | 482 | if (isset($this->_form)) { |
| 483 | - $noValidate = ""; |
|
| 484 | - if (\sizeof($this->_form->getValidationParams()) > 0) |
|
| 485 | - $noValidate = "novalidate"; |
|
| 486 | - $this->wrapContent("<form class='" . $this->_form->getProperty('class') . "' id='frm-" . $this->identifier . "' name='frm-" . $this->identifier . "' " . $noValidate . ">", "</form>"); |
|
| 483 | + $noValidate=""; |
|
| 484 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
| 485 | + $noValidate="novalidate"; |
|
| 486 | + $this->wrapContent("<form class='".$this->_form->getProperty('class')."' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | |
@@ -505,21 +505,21 @@ discard block |
||
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | public function swapFields($index1, $index2) { |
| 508 | - $index1 = $this->_getIndex($index1); |
|
| 509 | - $index2 = $this->_getIndex($index2); |
|
| 508 | + $index1=$this->_getIndex($index1); |
|
| 509 | + $index2=$this->_getIndex($index2); |
|
| 510 | 510 | return $this->_instanceViewer->swapFields($index1, $index2); |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | public function removeField($index) { |
| 514 | - $index = $this->_getIndex($index); |
|
| 515 | - if ($index !== false) { |
|
| 514 | + $index=$this->_getIndex($index); |
|
| 515 | + if ($index!==false) { |
|
| 516 | 516 | $this->_instanceViewer->removeField($index); |
| 517 | 517 | } |
| 518 | 518 | return $this; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - public function asModal($header = null) { |
|
| 522 | - $modal = new HtmlModal("modal-" . $this->identifier, $header); |
|
| 521 | + public function asModal($header=null) { |
|
| 522 | + $modal=new HtmlModal("modal-".$this->identifier, $header); |
|
| 523 | 523 | $modal->setContent($this); |
| 524 | 524 | if (isset($this->_form)) { |
| 525 | 525 | $this->_form->onSuccess($modal->jsHide()); |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | return $modal; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - public function addToProperty($name, $value, $separator = " ") { |
|
| 530 | + public function addToProperty($name, $value, $separator=" ") { |
|
| 531 | 531 | return $this->getHtmlComponent()->addToProperty($name, $value, $separator); |
| 532 | 532 | } |
| 533 | 533 | |
@@ -19,38 +19,38 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | protected $_validation; |
| 21 | 21 | |
| 22 | - public function __construct($identifier, $field, $label = NULL) { |
|
| 22 | + public function __construct($identifier, $field, $label=NULL) { |
|
| 23 | 23 | parent::__construct($identifier, "div", "field"); |
| 24 | - $this->content = array(); |
|
| 25 | - $this->_states = [ |
|
| 24 | + $this->content=array(); |
|
| 25 | + $this->_states=[ |
|
| 26 | 26 | State::ERROR, |
| 27 | 27 | State::DISABLED |
| 28 | 28 | ]; |
| 29 | - if (isset($label) && $label !== "") |
|
| 29 | + if (isset($label) && $label!=="") |
|
| 30 | 30 | $this->setLabel($label); |
| 31 | 31 | $this->setField($field); |
| 32 | - $this->_validation = NULL; |
|
| 32 | + $this->_validation=NULL; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function addPointingLabel($label, $pointing = Direction::NONE) { |
|
| 36 | - $labelO = new HtmlLabel("", $label); |
|
| 35 | + public function addPointingLabel($label, $pointing=Direction::NONE) { |
|
| 36 | + $labelO=new HtmlLabel("", $label); |
|
| 37 | 37 | $labelO->setPointing($pointing); |
| 38 | - $this->addContent($labelO, $pointing === "below" || $pointing === "right"); |
|
| 38 | + $this->addContent($labelO, $pointing==="below" || $pointing==="right"); |
|
| 39 | 39 | return $labelO; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function setLabel($label) { |
| 43 | - $labelO = $label; |
|
| 43 | + $labelO=$label; |
|
| 44 | 44 | if (\is_string($label)) { |
| 45 | - $labelO = new HtmlSemDoubleElement("", "label", ""); |
|
| 45 | + $labelO=new HtmlSemDoubleElement("", "label", ""); |
|
| 46 | 46 | $labelO->setContent($label); |
| 47 | 47 | $labelO->setProperty("for", \str_replace("field-", "", $this->identifier)); |
| 48 | 48 | } |
| 49 | - $this->content["label"] = $labelO; |
|
| 49 | + $this->content["label"]=$labelO; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function setField($field) { |
| 53 | - $this->content["field"] = $field; |
|
| 53 | + $this->content["field"]=$field; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | * puts the label before or behind |
| 86 | 86 | */ |
| 87 | 87 | public function swapLabel() { |
| 88 | - $label = $this->getLabel(); |
|
| 88 | + $label=$this->getLabel(); |
|
| 89 | 89 | unset($this->content["label"]); |
| 90 | - $this->content["label"] = $label; |
|
| 90 | + $this->content["label"]=$label; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function setWidth($width) { |
| 100 | 100 | if (\is_int($width)) { |
| 101 | - $width = Wide::getConstants()["W" . $width]; |
|
| 101 | + $width=Wide::getConstants()["W".$width]; |
|
| 102 | 102 | } |
| 103 | 103 | $this->addToPropertyCtrl("class", $width, Wide::getConstants()); |
| 104 | 104 | if (isset($this->_container)) { |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public function setContainer($_container) { |
| 130 | - $this->_container = $_container; |
|
| 130 | + $this->_container=$_container; |
|
| 131 | 131 | return $this; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | $this->getDataField()->setProperty("readonly", ""); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function addRule($type, $prompt = NULL, $value = NULL) { |
|
| 139 | - $field = $this->getDataField(); |
|
| 138 | + public function addRule($type, $prompt=NULL, $value=NULL) { |
|
| 139 | + $field=$this->getDataField(); |
|
| 140 | 140 | if (isset($field)) { |
| 141 | - if (! isset($this->_validation)) { |
|
| 142 | - $this->_validation = new FieldValidation($field->getIdentifier()); |
|
| 141 | + if (!isset($this->_validation)) { |
|
| 142 | + $this->_validation=new FieldValidation($field->getIdentifier()); |
|
| 143 | 143 | } |
| 144 | - if($type instanceof Rule){ |
|
| 145 | - if($type->getType()=='empty'){ |
|
| 144 | + if ($type instanceof Rule) { |
|
| 145 | + if ($type->getType()=='empty') { |
|
| 146 | 146 | $this->addToProperty('class', 'required'); |
| 147 | 147 | } |
| 148 | - }elseif ($type === 'empty' || ($type['type'] ?? '') === 'empty') { |
|
| 148 | + }elseif ($type==='empty' || ($type['type'] ?? '')==='empty') { |
|
| 149 | 149 | $this->addToProperty('class', 'required'); |
| 150 | 150 | } |
| 151 | 151 | $this->_validation->addRule($type, $prompt, $value); |
@@ -153,11 +153,11 @@ discard block |
||
| 153 | 153 | return $this; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - public function setOptional($optional = true) { |
|
| 157 | - $field = $this->getDataField(); |
|
| 156 | + public function setOptional($optional=true) { |
|
| 157 | + $field=$this->getDataField(); |
|
| 158 | 158 | if (isset($field)) { |
| 159 | - if (! isset($this->_validation)) { |
|
| 160 | - $this->_validation = new FieldValidation($field->getIdentifier()); |
|
| 159 | + if (!isset($this->_validation)) { |
|
| 160 | + $this->_validation=new FieldValidation($field->getIdentifier()); |
|
| 161 | 161 | } |
| 162 | 162 | $this->_validation->setOptional($optional); |
| 163 | 163 | } |
@@ -171,12 +171,12 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function setRules(array $rules) { |
| 174 | - $this->_validation = null; |
|
| 174 | + $this->_validation=null; |
|
| 175 | 175 | return $this->addRules($rules); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - public function addIcon($icon, $direction = Direction::LEFT) { |
|
| 179 | - $field = $this->getField(); |
|
| 178 | + public function addIcon($icon, $direction=Direction::LEFT) { |
|
| 179 | + $field=$this->getField(); |
|
| 180 | 180 | return $field->addIcon($icon, $direction); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -15,79 +15,79 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | protected $ajaxTransition; |
| 17 | 17 | |
| 18 | - protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 18 | + protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 19 | 19 | |
| 20 | 20 | abstract public function getUrl($url); |
| 21 | 21 | |
| 22 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn = false); |
|
| 22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 23 | 23 | |
| 24 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
| 24 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 25 | 25 | |
| 26 | - protected function _ajax($method, $url, $responseElement = '', $parameters = []) { |
|
| 26 | + protected function _ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 27 | 27 | if (isset($this->params['ajax'])) { |
| 28 | 28 | extract($this->params['ajax']); |
| 29 | 29 | } |
| 30 | 30 | extract($parameters); |
| 31 | 31 | |
| 32 | - $jsCallback = isset($jsCallback) ? $jsCallback : ''; |
|
| 33 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 34 | - $originalSelector = $responseElement; |
|
| 35 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 36 | - $retour .= "let self=this;\n"; |
|
| 37 | - $before = isset($before) ? $before : ""; |
|
| 38 | - $retour .= $before; |
|
| 39 | - if ($hasLoader === true && JString::isNotNull($responseElement)) { |
|
| 32 | + $jsCallback=isset($jsCallback) ? $jsCallback : ''; |
|
| 33 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 34 | + $originalSelector=$responseElement; |
|
| 35 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 36 | + $retour.="let self=this;\n"; |
|
| 37 | + $before=isset($before) ? $before : ""; |
|
| 38 | + $retour.=$before; |
|
| 39 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 40 | 40 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 41 | - } elseif ($hasLoader === 'response') { |
|
| 41 | + } elseif ($hasLoader==='response') { |
|
| 42 | 42 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 43 | - } elseif ($hasLoader === 'internal-x') { |
|
| 43 | + } elseif ($hasLoader==='internal-x') { |
|
| 44 | 44 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 45 | - } elseif ($hasLoader === 'internal') { |
|
| 46 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 45 | + } elseif ($hasLoader==='internal') { |
|
| 46 | + $retour.="\n$(this).addClass('loading');"; |
|
| 47 | 47 | } elseif (\is_string($hasLoader)) { |
| 48 | 48 | $this->addLoading($retour, $hasLoader, $ajaxLoader); |
| 49 | 49 | } |
| 50 | - $ajaxParameters = [ |
|
| 50 | + $ajaxParameters=[ |
|
| 51 | 51 | "url" => "url", |
| 52 | - "method" => "'" . \strtoupper($method) . "'" |
|
| 52 | + "method" => "'".\strtoupper($method)."'" |
|
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
| 55 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 56 | 56 | |
| 57 | 57 | if (isset($params)) { |
| 58 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
| 58 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 59 | 59 | } |
| 60 | 60 | if (isset($headers)) { |
| 61 | - $ajaxParameters["headers"] = $headers; |
|
| 61 | + $ajaxParameters["headers"]=$headers; |
|
| 62 | 62 | } |
| 63 | 63 | if ($csrf) { |
| 64 | - $csrf = (is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | - $parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 64 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | + $parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 66 | 66 | } |
| 67 | 67 | if (isset($partial)) { |
| 68 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 69 | - $retour .= "let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 68 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 69 | + $retour.="let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 70 | 70 | } elseif (isset($upload)) { |
| 71 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 72 | - $retour .= 'let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.upload.addEventListener("progress", function(event) {if (event.lengthComputable) {' . $upload . '}}, false);'; |
|
| 71 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 72 | + $retour.='let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.upload.addEventListener("progress", function(event) {if (event.lengthComputable) {'.$upload.'}}, false);'; |
|
| 73 | 73 | } |
| 74 | 74 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 75 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 76 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, ($historize ? $originalSelector : null)) . "})"; |
|
| 75 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 76 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, ($historize ? $originalSelector : null))."})"; |
|
| 77 | 77 | if (isset($error)) { |
| 78 | - $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
| 78 | + $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
|
| 79 | 79 | } |
| 80 | - $retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})'; |
|
| 81 | - $retour .= ";\n"; |
|
| 82 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 80 | + $retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})'; |
|
| 81 | + $retour.=";\n"; |
|
| 82 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 83 | 83 | if ($immediatly) { |
| 84 | - $this->jquery_code_for_compile[] = $retour; |
|
| 84 | + $this->jquery_code_for_compile[]=$retour; |
|
| 85 | 85 | } |
| 86 | 86 | return $retour; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | protected function createAjaxParameters(&$original, $parameters) { |
| 90 | - $validParameters = [ |
|
| 90 | + $validParameters=[ |
|
| 91 | 91 | "contentType" => "%value%", |
| 92 | 92 | "dataType" => "'%value%'", |
| 93 | 93 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -96,21 +96,21 @@ discard block |
||
| 96 | 96 | ]; |
| 97 | 97 | foreach ($validParameters as $param => $mask) { |
| 98 | 98 | if (isset($parameters[$param])) { |
| 99 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
| 99 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | protected function implodeAjaxParameters($ajaxParameters) { |
| 105 | - $s = ''; |
|
| 105 | + $s=''; |
|
| 106 | 106 | foreach ($ajaxParameters as $k => $v) { |
| 107 | - if ($s !== '') { |
|
| 108 | - $s .= ','; |
|
| 107 | + if ($s!=='') { |
|
| 108 | + $s.=','; |
|
| 109 | 109 | } |
| 110 | 110 | if (is_array($v)) { |
| 111 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
| 111 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 112 | 112 | } else { |
| 113 | - $s .= "'{$k}':{$v}"; |
|
| 113 | + $s.="'{$k}':{$v}"; |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | return $s; |
@@ -118,29 +118,29 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 120 | 120 | if (isset($jsCondition)) { |
| 121 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 121 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 122 | 122 | } |
| 123 | 123 | return $jsSource; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | protected function _getAjaxUrl($url, $attr) { |
| 127 | - $url = $this->_correctAjaxUrl($url); |
|
| 128 | - $retour = "let url='" . $url . "';"; |
|
| 129 | - $slash = "/"; |
|
| 130 | - if (JString::endswith($url, "/") === true) { |
|
| 131 | - $slash = ""; |
|
| 127 | + $url=$this->_correctAjaxUrl($url); |
|
| 128 | + $retour="let url='".$url."';"; |
|
| 129 | + $slash="/"; |
|
| 130 | + if (JString::endswith($url, "/")===true) { |
|
| 131 | + $slash=""; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | if (JString::isNotNull($attr)) { |
| 135 | - if ($attr === "value") { |
|
| 136 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 137 | - } elseif ($attr === "html") { |
|
| 138 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 139 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
| 140 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
| 141 | - } elseif ($attr !== null && $attr !== "") { |
|
| 142 | - $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
|
| 143 | - $retour .= "url=!(new RegExp('^((http|https|ftp):\/\/)')).test(elmUrl)?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
| 135 | + if ($attr==="value") { |
|
| 136 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 137 | + } elseif ($attr==="html") { |
|
| 138 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 139 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 140 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 141 | + } elseif ($attr!==null && $attr!=="") { |
|
| 142 | + $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
| 143 | + $retour.="url=!(new RegExp('^((http|https|ftp):\/\/)')).test(elmUrl)?url+'".$slash."'+elmUrl:elmUrl;\n"; |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | return $retour; |
@@ -150,44 +150,44 @@ discard block |
||
| 150 | 150 | return "window.onpopstate = function(e){if(e.state){let target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 154 | - $result = "\nif (typeof getHref !== 'function'){function getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}}"; |
|
| 155 | - $result .= "\nlet myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 153 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 154 | + $result="\nif (typeof getHref !== 'function'){function getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}}"; |
|
| 155 | + $result.="\nlet myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 156 | 156 | return $result; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history = null) { |
|
| 160 | - $retour = ""; |
|
| 161 | - $call = null; |
|
| 159 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history=null) { |
|
| 160 | + $retour=""; |
|
| 161 | + $call=null; |
|
| 162 | 162 | if (JString::isNotNull($responseElement)) { |
| 163 | 163 | if (isset($ajaxTransition)) { |
| 164 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
| 164 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 165 | 165 | } elseif (isset($this->ajaxTransition)) { |
| 166 | - $call = $this->ajaxTransition; |
|
| 166 | + $call=$this->ajaxTransition; |
|
| 167 | 167 | } |
| 168 | 168 | if (\is_callable($call)) |
| 169 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 169 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 170 | 170 | else |
| 171 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 171 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 172 | 172 | } |
| 173 | 173 | if (isset($history)) { |
| 174 | 174 | if ($this->params["autoActiveLinks"]) { |
| 175 | - $retour .= $this->autoActiveLinks("url"); |
|
| 175 | + $retour.=$this->autoActiveLinks("url"); |
|
| 176 | 176 | } |
| 177 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 177 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 178 | 178 | } |
| 179 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 179 | + $retour.="\t".$jsCallback."\n"; |
|
| 180 | 180 | return $retour; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | protected function removeLoader($hasLoader) { |
| 184 | - if ($hasLoader === true) { |
|
| 184 | + if ($hasLoader===true) { |
|
| 185 | 185 | return "\n$('body').find('.ajax-loader').remove();"; |
| 186 | 186 | } |
| 187 | - if ($hasLoader === 'internal') { |
|
| 187 | + if ($hasLoader==='internal') { |
|
| 188 | 188 | return "\n$(self).removeClass('loading');"; |
| 189 | 189 | } |
| 190 | - if ($hasLoader === 'internal-x') { |
|
| 190 | + if ($hasLoader==='internal-x') { |
|
| 191 | 191 | return "\n$(self).children('.ajax-loader').remove();"; |
| 192 | 192 | } |
| 193 | 193 | return "\n$('body').find('.loading').removeClass('loading');"; |
@@ -195,71 +195,71 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | protected function _getResponseElement($responseElement) { |
| 197 | 197 | if (JString::isNotNull($responseElement)) { |
| 198 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
| 198 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 199 | 199 | } |
| 200 | 200 | return $responseElement; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | protected function _getFormElement($formElement) { |
| 204 | 204 | if (JString::isNotNull($formElement)) { |
| 205 | - $formElement = Javascript::prep_value($formElement); |
|
| 205 | + $formElement=Javascript::prep_value($formElement); |
|
| 206 | 206 | } |
| 207 | 207 | return $formElement; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | protected function _correctAjaxUrl($url) { |
| 211 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 212 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 213 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
| 214 | - $url = $this->getUrl($url); |
|
| 211 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 212 | + $url=substr($url, 0, strlen($url)-1); |
|
| 213 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 214 | + $url=$this->getUrl($url); |
|
| 215 | 215 | } |
| 216 | 216 | return $url; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
| 219 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 220 | 220 | if (JString::isNull($params)) { |
| 221 | 221 | return ""; |
| 222 | 222 | } |
| 223 | 223 | if (\preg_match("@^\{.*?\}$@", $params)) { |
| 224 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 225 | - return '$.param(' . $params . ')'; |
|
| 224 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 225 | + return '$.param('.$params.')'; |
|
| 226 | 226 | } else { |
| 227 | - return 'JSON.stringify(' . $params . ')'; |
|
| 227 | + return 'JSON.stringify('.$params.')'; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | return $params; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | public static function _implodeParams($parameters) { |
| 234 | - $allParameters = []; |
|
| 234 | + $allParameters=[]; |
|
| 235 | 235 | foreach ($parameters as $params) { |
| 236 | 236 | if (isset($params)) |
| 237 | - $allParameters[] = self::_correctParams($params); |
|
| 237 | + $allParameters[]=self::_correctParams($params); |
|
| 238 | 238 | } |
| 239 | 239 | return \implode("+'&'+", $allParameters); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 243 | - if (! isset($ajaxLoader)) { |
|
| 244 | - $ajaxLoader = $this->ajaxLoader; |
|
| 242 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 243 | + if (!isset($ajaxLoader)) { |
|
| 244 | + $ajaxLoader=$this->ajaxLoader; |
|
| 245 | 245 | } |
| 246 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
| 247 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 246 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
| 247 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 251 | - if (! isset($ajaxLoader)) { |
|
| 252 | - $ajaxLoader = $this->ajaxLoader; |
|
| 250 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 251 | + if (!isset($ajaxLoader)) { |
|
| 252 | + $ajaxLoader=$this->ajaxLoader; |
|
| 253 | 253 | } |
| 254 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 255 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 256 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 254 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 255 | + $retour.="{$responseElement}.empty();\n"; |
|
| 256 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | protected function setAjaxDataCall($params) { |
| 260 | - $result = null; |
|
| 261 | - if (! \is_callable($params)) { |
|
| 262 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
| 260 | + $result=null; |
|
| 261 | + if (!\is_callable($params)) { |
|
| 262 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
| 263 | 263 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
| 264 | 264 | }; |
| 265 | 265 | } |
@@ -268,13 +268,13 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | protected function setDefaultParameters(&$parameters, $default) { |
| 270 | 270 | foreach ($default as $k => $v) { |
| 271 | - if (! isset($parameters[$k])) |
|
| 272 | - $parameters[$k] = $v; |
|
| 271 | + if (!isset($parameters[$k])) |
|
| 272 | + $parameters[$k]=$v; |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | public function setAjaxLoader($loader) { |
| 277 | - $this->ajaxLoader = $loader; |
|
| 277 | + $this->ajaxLoader=$loader; |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @param string $responseElement |
| 286 | 286 | * selector of the HTML element displaying the answer |
| 287 | 287 | */ |
| 288 | - private function _get($url, $responseElement = '', $parameters = []) { |
|
| 288 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
| 289 | 289 | return $this->_ajax('get', $url, $responseElement, $parameters); |
| 290 | 290 | } |
| 291 | 291 | |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | * @param array $parameters |
| 300 | 300 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 301 | 301 | */ |
| 302 | - public function get($url, $responseElement = '', $parameters = []) { |
|
| 303 | - $parameters['immediatly'] = true; |
|
| 302 | + public function get($url, $responseElement='', $parameters=[]) { |
|
| 303 | + $parameters['immediatly']=true; |
|
| 304 | 304 | return $this->_get($url, $responseElement, $parameters); |
| 305 | 305 | } |
| 306 | 306 | |
@@ -316,8 +316,8 @@ discard block |
||
| 316 | 316 | * @param array $parameters |
| 317 | 317 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 318 | 318 | */ |
| 319 | - public function ajax($method, $url, $responseElement = '', $parameters = []) { |
|
| 320 | - $parameters['immediatly'] = true; |
|
| 319 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 320 | + $parameters['immediatly']=true; |
|
| 321 | 321 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 322 | 322 | } |
| 323 | 323 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | * $immediatly |
| 340 | 340 | * @return string |
| 341 | 341 | */ |
| 342 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
| 342 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
| 343 | 343 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
| 344 | 344 | } |
| 345 | 345 | |
@@ -355,8 +355,8 @@ discard block |
||
| 355 | 355 | * @param array $parameters |
| 356 | 356 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 357 | 357 | */ |
| 358 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
|
| 359 | - $parameters['immediatly'] = false; |
|
| 358 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
| 359 | + $parameters['immediatly']=false; |
|
| 360 | 360 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -370,15 +370,15 @@ discard block |
||
| 370 | 370 | * @param array $parameters |
| 371 | 371 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 372 | 372 | */ |
| 373 | - private function _json($url, $method = "get", $parameters = []) { |
|
| 374 | - $parameters = \array_merge($parameters, [ |
|
| 373 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 374 | + $parameters=\array_merge($parameters, [ |
|
| 375 | 375 | "hasLoader" => false |
| 376 | 376 | ]); |
| 377 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 378 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 379 | - $retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n"; |
|
| 380 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 381 | - $parameters["jsCallback"] = $retour; |
|
| 377 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 378 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 379 | + $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
|
| 380 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 381 | + $parameters["jsCallback"]=$retour; |
|
| 382 | 382 | return $this->_ajax($method, $url, null, $parameters); |
| 383 | 383 | } |
| 384 | 384 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @param array $parameters |
| 393 | 393 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 394 | 394 | */ |
| 395 | - public function json($url, $method = "get", $parameters = []) { |
|
| 395 | + public function json($url, $method="get", $parameters=[]) { |
|
| 396 | 396 | return $this->_json($url, $method, $parameters); |
| 397 | 397 | } |
| 398 | 398 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @param array $parameters |
| 409 | 409 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 410 | 410 | */ |
| 411 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
| 411 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
| 412 | 412 | $this->setDefaultParameters($parameters, [ |
| 413 | 413 | 'preventDefault' => true, |
| 414 | 414 | 'stopPropagation' => true, |
@@ -428,8 +428,8 @@ discard block |
||
| 428 | 428 | * @param array $parameters |
| 429 | 429 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 430 | 430 | */ |
| 431 | - public function jsonDeferred($url, $method = 'get', $parameters = []) { |
|
| 432 | - $parameters['immediatly'] = false; |
|
| 431 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
| 432 | + $parameters['immediatly']=false; |
|
| 433 | 433 | return $this->_json($url, $method, $parameters); |
| 434 | 434 | } |
| 435 | 435 | |
@@ -444,29 +444,29 @@ discard block |
||
| 444 | 444 | * @param array $parameters |
| 445 | 445 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 446 | 446 | */ |
| 447 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 448 | - $parameters = \array_merge($parameters, [ |
|
| 447 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 448 | + $parameters=\array_merge($parameters, [ |
|
| 449 | 449 | "hasLoader" => false |
| 450 | 450 | ]); |
| 451 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 452 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 453 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
| 454 | - if ($context === null) { |
|
| 455 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 456 | - $newElm = "$('#'+newId)"; |
|
| 451 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 452 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 453 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
| 454 | + if ($context===null) { |
|
| 455 | + $parent="$('".$maskSelector."').parent()"; |
|
| 456 | + $newElm="$('#'+newId)"; |
|
| 457 | 457 | } else { |
| 458 | - $parent = $context; |
|
| 459 | - $newElm = $context . ".find('#'+newId)"; |
|
| 458 | + $parent=$context; |
|
| 459 | + $newElm=$context.".find('#'+newId)"; |
|
| 460 | 460 | } |
| 461 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 462 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 463 | - $retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n" . "\tlet created=false;let maskElm=$('" . $maskSelector . "').first();maskElm.hide();" . "\tlet newId=(maskElm.attr('id') || 'mask')+'-'+index;" . "\tlet newElm=" . $newElm . ";\n" . "\tif(!newElm.length){\n" . "\t\tnewElm=maskElm.clone(); |
|
| 461 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 462 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 463 | + $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tlet created=false;let maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tlet newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tlet newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
|
| 464 | 464 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ let newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
| 465 | - $retour .= $appendTo; |
|
| 466 | - $retour .= "\t}\n" . "\tfor(var key in value){\n" . "\t\t\tlet 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\tlet sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n" . "\t\t\tlet 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"; |
|
| 467 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 468 | - $retour .= "\t" . $jsCallback; |
|
| 469 | - $parameters["jsCallback"] = $retour; |
|
| 465 | + $retour.=$appendTo; |
|
| 466 | + $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tlet 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\tlet sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tlet 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"; |
|
| 467 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 468 | + $retour.="\t".$jsCallback; |
|
| 469 | + $parameters["jsCallback"]=$retour; |
|
| 470 | 470 | return $this->_ajax($method, $url, null, $parameters); |
| 471 | 471 | } |
| 472 | 472 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @param array $parameters |
| 482 | 482 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 483 | 483 | */ |
| 484 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 484 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 485 | 485 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
| 486 | 486 | } |
| 487 | 487 | |
@@ -496,8 +496,8 @@ discard block |
||
| 496 | 496 | * @param array $parameters |
| 497 | 497 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 498 | 498 | */ |
| 499 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 500 | - $parameters['immediatly'] = false; |
|
| 499 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 500 | + $parameters['immediatly']=false; |
|
| 501 | 501 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
| 502 | 502 | } |
| 503 | 503 | |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | * @param array $parameters |
| 514 | 514 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 515 | 515 | */ |
| 516 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
| 516 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
| 517 | 517 | $this->setDefaultParameters($parameters, [ |
| 518 | 518 | 'preventDefault' => true, |
| 519 | 519 | 'stopPropagation' => true, |
@@ -534,8 +534,8 @@ discard block |
||
| 534 | 534 | * @param array $parameters |
| 535 | 535 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 536 | 536 | */ |
| 537 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
| 538 | - $parameters['immediatly'] = false; |
|
| 537 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 538 | + $parameters['immediatly']=false; |
|
| 539 | 539 | return $this->_get($url, $responseElement, $parameters); |
| 540 | 540 | } |
| 541 | 541 | |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | * @param array $parameters |
| 555 | 555 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 556 | 556 | */ |
| 557 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 558 | - $parameters['method'] = 'get'; |
|
| 557 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 558 | + $parameters['method']='get'; |
|
| 559 | 559 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 560 | 560 | } |
| 561 | 561 | |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @param array $parameters |
| 575 | 575 | * default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 576 | 576 | */ |
| 577 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
| 577 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
| 578 | 578 | $this->setDefaultParameters($parameters, [ |
| 579 | 579 | 'preventDefault' => true, |
| 580 | 580 | 'stopPropagation' => true, |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | * @param array $parameters |
| 599 | 599 | * default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 600 | 600 | */ |
| 601 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 601 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 602 | 602 | return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
| 603 | 603 | } |
| 604 | 604 | |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | * @param array $parameters |
| 616 | 616 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 617 | 617 | */ |
| 618 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 618 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 619 | 619 | return $this->getOn('click', $element, $url, $responseElement, $parameters); |
| 620 | 620 | } |
| 621 | 621 | |
@@ -630,18 +630,18 @@ discard block |
||
| 630 | 630 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null,"listenerOn"=>false) |
| 631 | 631 | * @return $this |
| 632 | 632 | */ |
| 633 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
| 634 | - $parameters['attr'] = 'href'; |
|
| 633 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 634 | + $parameters['attr']='href'; |
|
| 635 | 635 | if (JString::isNull($responseElement)) { |
| 636 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 636 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 637 | 637 | } else { |
| 638 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 638 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 639 | 639 | } |
| 640 | - if (! isset($parameters['historize'])) { |
|
| 641 | - $parameters['historize'] = true; |
|
| 640 | + if (!isset($parameters['historize'])) { |
|
| 641 | + $parameters['historize']=true; |
|
| 642 | 642 | } |
| 643 | - if (! isset($parameters['jsCallback'])) { |
|
| 644 | - $parameters['jsCallback'] = 'let event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
| 643 | + if (!isset($parameters['jsCallback'])) { |
|
| 644 | + $parameters['jsCallback']='let event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
| 645 | 645 | } |
| 646 | 646 | return $this->getOnClick($element, "", $responseElement, $parameters); |
| 647 | 647 | } |
@@ -657,15 +657,15 @@ discard block |
||
| 657 | 657 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null,"listenerOn"=>false) |
| 658 | 658 | * @return $this |
| 659 | 659 | */ |
| 660 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
| 661 | - $parameters['attr'] = 'href'; |
|
| 660 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 661 | + $parameters['attr']='href'; |
|
| 662 | 662 | if (JString::isNull($responseElement)) { |
| 663 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 663 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 664 | 664 | } else { |
| 665 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 665 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 666 | 666 | } |
| 667 | - if (! isset($parameters['historize'])) { |
|
| 668 | - $parameters['historize'] = true; |
|
| 667 | + if (!isset($parameters['historize'])) { |
|
| 668 | + $parameters['historize']=true; |
|
| 669 | 669 | } |
| 670 | 670 | return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
| 671 | 671 | } |
@@ -681,29 +681,29 @@ discard block |
||
| 681 | 681 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null,"listenerOn"=>false) |
| 682 | 682 | * @return $this |
| 683 | 683 | */ |
| 684 | - public function postFormAction($element, $responseElement = "", $parameters = array()) { |
|
| 685 | - $parameters['attr'] = 'action'; |
|
| 684 | + public function postFormAction($element, $responseElement="", $parameters=array()) { |
|
| 685 | + $parameters['attr']='action'; |
|
| 686 | 686 | if (JString::isNull($responseElement)) { |
| 687 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 687 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 688 | 688 | } else { |
| 689 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 689 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 690 | 690 | } |
| 691 | - $formId = '%$(this).attr("id")%'; |
|
| 692 | - if (! isset($parameters['historize'])) { |
|
| 693 | - $parameters['historize'] = true; |
|
| 691 | + $formId='%$(this).attr("id")%'; |
|
| 692 | + if (!isset($parameters['historize'])) { |
|
| 693 | + $parameters['historize']=true; |
|
| 694 | 694 | } |
| 695 | - $parameters['preventDefault'] = true; |
|
| 696 | - if (! isset($parameters['hasLoader'])) { |
|
| 697 | - $parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 695 | + $parameters['preventDefault']=true; |
|
| 696 | + if (!isset($parameters['hasLoader'])) { |
|
| 697 | + $parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 698 | 698 | } |
| 699 | - if (! isset($parameters['jsCallback'])) { |
|
| 700 | - $parameters['jsCallback'] = 'let event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
| 699 | + if (!isset($parameters['jsCallback'])) { |
|
| 700 | + $parameters['jsCallback']='let event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
| 701 | 701 | } |
| 702 | 702 | return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters); |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
| 706 | - $parameters['params'] = $params; |
|
| 705 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
| 706 | + $parameters['params']=$params; |
|
| 707 | 707 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
| 708 | 708 | } |
| 709 | 709 | |
@@ -719,8 +719,8 @@ discard block |
||
| 719 | 719 | * @param array $parameters |
| 720 | 720 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 721 | 721 | */ |
| 722 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 723 | - $parameters['immediatly'] = true; |
|
| 722 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 723 | + $parameters['immediatly']=true; |
|
| 724 | 724 | return $this->_post($url, $params, $responseElement, $parameters); |
| 725 | 725 | } |
| 726 | 726 | |
@@ -737,8 +737,8 @@ discard block |
||
| 737 | 737 | * @param array $parameters |
| 738 | 738 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 739 | 739 | */ |
| 740 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 741 | - $parameters['immediatly'] = false; |
|
| 740 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 741 | + $parameters['immediatly']=false; |
|
| 742 | 742 | return $this->_post($url, $params, $responseElement, $parameters); |
| 743 | 743 | } |
| 744 | 744 | |
@@ -757,9 +757,9 @@ discard block |
||
| 757 | 757 | * @param array $parameters |
| 758 | 758 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 759 | 759 | */ |
| 760 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 761 | - $parameters['method'] = 'post'; |
|
| 762 | - $parameters['params'] = $params; |
|
| 760 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 761 | + $parameters['method']='post'; |
|
| 762 | + $parameters['params']=$params; |
|
| 763 | 763 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 764 | 764 | } |
| 765 | 765 | |
@@ -777,75 +777,75 @@ discard block |
||
| 777 | 777 | * @param array $parameters |
| 778 | 778 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"before"=>null,"listenerOn"=>false) |
| 779 | 779 | */ |
| 780 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
| 780 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
| 781 | 781 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
| 782 | 782 | } |
| 783 | 783 | |
| 784 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
| 784 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 785 | 785 | if (isset($this->params['ajax'])) { |
| 786 | 786 | extract($this->params['ajax']); |
| 787 | 787 | } |
| 788 | - $params = '{}'; |
|
| 789 | - $validation = false; |
|
| 788 | + $params='{}'; |
|
| 789 | + $validation=false; |
|
| 790 | 790 | \extract($parameters); |
| 791 | - $async = ($async) ? 'true' : 'false'; |
|
| 792 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 793 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 794 | - $form = $this->_getFormElement($form); |
|
| 795 | - $retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');"; |
|
| 796 | - if (! isset($contentType) || $contentType != 'false') { |
|
| 797 | - $retour .= "\nlet params=$('#'+" . $form . ").serialize();\n"; |
|
| 791 | + $async=($async) ? 'true' : 'false'; |
|
| 792 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 793 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 794 | + $form=$this->_getFormElement($form); |
|
| 795 | + $retour.="\n$('#'+".$form.").trigger('ajaxSubmit');"; |
|
| 796 | + if (!isset($contentType) || $contentType!='false') { |
|
| 797 | + $retour.="\nlet params=$('#'+".$form.").serialize();\n"; |
|
| 798 | 798 | if (isset($params)) { |
| 799 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
| 799 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 800 | 800 | } |
| 801 | 801 | } else { |
| 802 | - $retour .= "\nlet params=new FormData($('#'+" . $form . ")[0]);\n"; |
|
| 802 | + $retour.="\nlet params=new FormData($('#'+".$form.")[0]);\n"; |
|
| 803 | 803 | } |
| 804 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 805 | - $retour .= "let self=this;\n"; |
|
| 806 | - $before = isset($before) ? $before : ""; |
|
| 807 | - $retour .= $before; |
|
| 808 | - if ($hasLoader === true) { |
|
| 804 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 805 | + $retour.="let self=this;\n"; |
|
| 806 | + $before=isset($before) ? $before : ""; |
|
| 807 | + $retour.=$before; |
|
| 808 | + if ($hasLoader===true) { |
|
| 809 | 809 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 810 | - } elseif ($hasLoader === 'response') { |
|
| 810 | + } elseif ($hasLoader==='response') { |
|
| 811 | 811 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 812 | - } elseif ($hasLoader === 'internal-x') { |
|
| 812 | + } elseif ($hasLoader==='internal-x') { |
|
| 813 | 813 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 814 | - } elseif ($hasLoader === 'internal') { |
|
| 815 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 814 | + } elseif ($hasLoader==='internal') { |
|
| 815 | + $retour.="\n$(this).addClass('loading');"; |
|
| 816 | 816 | } elseif (\is_string($hasLoader)) { |
| 817 | - $retour .= "\n$hasLoader.addClass('loading');"; |
|
| 817 | + $retour.="\n$hasLoader.addClass('loading');"; |
|
| 818 | 818 | } |
| 819 | - $ajaxParameters = [ |
|
| 819 | + $ajaxParameters=[ |
|
| 820 | 820 | "url" => "url", |
| 821 | 821 | "method" => "'POST'", |
| 822 | 822 | "data" => "params", |
| 823 | 823 | "async" => $async |
| 824 | 824 | ]; |
| 825 | 825 | if (isset($headers)) { |
| 826 | - $ajaxParameters["headers"] = $headers; |
|
| 826 | + $ajaxParameters["headers"]=$headers; |
|
| 827 | 827 | } |
| 828 | 828 | if (isset($partial)) { |
| 829 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 830 | - $retour .= "let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 829 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 830 | + $retour.="let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 831 | 831 | } |
| 832 | 832 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 833 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
| 834 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) . "})"; |
|
| 833 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 834 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."})"; |
|
| 835 | 835 | if (isset($error)) { |
| 836 | - $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
| 836 | + $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
|
| 837 | 837 | } |
| 838 | - $retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})'; |
|
| 839 | - $retour .= ";\n"; |
|
| 838 | + $retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})'; |
|
| 839 | + $retour.=";\n"; |
|
| 840 | 840 | if ($validation) { |
| 841 | - $retour = "$('#'+" . $form . ").validate({submitHandler: function(form) { |
|
| 842 | - " . $retour . " |
|
| 841 | + $retour="$('#'+".$form.").validate({submitHandler: function(form) { |
|
| 842 | + " . $retour." |
|
| 843 | 843 | }});\n"; |
| 844 | - $retour .= "$('#'+" . $form . ").submit();\n"; |
|
| 844 | + $retour.="$('#'+".$form.").submit();\n"; |
|
| 845 | 845 | } |
| 846 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 846 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 847 | 847 | if ($immediatly) |
| 848 | - $this->jquery_code_for_compile[] = $retour; |
|
| 848 | + $this->jquery_code_for_compile[]=$retour; |
|
| 849 | 849 | return $retour; |
| 850 | 850 | } |
| 851 | 851 | |
@@ -861,8 +861,8 @@ discard block |
||
| 861 | 861 | * @param array $parameters |
| 862 | 862 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 863 | 863 | */ |
| 864 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
| 865 | - $parameters['immediatly'] = true; |
|
| 864 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 865 | + $parameters['immediatly']=true; |
|
| 866 | 866 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 867 | 867 | } |
| 868 | 868 | |
@@ -879,8 +879,8 @@ discard block |
||
| 879 | 879 | * @param array $parameters |
| 880 | 880 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 881 | 881 | */ |
| 882 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
| 883 | - $parameters['immediatly'] = false; |
|
| 882 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 883 | + $parameters['immediatly']=false; |
|
| 884 | 884 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 885 | 885 | } |
| 886 | 886 | |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | * @param array $parameters |
| 898 | 898 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 899 | 899 | */ |
| 900 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 900 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 901 | 901 | $this->setDefaultParameters($parameters, [ |
| 902 | 902 | 'preventDefault' => true, |
| 903 | 903 | 'stopPropagation' => true, |
@@ -919,11 +919,11 @@ discard block |
||
| 919 | 919 | * @param array $parameters |
| 920 | 920 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 921 | 921 | */ |
| 922 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 922 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 923 | 923 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | - public function addCsrf($name = 'csrf-token') { |
|
| 926 | + public function addCsrf($name='csrf-token') { |
|
| 927 | 927 | return " |
| 928 | 928 | $.ajaxSetup({ |
| 929 | 929 | beforeSend: function(xhr, settings) { |