Completed
Push — master ( a4369d...ea5934 )
by Jean-Christophe
02:50
created
Ajax/common/Widget.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 use Ajax\semantic\html\modules\HtmlModal;
21 21
 
22 22
 abstract class Widget extends HtmlDoubleElement {
23
-	use FieldAsTrait,FormTrait;
23
+	use FieldAsTrait, FormTrait;
24 24
 
25 25
 	/**
26 26
 	 * @var string classname
@@ -53,17 +53,17 @@  discard block
 block discarded – undo
53 53
 	protected $_generated;
54 54
 
55 55
 
56
-	public function __construct($identifier,$model,$modelInstance=NULL) {
56
+	public function __construct($identifier, $model, $modelInstance=NULL) {
57 57
 		parent::__construct($identifier);
58 58
 		$this->_template="%wrapContentBefore%%content%%wrapContentAfter%";
59 59
 		$this->setModel($model);
60
-		if(isset($modelInstance)){
60
+		if (isset($modelInstance)) {
61 61
 			$this->show($modelInstance);
62 62
 		}
63 63
 		$this->_generated=false;
64 64
 	}
65 65
 
66
-	protected function _init($instanceViewer,$contentKey,$content,$edition){
66
+	protected function _init($instanceViewer, $contentKey, $content, $edition) {
67 67
 		$this->_instanceViewer=$instanceViewer;
68 68
 		$this->content=[$contentKey=>$content];
69 69
 		$this->_self=$content;
@@ -75,31 +75,31 @@  discard block
 block discarded – undo
75 75
 	 * @param int|string $fieldName
76 76
 	 * @return int|string
77 77
 	 */
78
-	protected function _getIndex($fieldName){
78
+	protected function _getIndex($fieldName) {
79 79
 		$index=$fieldName;
80
-		if(\is_string($fieldName)){
80
+		if (\is_string($fieldName)) {
81 81
 			$fields=$this->_instanceViewer->getVisibleProperties();
82 82
 			$index=\array_search($fieldName, $fields);
83 83
 		}
84 84
 		return $index;
85 85
 	}
86 86
 
87
-	protected function _getFieldIdentifier($prefix,$name=""){
87
+	protected function _getFieldIdentifier($prefix, $name="") {
88 88
 		return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier();
89 89
 	}
90 90
 
91
-	protected function _getFieldName($index){
91
+	protected function _getFieldName($index) {
92 92
 		return $this->_instanceViewer->getFieldName($index);
93 93
 	}
94 94
 
95
-	protected function _getFieldCaption($index){
95
+	protected function _getFieldCaption($index) {
96 96
 		return $this->_instanceViewer->getCaption($index);
97 97
 	}
98 98
 
99
-	abstract protected  function _setToolbarPosition($table,$captions=NULL);
99
+	abstract protected  function _setToolbarPosition($table, $captions=NULL);
100 100
 
101
-	public function show($modelInstance){
102
-		if(\is_array($modelInstance)){
101
+	public function show($modelInstance) {
102
+		if (\is_array($modelInstance)) {
103 103
 			$modelInstance=\json_decode(\json_encode($modelInstance), FALSE);
104 104
 		}
105 105
 		$this->_modelInstance=$modelInstance;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 	abstract public function getHtmlComponent();
127 127
 
128
-	public function setAttached($value=true){
128
+	public function setAttached($value=true) {
129 129
 		return $this->getHtmlComponent()->setAttached($value);
130 130
 	}
131 131
 
@@ -136,71 +136,71 @@  discard block
 block discarded – undo
136 136
 	 * @param callable $callback function called after the field compilation
137 137
 	 * @return Widget
138 138
 	 */
139
-	public function afterCompile($index,$callback){
139
+	public function afterCompile($index, $callback) {
140 140
 		$index=$this->_getIndex($index);
141 141
 		$this->_instanceViewer->afterCompile($index, $callback);
142 142
 		return $this;
143 143
 	}
144 144
 
145
-	public function setColor($color){
145
+	public function setColor($color) {
146 146
 		return $this->getHtmlComponent()->setColor($color);
147 147
 	}
148 148
 
149 149
 
150
-	public function setCaptions($captions){
150
+	public function setCaptions($captions) {
151 151
 		$this->_instanceViewer->setCaptions($captions);
152 152
 		return $this;
153 153
 	}
154 154
 
155
-	public function setCaption($index,$caption){
155
+	public function setCaption($index, $caption) {
156 156
 		$this->_instanceViewer->setCaption($this->_getIndex($index), $caption);
157 157
 		return $this;
158 158
 	}
159 159
 
160
-	public function setFields($fields){
160
+	public function setFields($fields) {
161 161
 		$this->_instanceViewer->setVisibleProperties($fields);
162 162
 		return $this;
163 163
 	}
164 164
 
165
-	public function addField($field){
165
+	public function addField($field) {
166 166
 		$this->_instanceViewer->addField($field);
167 167
 		return $this;
168 168
 	}
169 169
 
170
-	public function addFields($fields){
170
+	public function addFields($fields) {
171 171
 		$this->_instanceViewer->addFields($fields);
172 172
 		return $this;
173 173
 	}
174 174
 
175
-	public function addMessage($attributes=NULL,$fieldName="message"){
175
+	public function addMessage($attributes=NULL, $fieldName="message") {
176 176
 		$this->_instanceViewer->addField($fieldName);
177 177
 		$count=$this->_instanceViewer->visiblePropertiesCount();
178
-		return $this->fieldAsMessage($count-1,$attributes);
178
+		return $this->fieldAsMessage($count-1, $attributes);
179 179
 	}
180 180
 
181
-	public function addErrorMessage(){
182
-		return $this->addMessage(["error"=>true],"message");
181
+	public function addErrorMessage() {
182
+		return $this->addMessage(["error"=>true], "message");
183 183
 	}
184 184
 
185
-	public function insertField($index,$field){
185
+	public function insertField($index, $field) {
186 186
 		$index=$this->_getIndex($index);
187 187
 		$this->_instanceViewer->insertField($index, $field);
188 188
 		return $this;
189 189
 	}
190 190
 
191
-	public function insertInField($index,$field){
191
+	public function insertInField($index, $field) {
192 192
 		$index=$this->_getIndex($index);
193 193
 		$this->_instanceViewer->insertInField($index, $field);
194 194
 		return $this;
195 195
 	}
196 196
 
197
-	public function setValueFunction($index,$callback){
197
+	public function setValueFunction($index, $callback) {
198 198
 		$index=$this->_getIndex($index);
199 199
 		$this->_instanceViewer->setValueFunction($index, $callback);
200 200
 		return $this;
201 201
 	}
202 202
 
203
-	public function setIdentifierFunction($callback){
203
+	public function setIdentifierFunction($callback) {
204 204
 		$this->_instanceViewer->setIdentifierFunction($callback);
205 205
 		return $this;
206 206
 	}
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	/**
209 209
 	 * @return \Ajax\semantic\html\collections\menus\HtmlMenu
210 210
 	 */
211
-	public function getToolbar(){
212
-		if(isset($this->_toolbar)===false){
211
+	public function getToolbar() {
212
+		if (isset($this->_toolbar)===false) {
213 213
 			$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier);
214 214
 		}
215 215
 		return $this->_toolbar;
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
 	 * @param callable $callback function to call on $element
222 222
 	 * @return \Ajax\common\html\HtmlDoubleElement
223 223
 	 */
224
-	public function addInToolbar($element,$callback=NULL){
224
+	public function addInToolbar($element, $callback=NULL) {
225 225
 		$tb=$this->getToolbar();
226
-		if($element instanceof BaseWidget){
227
-			if($element->getIdentifier()===""){
226
+		if ($element instanceof BaseWidget) {
227
+			if ($element->getIdentifier()==="") {
228 228
 				$element->setIdentifier("tb-item-".$this->identifier."-".$tb->count());
229 229
 			}
230 230
 		}
231
-		if(isset($callback)){
232
-			if(\is_callable($callback)){
231
+		if (isset($callback)) {
232
+			if (\is_callable($callback)) {
233 233
 				$callback($element);
234 234
 			}
235 235
 		}
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 	 * @param callable $callback function($element)
243 243
 	 * @return \Ajax\common\html\HtmlDoubleElement
244 244
 	 */
245
-	public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){
246
-		$result=$this->addInToolbar($caption,$callback);
247
-		if(isset($icon))
245
+	public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) {
246
+		$result=$this->addInToolbar($caption, $callback);
247
+		if (isset($icon))
248 248
 			$result->addIcon($icon);
249 249
 		return $result;
250 250
 	}
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
 	 * @param callable $callback function($element)
255 255
 	 * @return \Ajax\common\Widget
256 256
 	 */
257
-	public function addItemsInToolbar(array $items,$callback=NULL){
258
-		if(JArray::isAssociative($items)){
259
-			foreach ($items as $icon=>$item){
260
-				$this->addItemInToolbar($item,$icon,$callback);
257
+	public function addItemsInToolbar(array $items, $callback=NULL) {
258
+		if (JArray::isAssociative($items)) {
259
+			foreach ($items as $icon=>$item) {
260
+				$this->addItemInToolbar($item, $icon, $callback);
261 261
 			}
262
-		}else{
263
-			foreach ($items as $item){
264
-				$this->addItemInToolbar($item,null,$callback);
262
+		} else {
263
+			foreach ($items as $item) {
264
+				$this->addItemInToolbar($item, null, $callback);
265 265
 			}
266 266
 		}
267 267
 		return $this;
@@ -273,12 +273,12 @@  discard block
 block discarded – undo
273 273
 	 * @param callable $callback function($element)
274 274
 	 * @return \Ajax\common\html\HtmlDoubleElement
275 275
 	 */
276
-	public function addDropdownInToolbar($value,$items,$callback=NULL){
276
+	public function addDropdownInToolbar($value, $items, $callback=NULL) {
277 277
 		$dd=$value;
278 278
 		if (\is_string($value)) {
279
-			$dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items);
279
+			$dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items);
280 280
 		}
281
-		return $this->addInToolbar($dd,$callback);
281
+		return $this->addInToolbar($dd, $callback);
282 282
 	}
283 283
 
284 284
 	/**
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 	 * @param callable $callback function($element)
288 288
 	 * @return \Ajax\common\html\HtmlDoubleElement
289 289
 	 */
290
-	public function addButtonInToolbar($caption,$cssStyle=null,$callback=NULL){
291
-		$bt=new HtmlButton("bt-".$caption,$caption,$cssStyle);
292
-		return $this->addInToolbar($bt,$callback);
290
+	public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) {
291
+		$bt=new HtmlButton("bt-".$caption, $caption, $cssStyle);
292
+		return $this->addInToolbar($bt, $callback);
293 293
 	}
294 294
 
295 295
 	/**
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 	 * @param callable $callback function($element)
299 299
 	 * @return \Ajax\common\html\HtmlDoubleElement
300 300
 	 */
301
-	public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){
302
-		$bts=new HtmlButtonGroups("",$captions,$asIcon);
303
-		return $this->addInToolbar($bts,$callback);
301
+	public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) {
302
+		$bts=new HtmlButtonGroups("", $captions, $asIcon);
303
+		return $this->addInToolbar($bts, $callback);
304 304
 	}
305 305
 
306 306
 	/**
@@ -310,15 +310,15 @@  discard block
 block discarded – undo
310 310
 	 * @param boolean $labeled
311 311
 	 * @return \Ajax\common\html\HtmlDoubleElement
312 312
 	 */
313
-	public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){
314
-		$bt=new HtmlButton("",$caption);
315
-		$bt->addIcon($icon,$before,$labeled);
313
+	public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) {
314
+		$bt=new HtmlButton("", $caption);
315
+		$bt->addIcon($icon, $before, $labeled);
316 316
 		return $this->addInToolbar($bt);
317 317
 	}
318 318
 
319
-	public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){
320
-		$button=new HtmlButton($identifier,$value,$cssStyle);
321
-		$this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters);
319
+	public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) {
320
+		$button=new HtmlButton($identifier, $value, $cssStyle);
321
+		$this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters);
322 322
 		return $this->addInToolbar($button);
323 323
 	}
324 324
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	 * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model
349 349
 	 * @return \Ajax\common\Widget
350 350
 	 */
351
-	public function setDefaultValueFunction($defaultValueFunction){
351
+	public function setDefaultValueFunction($defaultValueFunction) {
352 352
 		$this->_instanceViewer->setDefaultValueFunction($defaultValueFunction);
353 353
 		return $this;
354 354
 	}
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 	 * @param string|boolean $disable
358 358
 	 * @return string
359 359
 	 */
360
-	public function jsDisabled($disable=true){
360
+	public function jsDisabled($disable=true) {
361 361
 		return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");";
362 362
 	}
363 363
 
@@ -366,12 +366,12 @@  discard block
 block discarded – undo
366 366
 	 * @param callable $callback function($element)
367 367
 	 * @return \Ajax\common\html\HtmlDoubleElement
368 368
 	 */
369
-	public function addEditButtonInToolbar($caption,$callback=NULL){
370
-		$bt=new HtmlButton($this->identifier."-editBtn",$caption);
369
+	public function addEditButtonInToolbar($caption, $callback=NULL) {
370
+		$bt=new HtmlButton($this->identifier."-editBtn", $caption);
371 371
 		$bt->setToggle();
372 372
 		$bt->setActive($this->_edition);
373 373
 		$bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')")));
374
-		return $this->addInToolbar($bt,$callback);
374
+		return $this->addInToolbar($bt, $callback);
375 375
 	}
376 376
 
377 377
 	public function setToolbar(HtmlMenu $_toolbar) {
@@ -385,35 +385,35 @@  discard block
 block discarded – undo
385 385
 	}
386 386
 
387 387
 	public function getForm() {
388
-		if(!isset($this->_form)){
388
+		if (!isset($this->_form)) {
389 389
 			$this->_form=new HtmlForm("frm-".$this->identifier);
390 390
 			$this->setEdition(true);
391 391
 		}
392 392
 		return $this->_form;
393 393
 	}
394 394
 
395
-	public function run(JsUtils $js){
395
+	public function run(JsUtils $js) {
396 396
 		$result=parent::run($js);
397
-		if(isset($this->_form)){
397
+		if (isset($this->_form)) {
398 398
 			$result=$this->runForm($js);
399 399
 		}
400 400
 		return $result;
401 401
 	}
402 402
 
403
-	protected function runForm(JsUtils $js){
403
+	protected function runForm(JsUtils $js) {
404 404
 		$fields=$this->getContentInstances(HtmlFormField::class);
405
-		foreach ($fields as $field){
405
+		foreach ($fields as $field) {
406 406
 			$this->_form->addField($field);
407 407
 		}
408 408
 		return $this->_form->run($js);
409 409
 	}
410 410
 
411
-	protected function _compileForm(){
412
-		if(isset($this->_form)){
411
+	protected function _compileForm() {
412
+		if (isset($this->_form)) {
413 413
 			$noValidate="";
414
-			if(\sizeof($this->_form->getValidationParams())>0)
414
+			if (\sizeof($this->_form->getValidationParams())>0)
415 415
 				$noValidate="novalidate";
416
-			$this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>");
416
+			$this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>");
417 417
 		}
418 418
 	}
419 419
 
@@ -422,32 +422,32 @@  discard block
 block discarded – undo
422 422
 		return $this;
423 423
 	}
424 424
 
425
-	public function moveFieldTo($from,$to){
425
+	public function moveFieldTo($from, $to) {
426 426
 		return $this->_instanceViewer->moveFieldTo($from, $to);
427 427
 	}
428 428
 
429
-	public function swapFields($index1,$index2){
429
+	public function swapFields($index1, $index2) {
430 430
 		$index1=$this->_getIndex($index1);
431 431
 		$index2=$this->_getIndex($index2);
432 432
 		return $this->_instanceViewer->swapFields($index1, $index2);
433 433
 	}
434 434
 
435
-	public function removeField($index){
435
+	public function removeField($index) {
436 436
 		$index=$this->_getIndex($index);
437 437
 		$this->_instanceViewer->removeField($index);
438 438
 		return $this;
439 439
 	}
440 440
 
441
-	public function asModal($header=null){
442
-		$modal=new HtmlModal("modal-".$this->identifier,$header);
441
+	public function asModal($header=null) {
442
+		$modal=new HtmlModal("modal-".$this->identifier, $header);
443 443
 		$modal->setContent($this);
444
-		if(isset($this->_form)){
444
+		if (isset($this->_form)) {
445 445
 			$this->_form->onSuccess($modal->jsHide());
446 446
 		}
447 447
 		return $modal;
448 448
 	}
449 449
 
450 450
 	public function addToProperty($name, $value, $separator=" ") {
451
-		return $this->getHtmlComponent()->addToProperty($name,$value,$separator);
451
+		return $this->getHtmlComponent()->addToProperty($name, $value, $separator);
452 452
 	}
453 453
 }
Please login to merge, or discard this patch.