@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | use Ajax\semantic\html\collections\form\traits\FormTrait; |
| 19 | 19 | |
| 20 | 20 | abstract class Widget extends HtmlDoubleElement { |
| 21 | - use FieldAsTrait,FormTrait; |
|
| 21 | + use FieldAsTrait, FormTrait; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @var string classname |
@@ -49,36 +49,36 @@ discard block |
||
| 49 | 49 | protected $_form; |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 52 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 53 | 53 | parent::__construct($identifier); |
| 54 | 54 | $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
| 55 | 55 | $this->setModel($model); |
| 56 | - if(isset($modelInstance)); |
|
| 56 | + if (isset($modelInstance)); |
|
| 57 | 57 | $this->show($modelInstance); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - protected function _init($instanceViewer,$contentKey,$content,$edition){ |
|
| 60 | + protected function _init($instanceViewer, $contentKey, $content, $edition) { |
|
| 61 | 61 | $this->_instanceViewer=$instanceViewer; |
| 62 | 62 | $this->content=[$contentKey=>$content]; |
| 63 | 63 | $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
| 64 | 64 | $this->_edition=$edition; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
| 67 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
| 68 | 68 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - protected function _getFieldName($index){ |
|
| 71 | + protected function _getFieldName($index) { |
|
| 72 | 72 | return $this->_instanceViewer->getFieldName($index); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - protected function _getFieldCaption($index){ |
|
| 75 | + protected function _getFieldCaption($index) { |
|
| 76 | 76 | return $this->_instanceViewer->getCaption($index); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
| 79 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
| 80 | 80 | |
| 81 | - public function show($modelInstance){ |
|
| 81 | + public function show($modelInstance) { |
|
| 82 | 82 | $this->_modelInstance=$modelInstance; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -102,42 +102,42 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | abstract public function getHtmlComponent(); |
| 104 | 104 | |
| 105 | - public function setColor($color){ |
|
| 105 | + public function setColor($color) { |
|
| 106 | 106 | return $this->getHtmlComponent()->setColor($color); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
| 110 | - public function setCaptions($captions){ |
|
| 110 | + public function setCaptions($captions) { |
|
| 111 | 111 | $this->_instanceViewer->setCaptions($captions); |
| 112 | 112 | return $this; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function setFields($fields){ |
|
| 115 | + public function setFields($fields) { |
|
| 116 | 116 | $this->_instanceViewer->setVisibleProperties($fields); |
| 117 | 117 | return $this; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - public function addField($field){ |
|
| 120 | + public function addField($field) { |
|
| 121 | 121 | $this->_instanceViewer->addField($field); |
| 122 | 122 | return $this; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function insertField($index,$field){ |
|
| 125 | + public function insertField($index, $field) { |
|
| 126 | 126 | $this->_instanceViewer->insertField($index, $field); |
| 127 | 127 | return $this; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function insertInField($index,$field){ |
|
| 130 | + public function insertInField($index, $field) { |
|
| 131 | 131 | $this->_instanceViewer->insertInField($index, $field); |
| 132 | 132 | return $this; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function setValueFunction($index,$callback){ |
|
| 135 | + public function setValueFunction($index, $callback) { |
|
| 136 | 136 | $this->_instanceViewer->setValueFunction($index, $callback); |
| 137 | 137 | return $this; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public function setIdentifierFunction($callback){ |
|
| 140 | + public function setIdentifierFunction($callback) { |
|
| 141 | 141 | $this->_instanceViewer->setIdentifierFunction($callback); |
| 142 | 142 | return $this; |
| 143 | 143 | } |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | /** |
| 146 | 146 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
| 147 | 147 | */ |
| 148 | - public function getToolbar(){ |
|
| 149 | - if(isset($this->_toolbar)===false){ |
|
| 148 | + public function getToolbar() { |
|
| 149 | + if (isset($this->_toolbar)===false) { |
|
| 150 | 150 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
| 151 | 151 | } |
| 152 | 152 | return $this->_toolbar; |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | * @param callable $callback function to call on $element |
| 159 | 159 | * @return \Ajax\common\html\HtmlDoubleElement |
| 160 | 160 | */ |
| 161 | - public function addInToolbar($element,$callback=NULL){ |
|
| 161 | + public function addInToolbar($element, $callback=NULL) { |
|
| 162 | 162 | $tb=$this->getToolbar(); |
| 163 | - if(isset($callback)){ |
|
| 164 | - if(\is_callable($callback)){ |
|
| 163 | + if (isset($callback)) { |
|
| 164 | + if (\is_callable($callback)) { |
|
| 165 | 165 | $callback($element); |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | * @param callable $callback function($element) |
| 175 | 175 | * @return \Ajax\common\html\HtmlDoubleElement |
| 176 | 176 | */ |
| 177 | - public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
| 178 | - $result=$this->addInToolbar($caption,$callback); |
|
| 179 | - if(isset($icon)) |
|
| 177 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
| 178 | + $result=$this->addInToolbar($caption, $callback); |
|
| 179 | + if (isset($icon)) |
|
| 180 | 180 | $result->addIcon($icon); |
| 181 | 181 | return $result; |
| 182 | 182 | } |
@@ -186,14 +186,14 @@ discard block |
||
| 186 | 186 | * @param callable $callback function($element) |
| 187 | 187 | * @return \Ajax\common\Widget |
| 188 | 188 | */ |
| 189 | - public function addItemsInToolbar(array $items,$callback=NULL){ |
|
| 190 | - if(JArray::isAssociative($items)){ |
|
| 191 | - foreach ($items as $icon=>$item){ |
|
| 192 | - $this->addItemInToolbar($item,$icon,$callback); |
|
| 189 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
| 190 | + if (JArray::isAssociative($items)) { |
|
| 191 | + foreach ($items as $icon=>$item) { |
|
| 192 | + $this->addItemInToolbar($item, $icon, $callback); |
|
| 193 | 193 | } |
| 194 | - }else{ |
|
| 195 | - foreach ($items as $item){ |
|
| 196 | - $this->addItemInToolbar($item,null,$callback); |
|
| 194 | + } else { |
|
| 195 | + foreach ($items as $item) { |
|
| 196 | + $this->addItemInToolbar($item, null, $callback); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | return $this; |
@@ -205,12 +205,12 @@ discard block |
||
| 205 | 205 | * @param callable $callback function($element) |
| 206 | 206 | * @return \Ajax\common\html\HtmlDoubleElement |
| 207 | 207 | */ |
| 208 | - public function addDropdownInToolbar($value,$items,$callback=NULL){ |
|
| 208 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
| 209 | 209 | $dd=$value; |
| 210 | 210 | if (\is_string($value)) { |
| 211 | - $dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
| 211 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
| 212 | 212 | } |
| 213 | - return $this->addInToolbar($dd,$callback); |
|
| 213 | + return $this->addInToolbar($dd, $callback); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | * @param callable $callback function($element) |
| 219 | 219 | * @return \Ajax\common\html\HtmlDoubleElement |
| 220 | 220 | */ |
| 221 | - public function addButtonInToolbar($caption,$callback=NULL){ |
|
| 222 | - $bt=new HtmlButton("bt-".$caption,$caption); |
|
| 223 | - return $this->addInToolbar($bt,$callback); |
|
| 221 | + public function addButtonInToolbar($caption, $callback=NULL) { |
|
| 222 | + $bt=new HtmlButton("bt-".$caption, $caption); |
|
| 223 | + return $this->addInToolbar($bt, $callback); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -229,9 +229,9 @@ discard block |
||
| 229 | 229 | * @param callable $callback function($element) |
| 230 | 230 | * @return \Ajax\common\html\HtmlDoubleElement |
| 231 | 231 | */ |
| 232 | - public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
| 233 | - $bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
| 234 | - return $this->addInToolbar($bts,$callback); |
|
| 232 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
| 233 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
| 234 | + return $this->addInToolbar($bts, $callback); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @param boolean $labeled |
| 242 | 242 | * @return \Ajax\common\html\HtmlDoubleElement |
| 243 | 243 | */ |
| 244 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
| 245 | - $bt=new HtmlButton("",$caption); |
|
| 246 | - $bt->addIcon($icon,$before,$labeled); |
|
| 244 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
| 245 | + $bt=new HtmlButton("", $caption); |
|
| 246 | + $bt->addIcon($icon, $before, $labeled); |
|
| 247 | 247 | return $this->addInToolbar($bt); |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){ |
|
| 251 | - $button=new HtmlButton($identifier,$value,$cssStyle); |
|
| 252 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement); |
|
| 250 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL) { |
|
| 251 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
| 252 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement); |
|
| 253 | 253 | return $this->addInToolbar($button); |
| 254 | 254 | } |
| 255 | 255 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model |
| 280 | 280 | * @return \Ajax\common\Widget |
| 281 | 281 | */ |
| 282 | - public function setDefaultValueFunction($defaultValueFunction){ |
|
| 282 | + public function setDefaultValueFunction($defaultValueFunction) { |
|
| 283 | 283 | $this->_instanceViewer->setDefaultValueFunction($defaultValueFunction); |
| 284 | 284 | return $this; |
| 285 | 285 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @param string|boolean $disable |
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | - public function jsDisabled($disable=true){ |
|
| 291 | + public function jsDisabled($disable=true) { |
|
| 292 | 292 | return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
| 293 | 293 | } |
| 294 | 294 | |
@@ -297,12 +297,12 @@ discard block |
||
| 297 | 297 | * @param callable $callback function($element) |
| 298 | 298 | * @return \Ajax\common\html\HtmlDoubleElement |
| 299 | 299 | */ |
| 300 | - public function addEditButtonInToolbar($caption,$callback=NULL){ |
|
| 301 | - $bt=new HtmlButton($this->identifier."-editBtn",$caption); |
|
| 300 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
| 301 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
| 302 | 302 | $bt->setToggle(); |
| 303 | 303 | $bt->setActive($this->_edition); |
| 304 | 304 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
| 305 | - return $this->addInToolbar($bt,$callback); |
|
| 305 | + return $this->addInToolbar($bt, $callback); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | public function setToolbar(HtmlMenu $_toolbar) { |
@@ -316,35 +316,35 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | public function getForm() { |
| 319 | - if(!isset($this->_form)){ |
|
| 319 | + if (!isset($this->_form)) { |
|
| 320 | 320 | $this->_form=new HtmlForm("frm-".$this->identifier); |
| 321 | 321 | $this->setEdition(true); |
| 322 | 322 | } |
| 323 | 323 | return $this->_form; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - public function run(JsUtils $js=NULL){ |
|
| 326 | + public function run(JsUtils $js=NULL) { |
|
| 327 | 327 | $result=parent::run($js); |
| 328 | - if(isset($this->_form)){ |
|
| 328 | + if (isset($this->_form)) { |
|
| 329 | 329 | $this->runForm($js); |
| 330 | 330 | } |
| 331 | 331 | return $result; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - protected function runForm(JsUtils $js){ |
|
| 334 | + protected function runForm(JsUtils $js) { |
|
| 335 | 335 | $fields=$this->getContentInstances(HtmlFormField::class); |
| 336 | - foreach ($fields as $field){ |
|
| 336 | + foreach ($fields as $field) { |
|
| 337 | 337 | $this->_form->addField($field); |
| 338 | 338 | } |
| 339 | 339 | return $this->_form->run($js); |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - protected function _compileForm(JsUtils $js=NULL,&$view=NULL){ |
|
| 343 | - if(isset($this->_form)){ |
|
| 342 | + protected function _compileForm(JsUtils $js=NULL, &$view=NULL) { |
|
| 343 | + if (isset($this->_form)) { |
|
| 344 | 344 | $noValidate=""; |
| 345 | - if(\sizeof($this->_form->getValidationParams())>0) |
|
| 345 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
| 346 | 346 | $noValidate="novalidate"; |
| 347 | - $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>"); |
|
| 347 | + $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | |
@@ -176,8 +176,9 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
| 178 | 178 | $result=$this->addInToolbar($caption,$callback); |
| 179 | - if(isset($icon)) |
|
| 180 | - $result->addIcon($icon); |
|
| 179 | + if(isset($icon)) { |
|
| 180 | + $result->addIcon($icon); |
|
| 181 | + } |
|
| 181 | 182 | return $result; |
| 182 | 183 | } |
| 183 | 184 | |
@@ -191,7 +192,7 @@ discard block |
||
| 191 | 192 | foreach ($items as $icon=>$item){ |
| 192 | 193 | $this->addItemInToolbar($item,$icon,$callback); |
| 193 | 194 | } |
| 194 | - }else{ |
|
| 195 | + } else{ |
|
| 195 | 196 | foreach ($items as $item){ |
| 196 | 197 | $this->addItemInToolbar($item,null,$callback); |
| 197 | 198 | } |
@@ -342,8 +343,9 @@ discard block |
||
| 342 | 343 | protected function _compileForm(JsUtils $js=NULL,&$view=NULL){ |
| 343 | 344 | if(isset($this->_form)){ |
| 344 | 345 | $noValidate=""; |
| 345 | - if(\sizeof($this->_form->getValidationParams())>0) |
|
| 346 | - $noValidate="novalidate"; |
|
| 346 | + if(\sizeof($this->_form->getValidationParams())>0) { |
|
| 347 | + $noValidate="novalidate"; |
|
| 348 | + } |
|
| 347 | 349 | $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>"); |
| 348 | 350 | } |
| 349 | 351 | } |
@@ -19,49 +19,49 @@ 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){ |
|
| 31 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 32 | 32 | $this->_instanceViewer->setInstance($this->_modelInstance); |
| 33 | 33 | |
| 34 | 34 | $form=$this->content["form"]; |
| 35 | 35 | $this->_generateContent($form); |
| 36 | 36 | |
| 37 | - if(isset($this->_toolbar)){ |
|
| 37 | + if (isset($this->_toolbar)) { |
|
| 38 | 38 | $this->_setToolbarPosition($form); |
| 39 | 39 | } |
| 40 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
| 41 | - return parent::compile($js,$view); |
|
| 40 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
| 41 | + return parent::compile($js, $view); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @param HtmlForm $form |
| 46 | 46 | */ |
| 47 | - protected function _generateContent($form){ |
|
| 48 | - $values= $this->_instanceViewer->getValues(); |
|
| 47 | + protected function _generateContent($form) { |
|
| 48 | + $values=$this->_instanceViewer->getValues(); |
|
| 49 | 49 | $count=$this->_instanceViewer->count(); |
| 50 | 50 | |
| 51 | 51 | $separators=$this->_instanceViewer->getSeparators(); |
| 52 | 52 | $size=\sizeof($separators); |
| 53 | - if($size===1){ |
|
| 54 | - foreach ($values as $v){ |
|
| 53 | + if ($size===1) { |
|
| 54 | + foreach ($values as $v) { |
|
| 55 | 55 | $form->addField($v); |
| 56 | 56 | } |
| 57 | - }else{ |
|
| 57 | + } else { |
|
| 58 | 58 | $separators[]=$count; |
| 59 | - for($i=0;$i<$size;$i++){ |
|
| 60 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
| 59 | + for ($i=0; $i<$size; $i++) { |
|
| 60 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
| 61 | 61 | //TODO check why $fields is empty |
| 62 | - if(\sizeof($fields)===1){ |
|
| 62 | + if (\sizeof($fields)===1) { |
|
| 63 | 63 | $form->addField($fields[0]); |
| 64 | - }elseif(\sizeof($fields)>1){ |
|
| 64 | + }elseif (\sizeof($fields)>1) { |
|
| 65 | 65 | $form->addFields($fields); |
| 66 | 66 | $i+=\sizeof($fields)-1; |
| 67 | 67 | } |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | * {@inheritDoc} |
| 74 | 74 | * @see \Ajax\common\Widget::getForm() |
| 75 | 75 | */ |
| 76 | - public function getForm(){ |
|
| 76 | + public function getForm() { |
|
| 77 | 77 | return $this->content["form"]; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function addSeparatorAfter($fieldNum){ |
|
| 80 | + public function addSeparatorAfter($fieldNum) { |
|
| 81 | 81 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
| 82 | 82 | return $this; |
| 83 | 83 | } |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | return $this; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 95 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
| 96 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 94 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 95 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
| 96 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 97 | 97 | $button->setProperty("type", "reset"); |
| 98 | 98 | return $button; |
| 99 | - }, $index,$attributes); |
|
| 99 | + }, $index, $attributes); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function run(JsUtils $js=NULL){ |
|
| 118 | + public function run(JsUtils $js=NULL) { |
|
| 119 | 119 | return parent::run($js); |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | \ No newline at end of file |
@@ -23,23 +23,23 @@ discard block |
||
| 23 | 23 | * @property boolean $_edition |
| 24 | 24 | * @property mixed _modelInstance |
| 25 | 25 | */ |
| 26 | -trait FieldAsTrait{ |
|
| 26 | +trait FieldAsTrait { |
|
| 27 | 27 | |
| 28 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
| 29 | - abstract public function setValueFunction($index,$callback); |
|
| 28 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
| 29 | + abstract public function setValueFunction($index, $callback); |
|
| 30 | 30 | abstract protected function _getFieldName($index); |
| 31 | 31 | abstract protected function _getFieldCaption($index); |
| 32 | - abstract protected function _buttonAsSubmit(&$button,$event,$url,$responseElement=NULL); |
|
| 32 | + abstract protected function _buttonAsSubmit(&$button, $event, $url, $responseElement=NULL); |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @param HtmlFormField $element |
| 36 | 36 | * @param array $attributes |
| 37 | 37 | */ |
| 38 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
| 39 | - if(isset($attributes["callback"])){ |
|
| 38 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
| 39 | + if (isset($attributes["callback"])) { |
|
| 40 | 40 | $callback=$attributes["callback"]; |
| 41 | - if(\is_callable($callback)){ |
|
| 42 | - $callback($element,$this->_modelInstance,$index); |
|
| 41 | + if (\is_callable($callback)) { |
|
| 42 | + $callback($element, $this->_modelInstance, $index); |
|
| 43 | 43 | unset($attributes["callback"]); |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -47,42 +47,42 @@ discard block |
||
| 47 | 47 | $element->fromArray($attributes); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 51 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 50 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 51 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 52 | 52 | return $label; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - protected function _addRules($element,&$attributes){ |
|
| 56 | - if(isset($attributes["rules"])){ |
|
| 55 | + protected function _addRules($element, &$attributes) { |
|
| 56 | + if (isset($attributes["rules"])) { |
|
| 57 | 57 | $rules=$attributes["rules"]; |
| 58 | - if(\is_array($rules)){ |
|
| 58 | + if (\is_array($rules)) { |
|
| 59 | 59 | $element->addRules($rules); |
| 60 | 60 | } |
| 61 | - else{ |
|
| 61 | + else { |
|
| 62 | 62 | $element->addRule($rules); |
| 63 | 63 | } |
| 64 | 64 | unset($attributes["rules"]); |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - protected function _prepareFormFields(&$field,$name,&$attributes){ |
|
| 68 | + protected function _prepareFormFields(&$field, $name, &$attributes) { |
|
| 69 | 69 | $field->setName($name); |
| 70 | 70 | $this->_addRules($field, $attributes); |
| 71 | 71 | return $field; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
|
| 75 | - $this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback,$prefix){ |
|
| 74 | + protected function _fieldAs($elementCallback, $index, $attributes=NULL, $prefix=null) { |
|
| 75 | + $this->setValueFunction($index, function($value) use ($index, &$attributes, $elementCallback, $prefix){ |
|
| 76 | 76 | $caption=$this->_getFieldCaption($index); |
| 77 | 77 | $name=$this->_getFieldName($index); |
| 78 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
| 79 | - if(isset($attributes["name"])){ |
|
| 78 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
| 79 | + if (isset($attributes["name"])) { |
|
| 80 | 80 | $name=$attributes["name"]; |
| 81 | 81 | unset($attributes["name"]); |
| 82 | 82 | } |
| 83 | - $element=$elementCallback($id,$name,$value,$caption); |
|
| 84 | - if(\is_array($attributes)){ |
|
| 85 | - $this->_applyAttributes($element, $attributes,$index); |
|
| 83 | + $element=$elementCallback($id, $name, $value, $caption); |
|
| 84 | + if (\is_array($attributes)) { |
|
| 85 | + $this->_applyAttributes($element, $attributes, $index); |
|
| 86 | 86 | } |
| 87 | 87 | $element->setDisabled(!$this->_edition); |
| 88 | 88 | return $element; |
@@ -91,151 +91,151 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
| 94 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
| 95 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
| 96 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
| 94 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 95 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
| 96 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 97 | 97 | return $pb; |
| 98 | 98 | }); |
| 99 | 99 | return $this; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
| 103 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
| 104 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
| 102 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 103 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
| 104 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 105 | 105 | return $rating; |
| 106 | 106 | }); |
| 107 | 107 | return $this; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function fieldAsLabel($index,$icon=NULL){ |
|
| 111 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
| 112 | - $lbl=$this->_getLabelField($caption,$icon); |
|
| 110 | + public function fieldAsLabel($index, $icon=NULL) { |
|
| 111 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
| 112 | + $lbl=$this->_getLabelField($caption, $icon); |
|
| 113 | 113 | return $lbl; |
| 114 | 114 | }); |
| 115 | 115 | return $this; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
| 119 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
| 120 | - $header=new HtmlHeader($id,$niveau,$value); |
|
| 121 | - if(isset($icon)) |
|
| 118 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
| 119 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
| 120 | + $header=new HtmlHeader($id, $niveau, $value); |
|
| 121 | + if (isset($icon)) |
|
| 122 | 122 | $header->asIcon($icon, $value); |
| 123 | 123 | return $header; |
| 124 | - }, $index,$attributes,"header"); |
|
| 124 | + }, $index, $attributes, "header"); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
| 128 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
| 129 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
| 130 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 128 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
| 129 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
| 130 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
| 131 | 131 | return $image; |
| 132 | 132 | }); |
| 133 | 133 | return $this; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
| 137 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 138 | - $img=new HtmlImage($id,$value); |
|
| 136 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 137 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 138 | + $img=new HtmlImage($id, $value); |
|
| 139 | 139 | $img->asAvatar(); |
| 140 | 140 | return $img; |
| 141 | - }, $index,$attributes,"avatar"); |
|
| 141 | + }, $index, $attributes, "avatar"); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 145 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 146 | - $input= new HtmlRadio($id,$name,$value,$value); |
|
| 144 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 145 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 146 | + $input=new HtmlRadio($id, $name, $value, $value); |
|
| 147 | 147 | return $input; |
| 148 | - }, $index,$attributes,"radio"); |
|
| 148 | + }, $index, $attributes, "radio"); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
| 152 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
| 153 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
| 154 | - }, $index,$attributes,"radios"); |
|
| 151 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
| 152 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
| 153 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
| 154 | + }, $index, $attributes, "radios"); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 158 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
| 159 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
| 157 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 158 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
| 159 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 160 | 160 | return $this->_prepareFormFields($input, $name, $attributes); |
| 161 | - }, $index,$attributes,"input"); |
|
| 161 | + }, $index, $attributes, "input"); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
| 165 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 166 | - $textarea=new HtmlFormTextarea($id,null,$value); |
|
| 164 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 165 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 166 | + $textarea=new HtmlFormTextarea($id, null, $value); |
|
| 167 | 167 | $textarea->setName($name); |
| 168 | 168 | return $textarea; |
| 169 | - }, $index,$attributes,"textarea"); |
|
| 169 | + }, $index, $attributes, "textarea"); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
| 173 | - if(!\is_array($attributes)){ |
|
| 172 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
| 173 | + if (!\is_array($attributes)) { |
|
| 174 | 174 | $attributes=[]; |
| 175 | 175 | } |
| 176 | 176 | $attributes["imputType"]="hidden"; |
| 177 | - return $this->fieldAsInput($index,$attributes); |
|
| 177 | + return $this->fieldAsInput($index, $attributes); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 181 | - return $this->_fieldAs(function($id,$name,$value){ |
|
| 182 | - $input=new HtmlFormCheckbox($id,NULL,$this->_instanceViewer->getIdentifier()); |
|
| 180 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 181 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 182 | + $input=new HtmlFormCheckbox($id, NULL, $this->_instanceViewer->getIdentifier()); |
|
| 183 | 183 | $input->setChecked(JString::isBooleanTrue($value)); |
| 184 | 184 | $input->setName($name); |
| 185 | 185 | return $input; |
| 186 | - }, $index,$attributes,"ck"); |
|
| 186 | + }, $index, $attributes, "ck"); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 190 | - return $this->_fieldAs(function($id,$name,$value) use($elements,$multiple){ |
|
| 191 | - $dd=new HtmlFormDropdown($id,$elements,NULL,$value); |
|
| 192 | - $dd->asSelect($name,$multiple); |
|
| 189 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 190 | + return $this->_fieldAs(function($id, $name, $value) use($elements, $multiple){ |
|
| 191 | + $dd=new HtmlFormDropdown($id, $elements, NULL, $value); |
|
| 192 | + $dd->asSelect($name, $multiple); |
|
| 193 | 193 | return $dd; |
| 194 | - }, $index,$attributes,"dd"); |
|
| 194 | + }, $index, $attributes, "dd"); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
| 198 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
| 199 | - $mess= new HtmlMessage("message-".$id,$value); |
|
| 197 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
| 198 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 199 | + $mess=new HtmlMessage("message-".$id, $value); |
|
| 200 | 200 | $mess->addHeader($caption); |
| 201 | 201 | return $mess; |
| 202 | - }, $index,$attributes,"message"); |
|
| 202 | + }, $index, $attributes, "message"); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /**Change fields type |
| 206 | 206 | * @param array $types an array or associative array $type=>$attribute |
| 207 | 207 | */ |
| 208 | - public function fieldsAs(array $types){ |
|
| 208 | + public function fieldsAs(array $types) { |
|
| 209 | 209 | $i=0; |
| 210 | - if(JArray::isAssociative($types)){ |
|
| 211 | - foreach ($types as $type=>$attributes){ |
|
| 212 | - $this->fieldAs($i++,$type,$attributes); |
|
| 210 | + if (JArray::isAssociative($types)) { |
|
| 211 | + foreach ($types as $type=>$attributes) { |
|
| 212 | + $this->fieldAs($i++, $type, $attributes); |
|
| 213 | 213 | } |
| 214 | - }else{ |
|
| 215 | - foreach ($types as $type){ |
|
| 216 | - $this->fieldAs($i++,$type); |
|
| 214 | + } else { |
|
| 215 | + foreach ($types as $type) { |
|
| 216 | + $this->fieldAs($i++, $type); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
| 221 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
| 222 | 222 | $method="fieldAs".\ucfirst($type); |
| 223 | 223 | |
| 224 | - if(\method_exists($this, $method)){ |
|
| 225 | - if(!\is_array($attributes)){ |
|
| 224 | + if (\method_exists($this, $method)) { |
|
| 225 | + if (!\is_array($attributes)) { |
|
| 226 | 226 | $attributes=[$index]; |
| 227 | - }else{ |
|
| 227 | + } else { |
|
| 228 | 228 | \array_unshift($attributes, $index); |
| 229 | 229 | } |
| 230 | - \call_user_func_array([$this,$method], $attributes); |
|
| 230 | + \call_user_func_array([$this, $method], $attributes); |
|
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
| 235 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle){ |
|
| 236 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 237 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement); |
|
| 234 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 235 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle){ |
|
| 236 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 237 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement); |
|
| 238 | 238 | return $button; |
| 239 | - }, $index,$attributes); |
|
| 239 | + }, $index, $attributes); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | \ No newline at end of file |
@@ -57,8 +57,7 @@ discard block |
||
| 57 | 57 | $rules=$attributes["rules"]; |
| 58 | 58 | if(\is_array($rules)){ |
| 59 | 59 | $element->addRules($rules); |
| 60 | - } |
|
| 61 | - else{ |
|
| 60 | + } else{ |
|
| 62 | 61 | $element->addRule($rules); |
| 63 | 62 | } |
| 64 | 63 | unset($attributes["rules"]); |
@@ -118,8 +117,9 @@ discard block |
||
| 118 | 117 | public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
| 119 | 118 | return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
| 120 | 119 | $header=new HtmlHeader($id,$niveau,$value); |
| 121 | - if(isset($icon)) |
|
| 122 | - $header->asIcon($icon, $value); |
|
| 120 | + if(isset($icon)) { |
|
| 121 | + $header->asIcon($icon, $value); |
|
| 122 | + } |
|
| 123 | 123 | return $header; |
| 124 | 124 | }, $index,$attributes,"header"); |
| 125 | 125 | } |
@@ -127,7 +127,9 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
| 129 | 129 | $this->setValueFunction($index,function($img) use($size,$circular){ |
| 130 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 130 | + $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular) { |
|
| 131 | + $image->setCircular(); |
|
| 132 | + } |
|
| 131 | 133 | return $image; |
| 132 | 134 | }); |
| 133 | 135 | return $this; |
@@ -211,7 +213,7 @@ discard block |
||
| 211 | 213 | foreach ($types as $type=>$attributes){ |
| 212 | 214 | $this->fieldAs($i++,$type,$attributes); |
| 213 | 215 | } |
| 214 | - }else{ |
|
| 216 | + } else{ |
|
| 215 | 217 | foreach ($types as $type){ |
| 216 | 218 | $this->fieldAs($i++,$type); |
| 217 | 219 | } |
@@ -224,7 +226,7 @@ discard block |
||
| 224 | 226 | if(\method_exists($this, $method)){ |
| 225 | 227 | if(!\is_array($attributes)){ |
| 226 | 228 | $attributes=[$index]; |
| 227 | - }else{ |
|
| 229 | + } else{ |
|
| 228 | 230 | \array_unshift($attributes, $index); |
| 229 | 231 | } |
| 230 | 232 | \call_user_func_array([$this,$method], $attributes); |