@@ -11,46 +11,46 @@ discard block |
||
| 11 | 11 | use Ajax\semantic\html\collections\form\HtmlFormField; |
| 12 | 12 | |
| 13 | 13 | trait FieldsTrait { |
| 14 | - public abstract function addFields($fields=NULL,$label=NULL); |
|
| 14 | + public abstract function addFields($fields=NULL, $label=NULL); |
|
| 15 | 15 | public abstract function addItem($item); |
| 16 | 16 | |
| 17 | - protected function createItem($value){ |
|
| 18 | - if(\is_array($value)){ |
|
| 19 | - $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
|
| 17 | + protected function createItem($value) { |
|
| 18 | + if (\is_array($value)) { |
|
| 19 | + $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id", ""), JArray::getDefaultValue($value, "label", null), JArray::getDefaultValue($value, "type", "text"), JArray::getDefaultValue($value, "value", ""), JArray::getDefaultValue($value, "placeholder", JArray::getDefaultValue($value, "label", null))); |
|
| 20 | 20 | return $itemO; |
| 21 | - }elseif(\is_object($value)){ |
|
| 21 | + }elseif (\is_object($value)) { |
|
| 22 | 22 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
| 23 | 23 | return $itemO; |
| 24 | - }else |
|
| 24 | + } else |
|
| 25 | 25 | return new HtmlFormInput($value); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - protected function createCondition($value){ |
|
| 28 | + protected function createCondition($value) { |
|
| 29 | 29 | return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function addInputs($inputs,$fieldslabel=null){ |
|
| 32 | + public function addInputs($inputs, $fieldslabel=null) { |
|
| 33 | 33 | $fields=array(); |
| 34 | - foreach ($inputs as $input){ |
|
| 34 | + foreach ($inputs as $input) { |
|
| 35 | 35 | \extract($input); |
| 36 | - $f=new HtmlFormInput("",""); |
|
| 36 | + $f=new HtmlFormInput("", ""); |
|
| 37 | 37 | $f->fromArray($input); |
| 38 | 38 | $fields[]=$f; |
| 39 | 39 | } |
| 40 | - return $this->addFields($fields,$fieldslabel); |
|
| 40 | + return $this->addFields($fields, $fieldslabel); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){ |
|
| 43 | + public function addFieldRule($index, $type, $prompt=NULL, $value=NULL) { |
|
| 44 | 44 | $field=$this->getItem($index); |
| 45 | - if(isset($field)){ |
|
| 46 | - $field->addRule($type,$prompt,$value); |
|
| 45 | + if (isset($field)) { |
|
| 46 | + $field->addRule($type, $prompt, $value); |
|
| 47 | 47 | } |
| 48 | 48 | return $this; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function addFieldRules($index,$rules){ |
|
| 51 | + public function addFieldRules($index, $rules) { |
|
| 52 | 52 | $field=$this->getItem($index); |
| 53 | - if(isset($field)){ |
|
| 53 | + if (isset($field)) { |
|
| 54 | 54 | $field->addRules($rules); |
| 55 | 55 | } |
| 56 | 56 | return $this; |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | * @param boolean $multiple |
| 65 | 65 | * @return \Ajax\common\html\HtmlDoubleElement |
| 66 | 66 | */ |
| 67 | - public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){ |
|
| 68 | - return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple)); |
|
| 67 | + public function addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false) { |
|
| 68 | + return $this->addItem(new HtmlFormDropdown($identifier, $items, $label, $value, $multiple)); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -76,23 +76,23 @@ discard block |
||
| 76 | 76 | * @param string $placeholder |
| 77 | 77 | * @return HtmlFormInput |
| 78 | 78 | */ |
| 79 | - public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){ |
|
| 80 | - return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder)); |
|
| 79 | + public function addInput($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL) { |
|
| 80 | + return $this->addItem(new HtmlFormInput($identifier, $label, $type, $value, $placeholder)); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function addPassword($identifier, $label=NULL){ |
|
| 84 | - return $this->addItem(new HtmlFormInput($identifier,$label,"password","","")); |
|
| 83 | + public function addPassword($identifier, $label=NULL) { |
|
| 84 | + return $this->addItem(new HtmlFormInput($identifier, $label, "password", "", "")); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){ |
|
| 88 | - return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick)); |
|
| 87 | + public function addButton($identifier, $value, $cssStyle=NULL, $onClick=NULL) { |
|
| 88 | + return $this->addItem(new HtmlButton($identifier, $value, $cssStyle, $onClick)); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){ |
|
| 92 | - return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type)); |
|
| 91 | + public function addCheckbox($identifier, $label=NULL, $value=NULL, $type=NULL) { |
|
| 92 | + return $this->addItem(new HtmlFormCheckbox($identifier, $label, $value, $type)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public function addRadio($identifier, $name,$label=NULL,$value=NULL){ |
|
| 96 | - return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value)); |
|
| 95 | + public function addRadio($identifier, $name, $label=NULL, $value=NULL) { |
|
| 96 | + return $this->addItem(new HtmlFormRadio($identifier, $name, $label, $value)); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | \ No newline at end of file |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function __construct($identifier, $elements=array()) { |
| 34 | 34 | parent::__construct($identifier, "form", "ui form"); |
| 35 | - $this->_states=[ State::ERROR,State::SUCCESS,State::WARNING,State::DISABLED ]; |
|
| 35 | + $this->_states=[State::ERROR, State::SUCCESS, State::WARNING, State::DISABLED]; |
|
| 36 | 36 | $this->setProperty("name", $this->identifier); |
| 37 | - $this->_fields=array (); |
|
| 37 | + $this->_fields=array(); |
|
| 38 | 38 | $this->_validationParams=[]; |
| 39 | 39 | $this->addItems($elements); |
| 40 | 40 | } |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | * @param string $caption |
| 57 | 57 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 58 | 58 | */ |
| 59 | - public function addDivider($caption=NULL){ |
|
| 60 | - return $this->addContent(new HtmlDivider("",$caption)); |
|
| 59 | + public function addDivider($caption=NULL) { |
|
| 60 | + return $this->addContent(new HtmlDivider("", $caption)); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function addFields($fields=NULL, $label=NULL) { |
| 64 | 64 | if (isset($fields)) { |
| 65 | 65 | if (!$fields instanceof HtmlFormFields) { |
| 66 | - if (\is_array($fields) === false) { |
|
| 66 | + if (\is_array($fields)===false) { |
|
| 67 | 67 | $fields=\func_get_args(); |
| 68 | 68 | $end=\end($fields); |
| 69 | 69 | if (\is_string($end)) { |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | $label=NULL; |
| 74 | 74 | } |
| 75 | 75 | $this->_fields=\array_merge($this->_fields, $fields); |
| 76 | - $fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count(), $fields); |
|
| 76 | + $fields=new HtmlFormFields("fields-".$this->identifier."-".$this->count(), $fields); |
|
| 77 | 77 | } |
| 78 | 78 | if (isset($label)) |
| 79 | 79 | $fields=new HtmlFormField("", $fields, $label); |
| 80 | 80 | } else { |
| 81 | - $fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count()); |
|
| 81 | + $fields=new HtmlFormFields("fields-".$this->identifier."-".$this->count()); |
|
| 82 | 82 | } |
| 83 | 83 | $this->addItem($fields); |
| 84 | 84 | return $fields; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function addItem($item) { |
| 88 | 88 | $item=parent::addItem($item); |
| 89 | - if (\is_subclass_of($item, HtmlFormField::class) === true) { |
|
| 89 | + if (\is_subclass_of($item, HtmlFormField::class)===true) { |
|
| 90 | 90 | $this->_fields[]=$item; |
| 91 | 91 | } |
| 92 | 92 | return $item; |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | return $this->addItem($message); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - private function addCompoValidation($js,$compo,$field){ |
|
| 141 | + private function addCompoValidation($js, $compo, $field) { |
|
| 142 | 142 | $validation=$field->getValidation(); |
| 143 | - if(isset($validation)){ |
|
| 144 | - if(isset($compo)===false){ |
|
| 143 | + if (isset($validation)) { |
|
| 144 | + if (isset($compo)===false) { |
|
| 145 | 145 | $compo=$js->semantic()->form("#".$this->identifier); |
| 146 | 146 | } |
| 147 | 147 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
@@ -152,26 +152,26 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | public function run(JsUtils $js) { |
| 154 | 154 | $compo=NULL; |
| 155 | - foreach ($this->_fields as $field){ |
|
| 156 | - if($field instanceof HtmlFormField) |
|
| 155 | + foreach ($this->_fields as $field) { |
|
| 156 | + if ($field instanceof HtmlFormField) |
|
| 157 | 157 | $compo=$this->addCompoValidation($js, $compo, $field); |
| 158 | 158 | } |
| 159 | - foreach ($this->content as $field){ |
|
| 160 | - if($field instanceof HtmlFormFields){ |
|
| 159 | + foreach ($this->content as $field) { |
|
| 160 | + if ($field instanceof HtmlFormFields) { |
|
| 161 | 161 | $items=$field->getItems(); |
| 162 | - foreach ($items as $_field){ |
|
| 163 | - if($_field instanceof HtmlFormField) |
|
| 162 | + foreach ($items as $_field) { |
|
| 163 | + if ($_field instanceof HtmlFormField) |
|
| 164 | 164 | $compo=$this->addCompoValidation($js, $compo, $_field); |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | - if(isset($compo)===false){ |
|
| 168 | + if (isset($compo)===false) { |
|
| 169 | 169 | return parent::run($js); |
| 170 | 170 | } |
| 171 | - if(isset($this->_validationParams["_ajaxSubmit"])){ |
|
| 172 | - if($this->_validationParams["_ajaxSubmit"] instanceof AjaxCall){ |
|
| 171 | + if (isset($this->_validationParams["_ajaxSubmit"])) { |
|
| 172 | + if ($this->_validationParams["_ajaxSubmit"] instanceof AjaxCall) { |
|
| 173 | 173 | $compilation=$this->_validationParams["_ajaxSubmit"]->compile($js); |
| 174 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
| 174 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
| 175 | 175 | $this->onSuccess($compilation); |
| 176 | 176 | unset($this->_validationParams["_ajaxSubmit"]); |
| 177 | 177 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | return $this->addToProperty("class", "loading"); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - public function addErrorMessage(){ |
|
| 189 | + public function addErrorMessage() { |
|
| 190 | 190 | return $this->addContent((new HtmlMessage(""))->setError()); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -199,22 +199,22 @@ discard block |
||
| 199 | 199 | return $this; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - public function submitOn($event,$identifier,$url,$responseElement){ |
|
| 202 | + public function submitOn($event, $identifier, $url, $responseElement) { |
|
| 203 | 203 | $elem=$this->getElementById($identifier, $this->content); |
| 204 | - if(isset($elem)){ |
|
| 204 | + if (isset($elem)) { |
|
| 205 | 205 | $elem->addEvent($event, "$('#".$this->identifier."').form('validate form');"); |
| 206 | - $this->_validationParams["_ajaxSubmit"]=new AjaxCall("postForm", ["form"=>$this->identifier,"responseElement"=>$responseElement,"url"=>$url]); |
|
| 206 | + $this->_validationParams["_ajaxSubmit"]=new AjaxCall("postForm", ["form"=>$this->identifier, "responseElement"=>$responseElement, "url"=>$url]); |
|
| 207 | 207 | } |
| 208 | 208 | return $this; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public function submitOnClick($identifier,$url,$responseElement){ |
|
| 211 | + public function submitOnClick($identifier, $url, $responseElement) { |
|
| 212 | 212 | return $this->submitOn("click", $identifier, $url, $responseElement); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - public function addSubmit($identifier,$value,$CssStyle=NULL,$url=NULL,$responseElement=NULL){ |
|
| 216 | - $bt=$this->addButton($identifier, $value,$CssStyle); |
|
| 217 | - if(isset($url) && isset($responseElement)) |
|
| 215 | + public function addSubmit($identifier, $value, $CssStyle=NULL, $url=NULL, $responseElement=NULL) { |
|
| 216 | + $bt=$this->addButton($identifier, $value, $CssStyle); |
|
| 217 | + if (isset($url) && isset($responseElement)) |
|
| 218 | 218 | $this->submitOnClick($identifier, $url, $responseElement); |
| 219 | 219 | return $bt; |
| 220 | 220 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @param string $jsCode |
| 225 | 225 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 226 | 226 | */ |
| 227 | - public function onValid($jsCode){ |
|
| 227 | + public function onValid($jsCode) { |
|
| 228 | 228 | $this->_validationParams["onValid"]="%function(){".$jsCode."}%"; |
| 229 | 229 | return $this; |
| 230 | 230 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @param string $jsCode can use event and fields parameters |
| 235 | 235 | * @return HtmlForm |
| 236 | 236 | */ |
| 237 | - public function onSuccess($jsCode){ |
|
| 237 | + public function onSuccess($jsCode) { |
|
| 238 | 238 | $this->_validationParams["onSuccess"]="%function(evt,fields){".$jsCode."}%"; |
| 239 | 239 | return $this; |
| 240 | 240 | } |