@@ -18,6 +18,10 @@ discard block |
||
| 18 | 18 | trait FieldAsTrait{ |
| 19 | 19 | |
| 20 | 20 | abstract protected function _getFieldIdentifier($prefix); |
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param \Closure $callback |
|
| 24 | + */ |
|
| 21 | 25 | abstract public function setValueFunction($index,$callback); |
| 22 | 26 | |
| 23 | 27 | private function _getLabelField($caption,$icon=NULL){ |
@@ -27,6 +31,10 @@ discard block |
||
| 27 | 31 | |
| 28 | 32 | protected function _addRules($element,$attributes){} |
| 29 | 33 | |
| 34 | + /** |
|
| 35 | + * @param \Closure $elementCallback |
|
| 36 | + * @param string $prefix |
|
| 37 | + */ |
|
| 30 | 38 | protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
| 31 | 39 | $this->setValueFunction($index,function($value)use ($index,&$attributes,$elementCallback,$prefix){ |
| 32 | 40 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
@@ -15,102 +15,102 @@ |
||
| 15 | 15 | * @property InstanceViewer $_instanceViewer |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -trait FieldAsTrait{ |
|
| 18 | +trait FieldAsTrait { |
|
| 19 | 19 | |
| 20 | 20 | abstract protected function _getFieldIdentifier($prefix); |
| 21 | - abstract public function setValueFunction($index,$callback); |
|
| 21 | + abstract public function setValueFunction($index, $callback); |
|
| 22 | 22 | |
| 23 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 24 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 23 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 24 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 25 | 25 | return $label; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - protected function _addRules($element,$attributes){} |
|
| 28 | + protected function _addRules($element, $attributes) {} |
|
| 29 | 29 | |
| 30 | - protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
|
| 31 | - $this->setValueFunction($index,function($value)use ($index,&$attributes,$elementCallback,$prefix){ |
|
| 30 | + protected function _fieldAs($elementCallback, $index, $attributes=NULL, $prefix=null) { |
|
| 31 | + $this->setValueFunction($index, function($value)use ($index, &$attributes, $elementCallback, $prefix){ |
|
| 32 | 32 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
| 33 | - if(isset($attributes["name"])===true){ |
|
| 33 | + if (isset($attributes["name"])===true) { |
|
| 34 | 34 | $name=$attributes["name"]; |
| 35 | 35 | } |
| 36 | - $element=$elementCallback($this->_getFieldIdentifier($prefix),$value,$name); |
|
| 37 | - if(\is_array($attributes)) |
|
| 38 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 36 | + $element=$elementCallback($this->_getFieldIdentifier($prefix), $value, $name); |
|
| 37 | + if (\is_array($attributes)) |
|
| 38 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 39 | 39 | return $element; |
| 40 | 40 | }); |
| 41 | 41 | return $this; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
| 46 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
| 47 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
| 45 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 46 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
| 47 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 48 | 48 | return $pb; |
| 49 | 49 | }); |
| 50 | 50 | return $this; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
| 54 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
| 55 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
| 53 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 54 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
| 55 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 56 | 56 | return $rating; |
| 57 | 57 | }); |
| 58 | 58 | return $this; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - public function fieldAsLabel($index,$icon=NULL){ |
|
| 62 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
| 63 | - $lbl=$this->_getLabelField($caption,$icon); |
|
| 61 | + public function fieldAsLabel($index, $icon=NULL) { |
|
| 62 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
| 63 | + $lbl=$this->_getLabelField($caption, $icon); |
|
| 64 | 64 | return $lbl; |
| 65 | 65 | }); |
| 66 | 66 | return $this; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
|
| 70 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
| 71 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 69 | + public function fieldAsImage($index, $size=Size::SMALL, $circular=false) { |
|
| 70 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
| 71 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
| 72 | 72 | return $image; |
| 73 | 73 | }); |
| 74 | 74 | return $this; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
| 78 | - return $this->_fieldAs(function($id,$value,$name){ |
|
| 79 | - $img= (new HtmlImage($id,$value))->asAvatar(); |
|
| 77 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 78 | + return $this->_fieldAs(function($id, $value, $name) { |
|
| 79 | + $img=(new HtmlImage($id, $value))->asAvatar(); |
|
| 80 | 80 | return $img; |
| 81 | - }, $index,$attributes,"avatar"); |
|
| 81 | + }, $index, $attributes, "avatar"); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
| 85 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 86 | - return $this->_fieldAs(function($id,$value,$name){ |
|
| 87 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
| 85 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 86 | + return $this->_fieldAs(function($id, $value, $name) { |
|
| 87 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
| 88 | 88 | return $input; |
| 89 | - }, $index,$attributes,"radio"); |
|
| 89 | + }, $index, $attributes, "radio"); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 93 | - return $this->_fieldAs(function($id,$value,$name){ |
|
| 94 | - $input= new HtmlInput($id,"text",$value); |
|
| 92 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 93 | + return $this->_fieldAs(function($id, $value, $name) { |
|
| 94 | + $input=new HtmlInput($id, "text", $value); |
|
| 95 | 95 | $input->getField()->setProperty("name", $name); |
| 96 | 96 | return $input; |
| 97 | - }, $index,$attributes,"input"); |
|
| 97 | + }, $index, $attributes, "input"); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 101 | - return $this->_fieldAs(function($id,$value,$name){ |
|
| 102 | - $input=new HtmlCheckbox($id,"",$this->_instanceViewer->getIdentifier()); |
|
| 100 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 101 | + return $this->_fieldAs(function($id, $value, $name) { |
|
| 102 | + $input=new HtmlCheckbox($id, "", $this->_instanceViewer->getIdentifier()); |
|
| 103 | 103 | $input->setChecked(JString::isBooleanTrue($value)); |
| 104 | 104 | $input->getField()->setProperty("name", $name); |
| 105 | 105 | return $input; |
| 106 | - }, $index,$attributes,"ck"); |
|
| 106 | + }, $index, $attributes, "ck"); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 110 | - return $this->_fieldAs(function($id,$value,$name) use($elements,$multiple){ |
|
| 111 | - $dd=new HtmlDropdown($id,$value,$elements); |
|
| 112 | - $dd->asSelect($name,$multiple); |
|
| 109 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 110 | + return $this->_fieldAs(function($id, $value, $name) use($elements, $multiple){ |
|
| 111 | + $dd=new HtmlDropdown($id, $value, $elements); |
|
| 112 | + $dd->asSelect($name, $multiple); |
|
| 113 | 113 | return $dd; |
| 114 | - }, $index,$attributes,"dd"); |
|
| 114 | + }, $index, $attributes, "dd"); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | \ No newline at end of file |
@@ -34,8 +34,9 @@ discard block |
||
| 34 | 34 | $name=$attributes["name"]; |
| 35 | 35 | } |
| 36 | 36 | $element=$elementCallback($this->_getFieldIdentifier($prefix),$value,$name); |
| 37 | - if(\is_array($attributes)) |
|
| 38 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 37 | + if(\is_array($attributes)) { |
|
| 38 | + $this->_applyAttributes($element, $attributes,$index); |
|
| 39 | + } |
|
| 39 | 40 | return $element; |
| 40 | 41 | }); |
| 41 | 42 | return $this; |
@@ -68,7 +69,9 @@ discard block |
||
| 68 | 69 | |
| 69 | 70 | public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
| 70 | 71 | $this->setValueFunction($index,function($img) use($size,$circular){ |
| 71 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 72 | + $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular) { |
|
| 73 | + $image->setCircular(); |
|
| 74 | + } |
|
| 72 | 75 | return $image; |
| 73 | 76 | }); |
| 74 | 77 | return $this; |
@@ -16,7 +16,14 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | trait FormFieldAsTrait{ |
| 18 | 18 | |
| 19 | + /** |
|
| 20 | + * @param string $prefix |
|
| 21 | + */ |
|
| 19 | 22 | abstract protected function _getFieldIdentifier($prefix); |
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param \Closure $callback |
|
| 26 | + */ |
|
| 20 | 27 | abstract public function setValueFunction($index,$callback); |
| 21 | 28 | |
| 22 | 29 | private function _getLabelField($caption,$icon=NULL){ |
@@ -40,6 +47,9 @@ discard block |
||
| 40 | 47 | $element->fromArray($attributes); |
| 41 | 48 | } |
| 42 | 49 | |
| 50 | + /** |
|
| 51 | + * @param HtmlFormField $element |
|
| 52 | + */ |
|
| 43 | 53 | protected function _addRules($element,$attributes){ |
| 44 | 54 | if(isset($attributes["rules"])){ |
| 45 | 55 | $rules=$attributes["rules"]; |
@@ -51,6 +61,9 @@ discard block |
||
| 51 | 61 | } |
| 52 | 62 | } |
| 53 | 63 | |
| 64 | + /** |
|
| 65 | + * @param \Closure $elementCallback |
|
| 66 | + */ |
|
| 54 | 67 | protected function _fieldAs($elementCallback,$index,$attributes=NULL,$identifier=null){ |
| 55 | 68 | $this->setValueFunction($index,function($value)use ($index,&$attributes,$elementCallback){ |
| 56 | 69 | $caption=$this->_instanceViewer->getCaption($index); |
@@ -14,13 +14,13 @@ discard block |
||
| 14 | 14 | * @property object $_modelInstance; |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -trait FormFieldAsTrait{ |
|
| 17 | +trait FormFieldAsTrait { |
|
| 18 | 18 | |
| 19 | 19 | abstract protected function _getFieldIdentifier($prefix); |
| 20 | - abstract public function setValueFunction($index,$callback); |
|
| 20 | + abstract public function setValueFunction($index, $callback); |
|
| 21 | 21 | |
| 22 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 23 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 22 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 23 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 24 | 24 | return $label; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -28,22 +28,22 @@ discard block |
||
| 28 | 28 | * @param HtmlFormField $element |
| 29 | 29 | * @param array $attributes |
| 30 | 30 | */ |
| 31 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
| 31 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
| 32 | 32 | $this->_addRules($element, $attributes); |
| 33 | - if(isset($attributes["callback"])){ |
|
| 33 | + if (isset($attributes["callback"])) { |
|
| 34 | 34 | $callback=$attributes["callback"]; |
| 35 | - if(\is_callable($callback)){ |
|
| 36 | - $callback($element,$this->_modelInstance,$index); |
|
| 35 | + if (\is_callable($callback)) { |
|
| 36 | + $callback($element, $this->_modelInstance, $index); |
|
| 37 | 37 | unset($attributes["callback"]); |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | $element->fromArray($attributes); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - protected function _addRules($element,$attributes){ |
|
| 44 | - if(isset($attributes["rules"])){ |
|
| 43 | + protected function _addRules($element, $attributes) { |
|
| 44 | + if (isset($attributes["rules"])) { |
|
| 45 | 45 | $rules=$attributes["rules"]; |
| 46 | - if(\is_array($rules)) |
|
| 46 | + if (\is_array($rules)) |
|
| 47 | 47 | $element->addRules($rules); |
| 48 | 48 | else |
| 49 | 49 | $element->addRule($rules); |
@@ -51,46 +51,46 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - protected function _fieldAs($elementCallback,$index,$attributes=NULL,$identifier=null){ |
|
| 55 | - $this->setValueFunction($index,function($value)use ($index,&$attributes,$elementCallback){ |
|
| 54 | + protected function _fieldAs($elementCallback, $index, $attributes=NULL, $identifier=null) { |
|
| 55 | + $this->setValueFunction($index, function($value)use ($index, &$attributes, $elementCallback){ |
|
| 56 | 56 | $caption=$this->_instanceViewer->getCaption($index); |
| 57 | 57 | $name=$this->_instanceViewer->getFieldName($index); |
| 58 | - $element=$elementCallback($name,$caption,$value); |
|
| 59 | - if(\is_array($attributes)) |
|
| 60 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 58 | + $element=$elementCallback($name, $caption, $value); |
|
| 59 | + if (\is_array($attributes)) |
|
| 60 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 61 | 61 | return $element; |
| 62 | 62 | }); |
| 63 | 63 | return $this; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
| 67 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 68 | - return $this->_fieldAs(function($name,$caption,$value){ |
|
| 69 | - return new HtmlFormRadio($name,$name,$caption,$value); |
|
| 70 | - }, $index,$attributes); |
|
| 67 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 68 | + return $this->_fieldAs(function($name, $caption, $value) { |
|
| 69 | + return new HtmlFormRadio($name, $name, $caption, $value); |
|
| 70 | + }, $index, $attributes); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
| 74 | - return $this->_fieldAs(function($name,$caption,$value){ |
|
| 75 | - return new HtmlFormTextarea($name,$caption,$value); |
|
| 76 | - }, $index,$attributes); |
|
| 73 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 74 | + return $this->_fieldAs(function($name, $caption, $value) { |
|
| 75 | + return new HtmlFormTextarea($name, $caption, $value); |
|
| 76 | + }, $index, $attributes); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 80 | - return $this->_fieldAs(function($name,$caption,$value){ |
|
| 81 | - return new HtmlFormInput($name,$caption,"text",$value); |
|
| 82 | - }, $index,$attributes); |
|
| 79 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 80 | + return $this->_fieldAs(function($name, $caption, $value) { |
|
| 81 | + return new HtmlFormInput($name, $caption, "text", $value); |
|
| 82 | + }, $index, $attributes); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 86 | - return $this->_fieldAs(function($name,$caption,$value){ |
|
| 87 | - return new HtmlFormCheckbox($name,$caption,$value); |
|
| 88 | - }, $index,$attributes); |
|
| 85 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 86 | + return $this->_fieldAs(function($name, $caption, $value) { |
|
| 87 | + return new HtmlFormCheckbox($name, $caption, $value); |
|
| 88 | + }, $index, $attributes); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 92 | - return $this->_fieldAs(function($name,$caption,$value) use ($elements,$multiple){ |
|
| 93 | - return new HtmlFormDropdown($name,$elements,$caption,$value,$multiple); |
|
| 94 | - }, $index,$attributes); |
|
| 91 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 92 | + return $this->_fieldAs(function($name, $caption, $value) use ($elements, $multiple){ |
|
| 93 | + return new HtmlFormDropdown($name, $elements, $caption, $value, $multiple); |
|
| 94 | + }, $index, $attributes); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | \ No newline at end of file |
@@ -43,10 +43,11 @@ discard block |
||
| 43 | 43 | protected function _addRules($element,$attributes){ |
| 44 | 44 | if(isset($attributes["rules"])){ |
| 45 | 45 | $rules=$attributes["rules"]; |
| 46 | - if(\is_array($rules)) |
|
| 47 | - $element->addRules($rules); |
|
| 48 | - else |
|
| 49 | - $element->addRule($rules); |
|
| 46 | + if(\is_array($rules)) { |
|
| 47 | + $element->addRules($rules); |
|
| 48 | + } else { |
|
| 49 | + $element->addRule($rules); |
|
| 50 | + } |
|
| 50 | 51 | unset($attributes["rules"]); |
| 51 | 52 | } |
| 52 | 53 | } |
@@ -56,8 +57,9 @@ discard block |
||
| 56 | 57 | $caption=$this->_instanceViewer->getCaption($index); |
| 57 | 58 | $name=$this->_instanceViewer->getFieldName($index); |
| 58 | 59 | $element=$elementCallback($name,$caption,$value); |
| 59 | - if(\is_array($attributes)) |
|
| 60 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 60 | + if(\is_array($attributes)) { |
|
| 61 | + $this->_applyAttributes($element, $attributes,$index); |
|
| 62 | + } |
|
| 61 | 63 | return $element; |
| 62 | 64 | }); |
| 63 | 65 | return $this; |
@@ -18,43 +18,43 @@ discard block |
||
| 18 | 18 | use FormFieldAsTrait; |
| 19 | 19 | |
| 20 | 20 | public function __construct($identifier, $modelInstance=NULL) { |
| 21 | - parent::__construct($identifier, null,$modelInstance); |
|
| 21 | + parent::__construct($identifier, null, $modelInstance); |
|
| 22 | 22 | $this->_instanceViewer=new FormInstanceViewer(); |
| 23 | 23 | $this->content=["form"=>new HtmlForm($identifier)]; |
| 24 | 24 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 27 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 28 | 28 | $this->_instanceViewer->setInstance($this->_modelInstance); |
| 29 | 29 | |
| 30 | 30 | $form=$this->content["form"]; |
| 31 | 31 | $this->_generateContent($form); |
| 32 | 32 | |
| 33 | - if(isset($this->_toolbar)){ |
|
| 33 | + if (isset($this->_toolbar)) { |
|
| 34 | 34 | $this->_setToolbarPosition($form); |
| 35 | 35 | } |
| 36 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
| 37 | - return parent::compile($js,$view); |
|
| 36 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
| 37 | + return parent::compile($js, $view); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * @param HtmlForm $form |
| 42 | 42 | */ |
| 43 | - protected function _generateContent($form){ |
|
| 44 | - $values= $this->_instanceViewer->getValues(); |
|
| 43 | + protected function _generateContent($form) { |
|
| 44 | + $values=$this->_instanceViewer->getValues(); |
|
| 45 | 45 | $count=$this->_instanceViewer->count(); |
| 46 | 46 | $separators=$this->_instanceViewer->getSeparators(); |
| 47 | 47 | $separators[]=$count; |
| 48 | - for($i=0;$i<\sizeof($separators)-1;$i++){ |
|
| 49 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
| 50 | - if(\sizeof($fields)===1){ |
|
| 48 | + for ($i=0; $i<\sizeof($separators)-1; $i++) { |
|
| 49 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
| 50 | + if (\sizeof($fields)===1) { |
|
| 51 | 51 | $form->addField($fields[0]); |
| 52 | - }else |
|
| 52 | + } else |
|
| 53 | 53 | $form->addFields($fields); |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function addSeparatorAfter($fieldNum){ |
|
| 57 | + public function addSeparatorAfter($fieldNum) { |
|
| 58 | 58 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function setValidationParams(array $_validationParams){ |
|
| 87 | + public function setValidationParams(array $_validationParams) { |
|
| 88 | 88 | return $this->getHtmlComponent()->setValidationParams($_validationParams); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){ |
|
| 92 | - return $this->getHtmlComponent()->addSubmit($identifier, $value,$cssStyle,$url,$responseElement); |
|
| 91 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL) { |
|
| 92 | + return $this->getHtmlComponent()->addSubmit($identifier, $value, $cssStyle, $url, $responseElement); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | \ 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,28 +199,28 @@ 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 | } |
| 221 | 221 | |
| 222 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
| 223 | - $bt=$this->addButton($identifier, $value,$cssStyle); |
|
| 222 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
| 223 | + $bt=$this->addButton($identifier, $value, $cssStyle); |
|
| 224 | 224 | $bt->setProperty("type", "reset"); |
| 225 | 225 | return $bt; |
| 226 | 226 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @param string $jsCode |
| 231 | 231 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 232 | 232 | */ |
| 233 | - public function onValid($jsCode){ |
|
| 233 | + public function onValid($jsCode) { |
|
| 234 | 234 | $this->_validationParams["onValid"]="%function(){".$jsCode."}%"; |
| 235 | 235 | return $this; |
| 236 | 236 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @param string $jsCode can use event and fields parameters |
| 241 | 241 | * @return HtmlForm |
| 242 | 242 | */ |
| 243 | - public function onSuccess($jsCode){ |
|
| 243 | + public function onSuccess($jsCode) { |
|
| 244 | 244 | $this->_validationParams["onSuccess"]="%function(evt,fields){".$jsCode."}%"; |
| 245 | 245 | return $this; |
| 246 | 246 | } |