@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | use BaseTrait; |
| 23 | 23 | protected $_popup=NULL; |
| 24 | 24 | protected $_dimmer=NULL; |
| 25 | - protected $_params=array (); |
|
| 25 | + protected $_params=array(); |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | public function __construct($identifier, $tagName="p", $baseClass="ui", $content=NULL) { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return HtmlDimmer |
| 79 | 79 | */ |
| 80 | 80 | public function addDimmer($params=array(), $content=NULL) { |
| 81 | - $dimmer=new HtmlDimmer("dimmer-" . $this->identifier, $content); |
|
| 81 | + $dimmer=new HtmlDimmer("dimmer-".$this->identifier, $content); |
|
| 82 | 82 | $dimmer->setParams($params); |
| 83 | 83 | $dimmer->setContainer($this); |
| 84 | 84 | $this->addContent($dimmer); |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function addLabel($label, $before=false, $icon=NULL) { |
| 96 | 96 | $labelO=$label; |
| 97 | - if (\is_object($label) === false) { |
|
| 98 | - $labelO=new HtmlLabel("label-" . $this->identifier, $label); |
|
| 97 | + if (\is_object($label)===false) { |
|
| 98 | + $labelO=new HtmlLabel("label-".$this->identifier, $label); |
|
| 99 | 99 | if (isset($icon)) |
| 100 | 100 | $labelO->addIcon($icon); |
| 101 | 101 | } else { |
| 102 | - $labelO->addToPropertyCtrl("class", "label", array ("label" )); |
|
| 102 | + $labelO->addToPropertyCtrl("class", "label", array("label")); |
|
| 103 | 103 | } |
| 104 | 104 | $this->addContent($labelO, $before); |
| 105 | 105 | return $labelO; |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | * @param string $icon |
| 114 | 114 | * @return HtmlSemDoubleElement |
| 115 | 115 | */ |
| 116 | - public function attachLabel($label,$side=Side::TOP,$direction=Direction::NONE,$icon=NULL){ |
|
| 117 | - $label=$this->addLabel($label,true,$icon); |
|
| 118 | - $label->setAttached($side,$direction); |
|
| 116 | + public function attachLabel($label, $side=Side::TOP, $direction=Direction::NONE, $icon=NULL) { |
|
| 117 | + $label=$this->addLabel($label, true, $icon); |
|
| 118 | + $label->setAttached($side, $direction); |
|
| 119 | 119 | return $this; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * Transforms the element into a link |
| 124 | 124 | * @return HtmlSemDoubleElement |
| 125 | 125 | */ |
| 126 | - public function asLink($href=NULL,$target=NULL) { |
|
| 126 | + public function asLink($href=NULL, $target=NULL) { |
|
| 127 | 127 | if (isset($href)) |
| 128 | 128 | $this->setProperty("href", $href); |
| 129 | - if(isset($target)) |
|
| 129 | + if (isset($target)) |
|
| 130 | 130 | $this->setProperty("target", $target); |
| 131 | 131 | return $this->setTagName("a"); |
| 132 | 132 | } |
@@ -138,9 +138,9 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function jsShowDimmer($show=true) { |
| 140 | 140 | $status="hide"; |
| 141 | - if ($show === true) |
|
| 141 | + if ($show===true) |
|
| 142 | 142 | $status="show"; |
| 143 | - return '$("#.' . $this->identifier . ').dimmer("' . $status . '");'; |
|
| 143 | + return '$("#.'.$this->identifier.').dimmer("'.$status.'");'; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @see HtmlDoubleElement::run() |
| 159 | 159 | */ |
| 160 | 160 | public function run(JsUtils $js) { |
| 161 | - $this->_bsComponent=$js->semantic()->generic("#" . $this->identifier); |
|
| 161 | + $this->_bsComponent=$js->semantic()->generic("#".$this->identifier); |
|
| 162 | 162 | parent::run($js); |
| 163 | 163 | $this->addEventsOnRun($js); |
| 164 | 164 | if (isset($this->_popup)) { |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | class HtmlCard extends HtmlSemDoubleElement { |
| 18 | 18 | |
| 19 | 19 | public function __construct($identifier) { |
| 20 | - parent::__construct($identifier, "div", "ui card", array ()); |
|
| 20 | + parent::__construct($identifier, "div", "ui card", array()); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | private function createContent($content, $baseClass="content") { |
| 24 | 24 | $count=\sizeof($this->content); |
| 25 | - $result=new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content); |
|
| 25 | + $result=new HtmlCardContent("content-".$count."-".$this->identifier, $content); |
|
| 26 | 26 | $result->setClass($baseClass); |
| 27 | 27 | return $result; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | private function addElementInContent($key, $element) { |
| 31 | - if (\array_key_exists($key, $this->content) === false) { |
|
| 32 | - $this->content[$key]=array (); |
|
| 31 | + if (\array_key_exists($key, $this->content)===false) { |
|
| 32 | + $this->content[$key]=array(); |
|
| 33 | 33 | } |
| 34 | 34 | $this->content[$key][]=$element; |
| 35 | 35 | return $element; |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function addHeader($header, $niveau=4, $type="page") { |
| 48 | 48 | if (!$header instanceof HtmlHeader) { |
| 49 | - $header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type); |
|
| 49 | + $header=new HtmlHeader("header-".$this->identifier, $niveau, $header, $type); |
|
| 50 | 50 | } |
| 51 | 51 | $this->content["header"]=$this->createContent($header); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function addImage($image, $title="") { |
| 55 | 55 | if (!$image instanceof HtmlImage) { |
| 56 | - $image=new HtmlImage("image-" . $this->identifier, $image, $title); |
|
| 56 | + $image=new HtmlImage("image-".$this->identifier, $image, $title); |
|
| 57 | 57 | } |
| 58 | 58 | $image->setClass("image"); |
| 59 | 59 | return $this->addElementInContent("content", $image); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) { |
| 63 | 63 | $reveal=$visibleContent; |
| 64 | 64 | if (!$visibleContent instanceof HtmlReveal) { |
| 65 | - $reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType); |
|
| 65 | + $reveal=new HtmlReveal("reveral-".$this->identifier, $visibleContent, $hiddenContent, $type, $attributeType); |
|
| 66 | 66 | } |
| 67 | 67 | return $this->addElementInContent("content", $reveal); |
| 68 | 68 | } |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * @param boolean $asIcons |
| 92 | 92 | * @return \Ajax\semantic\html\elements\HtmlButtonGroups |
| 93 | 93 | */ |
| 94 | - public function addButtons($elements=array(), $asIcons=false){ |
|
| 95 | - $buttons=new HtmlButtonGroups("buttons-".$this->identifier,$elements,$asIcons); |
|
| 94 | + public function addButtons($elements=array(), $asIcons=false) { |
|
| 95 | + $buttons=new HtmlButtonGroups("buttons-".$this->identifier, $elements, $asIcons); |
|
| 96 | 96 | $this->addElementInContent("content", $buttons); |
| 97 | 97 | return $buttons; |
| 98 | 98 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | public function addCardHeaderContent($header, $metas=array(), $description=NULL) { |
| 103 | 103 | $count=\sizeof($this->content); |
| 104 | - return $this->addElementInContent("content", new HtmlCardHeaderContent("content-" . $count . "-" . $this->identifier, $header, $metas, $description)); |
|
| 104 | + return $this->addElementInContent("content", new HtmlCardHeaderContent("content-".$count."-".$this->identifier, $header, $metas, $description)); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | public function addCardContent($content=array()) { |
| 108 | 108 | $count=\sizeof($this->content); |
| 109 | - return $this->addElementInContent("content", new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content)); |
|
| 109 | + return $this->addElementInContent("content", new HtmlCardContent("content-".$count."-".$this->identifier, $content)); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | public function getCardContent($index=NULL) { |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | * @see HtmlSemDoubleElement::compile() |
| 133 | 133 | */ |
| 134 | 134 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 135 | - $this->content=JArray::sortAssociative($this->content, [ "header","image","content","extra-content" ]); |
|
| 135 | + $this->content=JArray::sortAssociative($this->content, ["header", "image", "content", "extra-content"]); |
|
| 136 | 136 | return parent::compile($js, $view); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function asLink($href="",$target=NULL) { |
|
| 139 | + public function asLink($href="", $target=NULL) { |
|
| 140 | 140 | $this->addToProperty("class", "link"); |
| 141 | - if ($href !== "") { |
|
| 141 | + if ($href!=="") { |
|
| 142 | 142 | $this->setProperty("href", $href); |
| 143 | 143 | if (isset($target)) |
| 144 | 144 | $this->setProperty("target", $target); |
@@ -26,23 +26,23 @@ discard block |
||
| 26 | 26 | * @property boolean $_edition |
| 27 | 27 | * @property mixed _modelInstance |
| 28 | 28 | */ |
| 29 | -trait FieldAsTrait{ |
|
| 29 | +trait FieldAsTrait { |
|
| 30 | 30 | |
| 31 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
| 32 | - abstract public function setValueFunction($index,$callback); |
|
| 31 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
| 32 | + abstract public function setValueFunction($index, $callback); |
|
| 33 | 33 | abstract protected function _getFieldName($index); |
| 34 | 34 | abstract protected function _getFieldCaption($index); |
| 35 | - abstract protected function _buttonAsSubmit(HtmlButton &$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
| 35 | + abstract protected function _buttonAsSubmit(HtmlButton&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @param HtmlFormField $element |
| 39 | 39 | * @param array $attributes |
| 40 | 40 | */ |
| 41 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
| 42 | - if(isset($attributes["jsCallback"])){ |
|
| 41 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
| 42 | + if (isset($attributes["jsCallback"])) { |
|
| 43 | 43 | $callback=$attributes["jsCallback"]; |
| 44 | - if(\is_callable($callback)){ |
|
| 45 | - $callback($element,$this->_modelInstance,$index); |
|
| 44 | + if (\is_callable($callback)) { |
|
| 45 | + $callback($element, $this->_modelInstance, $index); |
|
| 46 | 46 | unset($attributes["jsCallback"]); |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -52,43 +52,43 @@ discard block |
||
| 52 | 52 | $element->fromArray($attributes); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 56 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 55 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 56 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 57 | 57 | return $label; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
| 61 | - protected function _addRules($element,&$attributes){ |
|
| 62 | - if(isset($attributes["rules"])){ |
|
| 61 | + protected function _addRules($element, &$attributes) { |
|
| 62 | + if (isset($attributes["rules"])) { |
|
| 63 | 63 | $rules=$attributes["rules"]; |
| 64 | - if(\is_array($rules)){ |
|
| 64 | + if (\is_array($rules)) { |
|
| 65 | 65 | $element->addRules($rules); |
| 66 | 66 | } |
| 67 | - else{ |
|
| 67 | + else { |
|
| 68 | 68 | $element->addRule($rules); |
| 69 | 69 | } |
| 70 | 70 | unset($attributes["rules"]); |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - protected function _prepareFormFields(&$field,$name,&$attributes){ |
|
| 74 | + protected function _prepareFormFields(&$field, $name, &$attributes) { |
|
| 75 | 75 | $field->setName($name); |
| 76 | 76 | $this->_addRules($field, $attributes); |
| 77 | 77 | return $field; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
| 81 | - $this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){ |
|
| 80 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
| 81 | + $this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){ |
|
| 82 | 82 | $caption=$this->_getFieldCaption($index); |
| 83 | 83 | $name=$this->_getFieldName($index); |
| 84 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
| 85 | - if(isset($attributes["name"])){ |
|
| 84 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
| 85 | + if (isset($attributes["name"])) { |
|
| 86 | 86 | $name=$attributes["name"]; |
| 87 | 87 | unset($attributes["name"]); |
| 88 | 88 | } |
| 89 | - $element=$elementCallback($id,$name,$value,$caption); |
|
| 90 | - if(\is_array($attributes)){ |
|
| 91 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 89 | + $element=$elementCallback($id, $name, $value, $caption); |
|
| 90 | + if (\is_array($attributes)) { |
|
| 91 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 92 | 92 | } |
| 93 | 93 | $element->setDisabled(!$this->_edition); |
| 94 | 94 | return $element; |
@@ -97,177 +97,177 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
| 101 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
| 102 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
| 100 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 101 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
| 102 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 103 | 103 | return $pb; |
| 104 | 104 | }); |
| 105 | 105 | return $this; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
| 109 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
| 110 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
| 108 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 109 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
| 110 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 111 | 111 | return $rating; |
| 112 | 112 | }); |
| 113 | 113 | return $this; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - public function fieldAsLabel($index,$icon=NULL){ |
|
| 117 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
| 118 | - $lbl=$this->_getLabelField($caption,$icon); |
|
| 116 | + public function fieldAsLabel($index, $icon=NULL) { |
|
| 117 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
| 118 | + $lbl=$this->_getLabelField($caption, $icon); |
|
| 119 | 119 | return $lbl; |
| 120 | 120 | }); |
| 121 | 121 | return $this; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
| 125 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
| 126 | - $header=new HtmlHeader($id,$niveau,$value); |
|
| 127 | - if(isset($icon)) |
|
| 124 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
| 125 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
| 126 | + $header=new HtmlHeader($id, $niveau, $value); |
|
| 127 | + if (isset($icon)) |
|
| 128 | 128 | $header->asIcon($icon, $value); |
| 129 | 129 | return $header; |
| 130 | - }, $index,$attributes,"header"); |
|
| 130 | + }, $index, $attributes, "header"); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
| 134 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
| 135 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
| 136 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 134 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
| 135 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
| 136 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
| 137 | 137 | return $image; |
| 138 | 138 | }); |
| 139 | 139 | return $this; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public function fieldAsFlag($index){ |
|
| 143 | - $this->setValueFunction($index,function($flag){ |
|
| 144 | - $flag=new HtmlFlag($this->_getFieldIdentifier("flag"),$flag); |
|
| 142 | + public function fieldAsFlag($index) { |
|
| 143 | + $this->setValueFunction($index, function($flag) { |
|
| 144 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
| 145 | 145 | return $flag; |
| 146 | 146 | }); |
| 147 | 147 | return $this; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
| 151 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 152 | - $img=new HtmlImage($id,$value); |
|
| 150 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 151 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 152 | + $img=new HtmlImage($id, $value); |
|
| 153 | 153 | $img->asAvatar(); |
| 154 | 154 | return $img; |
| 155 | - }, $index,$attributes,"avatar"); |
|
| 155 | + }, $index, $attributes, "avatar"); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 159 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 160 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
| 158 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 159 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 160 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
| 161 | 161 | return $input; |
| 162 | - }, $index,$attributes,"radio"); |
|
| 162 | + }, $index, $attributes, "radio"); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
| 166 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
| 167 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
| 168 | - }, $index,$attributes,"radios"); |
|
| 165 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
| 166 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
| 167 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
| 168 | + }, $index, $attributes, "radios"); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 172 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
| 173 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
| 171 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 172 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
| 173 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 174 | 174 | return $this->_prepareFormFields($input, $name, $attributes); |
| 175 | - }, $index,$attributes,"input"); |
|
| 175 | + }, $index, $attributes, "input"); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
| 179 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 180 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
| 178 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 179 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 180 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
| 181 | 181 | $textarea->setName($name); |
| 182 | 182 | return $textarea; |
| 183 | - }, $index,$attributes,"textarea"); |
|
| 183 | + }, $index, $attributes, "textarea"); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
| 187 | - if(!\is_array($attributes)){ |
|
| 186 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
| 187 | + if (!\is_array($attributes)) { |
|
| 188 | 188 | $attributes=[]; |
| 189 | 189 | } |
| 190 | 190 | $attributes["imputType"]="hidden"; |
| 191 | - return $this->fieldAsInput($index,$attributes); |
|
| 191 | + return $this->fieldAsInput($index, $attributes); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 195 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 196 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
| 194 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 195 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 196 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
| 197 | 197 | $input->setChecked(JString::isBooleanTrue($value)); |
| 198 | 198 | $input->setName($name); |
| 199 | 199 | return $input; |
| 200 | - }, $index,$attributes,"ck"); |
|
| 200 | + }, $index, $attributes, "ck"); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 204 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple){ |
|
| 205 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
| 206 | - $dd->asSelect($name,$multiple); |
|
| 203 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 204 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple){ |
|
| 205 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
| 206 | + $dd->asSelect($name, $multiple); |
|
| 207 | 207 | return $dd; |
| 208 | - }, $index,$attributes,"dd"); |
|
| 208 | + }, $index, $attributes, "dd"); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
| 212 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 213 | - $mess= new HtmlMessage("message-".$id,$caption); |
|
| 211 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
| 212 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 213 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
| 214 | 214 | $mess->addHeader($value); |
| 215 | 215 | return $mess; |
| 216 | - }, $index,$attributes,"message"); |
|
| 216 | + }, $index, $attributes, "message"); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - public function fieldAsLink($index,$attributes=NULL){ |
|
| 220 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 221 | - $lnk= new HtmlLink("message-".$id,"#",$caption); |
|
| 219 | + public function fieldAsLink($index, $attributes=NULL) { |
|
| 220 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 221 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
| 222 | 222 | return $lnk; |
| 223 | - }, $index,$attributes,"link"); |
|
| 223 | + }, $index, $attributes, "link"); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /**Change fields type |
| 227 | 227 | * @param array $types an array or associative array $type=>$attributes |
| 228 | 228 | */ |
| 229 | - public function fieldsAs(array $types){ |
|
| 229 | + public function fieldsAs(array $types) { |
|
| 230 | 230 | $i=0; |
| 231 | - if(JArray::isAssociative($types)){ |
|
| 232 | - foreach ($types as $type=>$attributes){ |
|
| 233 | - if(\is_int($type)) |
|
| 234 | - $this->fieldAs($i++,$attributes,[]); |
|
| 235 | - else{ |
|
| 236 | - $type=preg_replace('/\d/', '', $type ); |
|
| 237 | - $this->fieldAs($i++,$type,$attributes); |
|
| 231 | + if (JArray::isAssociative($types)) { |
|
| 232 | + foreach ($types as $type=>$attributes) { |
|
| 233 | + if (\is_int($type)) |
|
| 234 | + $this->fieldAs($i++, $attributes, []); |
|
| 235 | + else { |
|
| 236 | + $type=preg_replace('/\d/', '', $type); |
|
| 237 | + $this->fieldAs($i++, $type, $attributes); |
|
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | - }else{ |
|
| 241 | - foreach ($types as $type){ |
|
| 242 | - $this->fieldAs($i++,$type); |
|
| 240 | + } else { |
|
| 241 | + foreach ($types as $type) { |
|
| 242 | + $this->fieldAs($i++, $type); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
| 247 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
| 248 | 248 | $method="fieldAs".\ucfirst($type); |
| 249 | - if(\method_exists($this, $method)){ |
|
| 250 | - if(!\is_array($attributes)){ |
|
| 249 | + if (\method_exists($this, $method)) { |
|
| 250 | + if (!\is_array($attributes)) { |
|
| 251 | 251 | $attributes=[$index]; |
| 252 | - }else{ |
|
| 252 | + } else { |
|
| 253 | 253 | \array_unshift($attributes, $index); |
| 254 | 254 | } |
| 255 | - \call_user_func_array([$this,$method], $attributes); |
|
| 255 | + \call_user_func_array([$this, $method], $attributes); |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
| 260 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
| 261 | - $button=new HtmlButton($id,$caption,$cssStyle); |
|
| 262 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
| 259 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 260 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
| 261 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
| 262 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
| 263 | 263 | return $button; |
| 264 | - }, $index,$attributes,"submit"); |
|
| 264 | + }, $index, $attributes, "submit"); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 268 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
| 269 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 267 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 268 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
| 269 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 270 | 270 | return $button; |
| 271 | - }, $index,$attributes,"button"); |
|
| 271 | + }, $index, $attributes, "button"); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | \ No newline at end of file |
@@ -19,80 +19,80 @@ discard block |
||
| 19 | 19 | class DataForm extends Widget { |
| 20 | 20 | |
| 21 | 21 | public function __construct($identifier, $modelInstance=NULL) { |
| 22 | - parent::__construct($identifier, null,$modelInstance); |
|
| 22 | + parent::__construct($identifier, null, $modelInstance); |
|
| 23 | 23 | $this->_form=new HtmlForm($identifier); |
| 24 | 24 | $this->_init(new FormInstanceViewer($identifier), "form", $this->_form, true); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
| 27 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
| 28 | 28 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 32 | - if(!$this->_generated){ |
|
| 31 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 32 | + if (!$this->_generated) { |
|
| 33 | 33 | $this->_instanceViewer->setInstance($this->_modelInstance); |
| 34 | 34 | |
| 35 | 35 | $form=$this->content["form"]; |
| 36 | 36 | $this->_generateContent($form); |
| 37 | 37 | |
| 38 | - if(isset($this->_toolbar)){ |
|
| 38 | + if (isset($this->_toolbar)) { |
|
| 39 | 39 | $this->_setToolbarPosition($form); |
| 40 | 40 | } |
| 41 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
| 41 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
| 42 | 42 | $this->_generated=true; |
| 43 | 43 | } |
| 44 | - return parent::compile($js,$view); |
|
| 44 | + return parent::compile($js, $view); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @param HtmlForm $form |
| 49 | 49 | */ |
| 50 | - protected function _generateContent($form){ |
|
| 51 | - $values= $this->_instanceViewer->getValues(); |
|
| 50 | + protected function _generateContent($form) { |
|
| 51 | + $values=$this->_instanceViewer->getValues(); |
|
| 52 | 52 | $count=$this->_instanceViewer->count(); |
| 53 | 53 | $separators=$this->_instanceViewer->getSeparators(); |
| 54 | 54 | $headers=$this->_instanceViewer->getHeaders(); |
| 55 | 55 | $wrappers=$this->_instanceViewer->getWrappers(); |
| 56 | 56 | \sort($separators); |
| 57 | 57 | $size=\sizeof($separators); |
| 58 | - if($size===1){ |
|
| 59 | - foreach ($values as $v){ |
|
| 58 | + if ($size===1) { |
|
| 59 | + foreach ($values as $v) { |
|
| 60 | 60 | $form->addField($v); |
| 61 | 61 | } |
| 62 | - }else{ |
|
| 62 | + } else { |
|
| 63 | 63 | $separators[]=$count; |
| 64 | - for($i=0;$i<$size;$i++){ |
|
| 64 | + for ($i=0; $i<$size; $i++) { |
|
| 65 | 65 | $this->_generateFields($form, $values, $headers, $separators[$i], $separators[$i+1], $wrappers); |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - protected function _generateFields($form,$values,$headers,$sepFirst,$sepLast,$wrappers){ |
|
| 70 | + protected function _generateFields($form, $values, $headers, $sepFirst, $sepLast, $wrappers) { |
|
| 71 | 71 | $wrapper=null; |
| 72 | - $fields=\array_slice($values, $sepFirst+1,$sepLast-$sepFirst); |
|
| 73 | - if(isset($headers[$sepFirst+1])) |
|
| 74 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 75 | - if(isset($wrappers[$sepFirst+1])){ |
|
| 72 | + $fields=\array_slice($values, $sepFirst+1, $sepLast-$sepFirst); |
|
| 73 | + if (isset($headers[$sepFirst+1])) |
|
| 74 | + $form->addHeader($headers[$sepFirst+1], 4, true); |
|
| 75 | + if (isset($wrappers[$sepFirst+1])) { |
|
| 76 | 76 | $wrapper=$wrappers[$sepFirst+1]; |
| 77 | 77 | } |
| 78 | - if(\sizeof($fields)===1){ |
|
| 78 | + if (\sizeof($fields)===1) { |
|
| 79 | 79 | $added=$form->addField($fields[0]); |
| 80 | - }elseif(\sizeof($fields)>1){ |
|
| 80 | + }elseif (\sizeof($fields)>1) { |
|
| 81 | 81 | $added=$form->addFields($fields); |
| 82 | 82 | } |
| 83 | - if(isset($wrapper)) |
|
| 84 | - $added->wrap($wrapper[0],$wrapper[1]); |
|
| 83 | + if (isset($wrapper)) |
|
| 84 | + $added->wrap($wrapper[0], $wrapper[1]); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * {@inheritDoc} |
| 89 | 89 | * @see \Ajax\common\Widget::getForm() |
| 90 | 90 | */ |
| 91 | - public function getForm(){ |
|
| 91 | + public function getForm() { |
|
| 92 | 92 | return $this->content["form"]; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public function addSeparatorAfter($fieldNum){ |
|
| 95 | + public function addSeparatorAfter($fieldNum) { |
|
| 96 | 96 | $fieldNum=$this->_getIndex($fieldNum); |
| 97 | 97 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
| 98 | 98 | return $this; |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | return $this; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 111 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
| 112 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 110 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 111 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
| 112 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 113 | 113 | $button->setProperty("type", "reset"); |
| 114 | 114 | return $button; |
| 115 | - }, $index,$attributes); |
|
| 115 | + }, $index, $attributes); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -131,19 +131,19 @@ discard block |
||
| 131 | 131 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - public function addDividerBefore($index,$title){ |
|
| 134 | + public function addDividerBefore($index, $title) { |
|
| 135 | 135 | $index=$this->_getIndex($index); |
| 136 | 136 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
| 137 | 137 | return $this; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
| 140 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
| 141 | 141 | $index=$this->_getIndex($index); |
| 142 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
| 142 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
| 143 | 143 | return $this; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function run(JsUtils $js){ |
|
| 146 | + public function run(JsUtils $js) { |
|
| 147 | 147 | return parent::run($js); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | \ No newline at end of file |
@@ -33,42 +33,42 @@ discard block |
||
| 33 | 33 | * @param string|HtmlSemDoubleElement $header |
| 34 | 34 | * @return \Ajax\semantic\html\collections\HtmlMessage |
| 35 | 35 | */ |
| 36 | - public function addHeader($header){ |
|
| 36 | + public function addHeader($header) { |
|
| 37 | 37 | $headerO=$header; |
| 38 | - if(\is_string($header)){ |
|
| 39 | - $headerO=new HtmlSemDoubleElement("header-".$this->identifier,"div"); |
|
| 38 | + if (\is_string($header)) { |
|
| 39 | + $headerO=new HtmlSemDoubleElement("header-".$this->identifier, "div"); |
|
| 40 | 40 | $headerO->setClass("header"); |
| 41 | 41 | $headerO->setContent($header); |
| 42 | 42 | } |
| 43 | - return $this->addContent($headerO,true); |
|
| 43 | + return $this->addContent($headerO, true); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function setHeader($header){ |
|
| 46 | + public function setHeader($header) { |
|
| 47 | 47 | return $this->addHeader($header); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public function addList($elements,$ordered=false){ |
|
| 51 | - $list=new HtmlList("list-".$this->identifier,$elements); |
|
| 50 | + public function addList($elements, $ordered=false) { |
|
| 51 | + $list=new HtmlList("list-".$this->identifier, $elements); |
|
| 52 | 52 | $list->setOrdered($ordered); |
| 53 | 53 | $list->setClass("ui list"); |
| 54 | 54 | $this->addContent($list); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function setIcon($icon){ |
|
| 57 | + public function setIcon($icon) { |
|
| 58 | 58 | $this->addToProperty("class", "icon"); |
| 59 | - $this->wrapContent("<div class='content'>","</div>"); |
|
| 59 | + $this->wrapContent("<div class='content'>", "</div>"); |
|
| 60 | 60 | $this->icon=new HtmlIcon("icon-".$this->identifier, $icon); |
| 61 | 61 | return $this; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function addLoader($loaderIcon="notched circle"){ |
|
| 64 | + public function addLoader($loaderIcon="notched circle") { |
|
| 65 | 65 | $this->setIcon($loaderIcon); |
| 66 | 66 | $this->icon->addToIcon("loading"); |
| 67 | 67 | return $this; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function setDismissable($dismiss=true){ |
|
| 71 | - if($dismiss===true) |
|
| 70 | + public function setDismissable($dismiss=true) { |
|
| 71 | + if ($dismiss===true) |
|
| 72 | 72 | $this->close=new HtmlIcon("close-".$this->identifier, "close"); |
| 73 | 73 | else |
| 74 | 74 | $this->close=NULL; |
@@ -79,41 +79,41 @@ discard block |
||
| 79 | 79 | * {@inheritDoc} |
| 80 | 80 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run() |
| 81 | 81 | */ |
| 82 | - public function run(JsUtils $js){ |
|
| 82 | + public function run(JsUtils $js) { |
|
| 83 | 83 | parent::run($js); |
| 84 | - if(isset($this->close)){ |
|
| 84 | + if (isset($this->close)) { |
|
| 85 | 85 | $js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition({$this->_closeTransition})"); |
| 86 | 86 | } |
| 87 | - if(isset($this->_timeout)){ |
|
| 88 | - $js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});",true); |
|
| 87 | + if (isset($this->_timeout)) { |
|
| 88 | + $js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});", true); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function setState($visible=true){ |
|
| 93 | - $visible=($visible===true)?"visible":"hidden"; |
|
| 94 | - return $this->addToPropertyCtrl("class", $visible, array("visible","hidden")); |
|
| 92 | + public function setState($visible=true) { |
|
| 93 | + $visible=($visible===true) ? "visible" : "hidden"; |
|
| 94 | + return $this->addToPropertyCtrl("class", $visible, array("visible", "hidden")); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function setVariation($value="floating"){ |
|
| 98 | - return $this->addToPropertyCtrl("class", $value, array("floating","compact")); |
|
| 97 | + public function setVariation($value="floating") { |
|
| 98 | + return $this->addToPropertyCtrl("class", $value, array("floating", "compact")); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function setStyle($style){ |
|
| 101 | + public function setStyle($style) { |
|
| 102 | 102 | return $this->addToPropertyCtrl("class", $style, Style::getConstants()); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function setError(){ |
|
| 105 | + public function setError() { |
|
| 106 | 106 | return $this->setStyle("error"); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function setWarning(){ |
|
| 109 | + public function setWarning() { |
|
| 110 | 110 | return $this->setStyle("warning"); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - public function setMessage($message){ |
|
| 114 | - if(\is_array($this->content)){ |
|
| 113 | + public function setMessage($message) { |
|
| 114 | + if (\is_array($this->content)) { |
|
| 115 | 115 | $this->content[\sizeof($this->content)-1]=$message; |
| 116 | - }else |
|
| 116 | + } else |
|
| 117 | 117 | $this->setContent($message); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -28,27 +28,27 @@ |
||
| 28 | 28 | $method="get"; |
| 29 | 29 | extract($this->parameters); |
| 30 | 30 | $result=$this->_eventPreparing($preventDefault, $stopPropagation); |
| 31 | - switch($this->method) { |
|
| 31 | + switch ($this->method) { |
|
| 32 | 32 | case "get": |
| 33 | - $result.=$js->getDeferred($url, $responseElement, $params, $jsCallback, $attr,$jqueryDone,$ajaxTransition); |
|
| 33 | + $result.=$js->getDeferred($url, $responseElement, $params, $jsCallback, $attr, $jqueryDone, $ajaxTransition); |
|
| 34 | 34 | break; |
| 35 | 35 | case "post": |
| 36 | - $result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition); |
|
| 36 | + $result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition); |
|
| 37 | 37 | break; |
| 38 | 38 | case "postForm": |
| 39 | - $result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition); |
|
| 39 | + $result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition); |
|
| 40 | 40 | break; |
| 41 | 41 | case "json": |
| 42 | - $result.=$js->jsonDeferred($url,$method,$params,$jsCallback); |
|
| 42 | + $result.=$js->jsonDeferred($url, $method, $params, $jsCallback); |
|
| 43 | 43 | break; |
| 44 | 44 | case "jsonArray": |
| 45 | - $result.=$js->jsonArrayDeferred($modelSelector, $url,$method,$params,$jsCallback); |
|
| 45 | + $result.=$js->jsonArrayDeferred($modelSelector, $url, $method, $params, $jsCallback); |
|
| 46 | 46 | break; |
| 47 | 47 | } |
| 48 | 48 | return $result; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - protected function _eventPreparing($preventDefault,$stopPropagation){ |
|
| 51 | + protected function _eventPreparing($preventDefault, $stopPropagation) { |
|
| 52 | 52 | $result=""; |
| 53 | 53 | if ($preventDefault===true) { |
| 54 | 54 | $result.=Javascript::$preventDefault; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | */ |
| 25 | 25 | class DataTable extends Widget { |
| 26 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
| 26 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
| 27 | 27 | protected $_searchField; |
| 28 | 28 | protected $_urls; |
| 29 | 29 | protected $_pagination; |
@@ -39,35 +39,35 @@ discard block |
||
| 39 | 39 | protected $_sortable; |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 43 | - parent::__construct($identifier, $model,$modelInstance); |
|
| 44 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
| 42 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 43 | + parent::__construct($identifier, $model, $modelInstance); |
|
| 44 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
| 45 | 45 | $this->_urls=[]; |
| 46 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
| 46 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
| 47 | 47 | $this->_emptyMessage->setIcon("info circle"); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public function run(JsUtils $js){ |
|
| 51 | - if($this->_hasCheckboxes && isset($js)){ |
|
| 50 | + public function run(JsUtils $js) { |
|
| 51 | + if ($this->_hasCheckboxes && isset($js)) { |
|
| 52 | 52 | $this->_runCheckboxes($js); |
| 53 | 53 | } |
| 54 | - if($this->_visibleHover){ |
|
| 55 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 56 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 54 | + if ($this->_visibleHover) { |
|
| 55 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 56 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 57 | 57 | } |
| 58 | - if(\is_array($this->_deleteBehavior)) |
|
| 59 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
| 60 | - if(\is_array($this->_editBehavior)) |
|
| 61 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
| 58 | + if (\is_array($this->_deleteBehavior)) |
|
| 59 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
| 60 | + if (\is_array($this->_editBehavior)) |
|
| 61 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
| 62 | 62 | return parent::run($js); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | |
| 67 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
| 68 | - if(isset($this->_urls[$op])){ |
|
| 69 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
| 70 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
| 67 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
| 68 | + if (isset($this->_urls[$op])) { |
|
| 69 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
| 70 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -80,134 +80,134 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
| 83 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 84 | - if(!$this->_generated){ |
|
| 83 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 84 | + if (!$this->_generated) { |
|
| 85 | 85 | $this->_instanceViewer->setInstance($this->_model); |
| 86 | 86 | $captions=$this->_instanceViewer->getCaptions(); |
| 87 | 87 | |
| 88 | 88 | $table=$this->content["table"]; |
| 89 | 89 | |
| 90 | - if($this->_hasCheckboxes){ |
|
| 90 | + if ($this->_hasCheckboxes) { |
|
| 91 | 91 | $this->_generateMainCheckbox($captions); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $table->setRowCount(0, \sizeof($captions)); |
| 95 | - $this->_generateHeader($table,$captions); |
|
| 95 | + $this->_generateHeader($table, $captions); |
|
| 96 | 96 | |
| 97 | - if(isset($this->_compileParts)) |
|
| 97 | + if (isset($this->_compileParts)) |
|
| 98 | 98 | $table->setCompileParts($this->_compileParts); |
| 99 | 99 | |
| 100 | - if(isset($this->_searchField) && isset($js)){ |
|
| 101 | - if(isset($this->_urls["refresh"])) |
|
| 102 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 100 | + if (isset($this->_searchField) && isset($js)) { |
|
| 101 | + if (isset($this->_urls["refresh"])) |
|
| 102 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $this->_generateContent($table); |
| 106 | 106 | |
| 107 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
| 107 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
| 108 | 108 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(isset($this->_toolbar)){ |
|
| 111 | + if (isset($this->_toolbar)) { |
|
| 112 | 112 | $this->_setToolbarPosition($table, $captions); |
| 113 | 113 | } |
| 114 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
| 115 | - $this->_generatePagination($table,$js); |
|
| 114 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
| 115 | + $this->_generatePagination($table, $js); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
| 118 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
| 119 | 119 | $this->_compileForm(); |
| 120 | 120 | |
| 121 | 121 | $this->_generated=true; |
| 122 | 122 | } |
| 123 | - return parent::compile($js,$view); |
|
| 123 | + return parent::compile($js, $view); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - protected function _generateHeader(HtmlTable $table,$captions){ |
|
| 126 | + protected function _generateHeader(HtmlTable $table, $captions) { |
|
| 127 | 127 | $table->setHeaderValues($captions); |
| 128 | - if(isset($this->_sortable)){ |
|
| 128 | + if (isset($this->_sortable)) { |
|
| 129 | 129 | $table->setSortable($this->_sortable); |
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
| 134 | 134 | |
| 135 | - protected function _generateContent($table){ |
|
| 135 | + protected function _generateContent($table) { |
|
| 136 | 136 | $objects=$this->_modelInstance; |
| 137 | - if(isset($this->_pagination)){ |
|
| 137 | + if (isset($this->_pagination)) { |
|
| 138 | 138 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
| 139 | 139 | } |
| 140 | 140 | InstanceViewer::setIndex(0); |
| 141 | 141 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
| 142 | 142 | return $this->_generateRow($instance, $table); |
| 143 | 143 | }); |
| 144 | - if($table->getRowCount()==0){ |
|
| 144 | + if ($table->getRowCount()==0) { |
|
| 145 | 145 | $result=$table->addRow(); |
| 146 | 146 | $result->mergeRow(); |
| 147 | 147 | $result->setValues([$this->_emptyMessage]); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - protected function _generateRow($instance,&$table,$checkedClass=null){ |
|
| 151 | + protected function _generateRow($instance, &$table, $checkedClass=null) { |
|
| 152 | 152 | $this->_instanceViewer->setInstance($instance); |
| 153 | 153 | InstanceViewer::$index++; |
| 154 | - $values= $this->_instanceViewer->getValues(); |
|
| 155 | - if($this->_hasCheckboxes){ |
|
| 156 | - $ck=new HtmlCheckbox("ck-".$this->identifier,""); |
|
| 154 | + $values=$this->_instanceViewer->getValues(); |
|
| 155 | + if ($this->_hasCheckboxes) { |
|
| 156 | + $ck=new HtmlCheckbox("ck-".$this->identifier, ""); |
|
| 157 | 157 | $field=$ck->getField(); |
| 158 | - $field->setProperty("value",$this->_instanceViewer->getIdentifier()); |
|
| 158 | + $field->setProperty("value", $this->_instanceViewer->getIdentifier()); |
|
| 159 | 159 | $field->setProperty("name", "selection[]"); |
| 160 | - if(isset($checkedClass)) |
|
| 160 | + if (isset($checkedClass)) |
|
| 161 | 161 | $field->setClass($checkedClass); |
| 162 | 162 | \array_unshift($values, $ck); |
| 163 | 163 | } |
| 164 | 164 | $result=$table->newRow(); |
| 165 | 165 | $result->setIdentifier($this->identifier."-tr-".$this->_instanceViewer->getIdentifier()); |
| 166 | 166 | $result->setValues($values); |
| 167 | - $result->addToProperty("class",$this->_rowClass); |
|
| 167 | + $result->addToProperty("class", $this->_rowClass); |
|
| 168 | 168 | return $result; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - protected function _generatePagination($table,$js=NULL){ |
|
| 172 | - if(isset($this->_toolbar)){ |
|
| 173 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 171 | + protected function _generatePagination($table, $js=NULL) { |
|
| 172 | + if (isset($this->_toolbar)) { |
|
| 173 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 174 | 174 | $this->_toolbar->setFloated("left"); |
| 175 | 175 | } |
| 176 | 176 | $footer=$table->getFooter(); |
| 177 | 177 | $footer->mergeCol(); |
| 178 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
| 178 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
| 179 | 179 | $menu->floatRight(); |
| 180 | 180 | $menu->setActiveItem($this->_pagination->getPage()-1); |
| 181 | 181 | $footer->addValues($menu); |
| 182 | - $this->_associatePaginationBehavior($menu,$js); |
|
| 182 | + $this->_associatePaginationBehavior($menu, $js); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){ |
|
| 186 | - if(isset($this->_urls["refresh"])){ |
|
| 187 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 185 | + protected function _associatePaginationBehavior(HtmlMenu $menu, JsUtils $js=NULL) { |
|
| 186 | + if (isset($this->_urls["refresh"])) { |
|
| 187 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - protected function _getFieldName($index){ |
|
| 191 | + protected function _getFieldName($index) { |
|
| 192 | 192 | return parent::_getFieldName($index)."[]"; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - protected function _getFieldCaption($index){ |
|
| 195 | + protected function _getFieldCaption($index) { |
|
| 196 | 196 | return null; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
| 200 | - switch ($this->_toolbarPosition){ |
|
| 199 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 200 | + switch ($this->_toolbarPosition) { |
|
| 201 | 201 | case PositionInTable::BEFORETABLE: |
| 202 | 202 | case PositionInTable::AFTERTABLE: |
| 203 | - if(isset($this->_compileParts)===false){ |
|
| 203 | + if (isset($this->_compileParts)===false) { |
|
| 204 | 204 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 205 | 205 | } |
| 206 | 206 | break; |
| 207 | 207 | case PositionInTable::HEADER: |
| 208 | 208 | case PositionInTable::FOOTER: |
| 209 | 209 | case PositionInTable::BODY: |
| 210 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
| 210 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
| 211 | 211 | break; |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -219,23 +219,23 @@ discard block |
||
| 219 | 219 | * @param callable $callback function called after the field compilation |
| 220 | 220 | * @return DataTable |
| 221 | 221 | */ |
| 222 | - public function afterCompile($index,$callback){ |
|
| 223 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
| 222 | + public function afterCompile($index, $callback) { |
|
| 223 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
| 224 | 224 | return $this; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - private function addToolbarRow($part,$table,$captions){ |
|
| 227 | + private function addToolbarRow($part, $table, $captions) { |
|
| 228 | 228 | $hasPart=$table->hasPart($part); |
| 229 | - if($hasPart){ |
|
| 229 | + if ($hasPart) { |
|
| 230 | 230 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 231 | - }else{ |
|
| 231 | + } else { |
|
| 232 | 232 | $row=$table->getPart($part)->getRow(0); |
| 233 | 233 | } |
| 234 | 234 | $row->mergeCol(); |
| 235 | 235 | $row->setValues([$this->_toolbar]); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - public function getHtmlComponent(){ |
|
| 238 | + public function getHtmlComponent() { |
|
| 239 | 239 | return $this->content["table"]; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | * @return DataTable |
| 250 | 250 | */ |
| 251 | 251 | public function setUrls($urls) { |
| 252 | - if(\is_array($urls)){ |
|
| 253 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
| 254 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
| 255 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
| 256 | - }else{ |
|
| 257 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
| 252 | + if (\is_array($urls)) { |
|
| 253 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 254 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 255 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 256 | + } else { |
|
| 257 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
| 258 | 258 | } |
| 259 | 259 | return $this; |
| 260 | 260 | } |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 268 | 268 | * @return DataTable |
| 269 | 269 | */ |
| 270 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
| 271 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
| 270 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 271 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 272 | 272 | return $this; |
| 273 | 273 | } |
| 274 | 274 | |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 280 | 280 | * @return DataTable |
| 281 | 281 | */ |
| 282 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
| 283 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
| 282 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
| 283 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
| 284 | 284 | return $this; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -290,20 +290,20 @@ discard block |
||
| 290 | 290 | * @param array $compileParts |
| 291 | 291 | * @return DataTable |
| 292 | 292 | */ |
| 293 | - public function refresh($compileParts=["tbody"]){ |
|
| 293 | + public function refresh($compileParts=["tbody"]) { |
|
| 294 | 294 | $this->_compileParts=$compileParts; |
| 295 | 295 | return $this; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | |
| 299 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
| 299 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 300 | 300 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - public function getSearchField(){ |
|
| 304 | - if(isset($this->_searchField)===false){ |
|
| 305 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
| 306 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
| 303 | + public function getSearchField() { |
|
| 304 | + if (isset($this->_searchField)===false) { |
|
| 305 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 306 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
| 307 | 307 | } |
| 308 | 308 | return $this->_searchField; |
| 309 | 309 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | return $this; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - public function asForm(){ |
|
| 322 | + public function asForm() { |
|
| 323 | 323 | return $this->getForm(); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | protected function getTargetSelector() { |
| 329 | 329 | $result=$this->_targetSelector; |
| 330 | - if(!isset($result)) |
|
| 330 | + if (!isset($result)) |
|
| 331 | 331 | $result="#".$this->identifier; |
| 332 | 332 | return $result; |
| 333 | 333 | } |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | public function getRefreshSelector() { |
| 346 | - if(isset($this->_refreshSelector)) |
|
| 346 | + if (isset($this->_refreshSelector)) |
|
| 347 | 347 | return $this->_refreshSelector; |
| 348 | 348 | return "#".$this->identifier." tbody"; |
| 349 | 349 | } |
@@ -357,9 +357,9 @@ discard block |
||
| 357 | 357 | * {@inheritDoc} |
| 358 | 358 | * @see \Ajax\common\Widget::show() |
| 359 | 359 | */ |
| 360 | - public function show($modelInstance){ |
|
| 361 | - if(\is_array($modelInstance)){ |
|
| 362 | - if(\is_array(array_values($modelInstance)[0])) |
|
| 360 | + public function show($modelInstance) { |
|
| 361 | + if (\is_array($modelInstance)) { |
|
| 362 | + if (\is_array(array_values($modelInstance)[0])) |
|
| 363 | 363 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
| 364 | 364 | } |
| 365 | 365 | $this->_modelInstance=$modelInstance; |