Completed
Push — master ( 2b1feb...63bca8 )
by Jean-Christophe
03:46
created
Ajax/semantic/widgets/datatable/PositionInTable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,5 +3,5 @@
 block discarded – undo
3 3
 use Ajax\common\BaseEnum;
4 4
 
5 5
 abstract class PositionInTable extends BaseEnum {
6
-	const BEFORETABLE="beforeTable",AFTERTABLE="afterTable",HEADER="thead",FOOTER="tfoot",BODY="tbody";
6
+	const BEFORETABLE="beforeTable", AFTERTABLE="afterTable", HEADER="thead", FOOTER="tfoot", BODY="tbody";
7 7
 }
Please login to merge, or discard this patch.
Ajax/semantic/widgets/datatable/DataTable.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  *
25 25
  */
26 26
 class DataTable extends Widget {
27
-	use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait;
27
+	use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait, BaseTrait;
28 28
 	protected $_searchField;
29 29
 	protected $_urls;
30 30
 	protected $_pagination;
@@ -42,35 +42,35 @@  discard block
 block discarded – undo
42 42
 	protected $_colWidths;
43 43
 
44 44
 
45
-	public function __construct($identifier,$model,$modelInstance=NULL) {
46
-		parent::__construct($identifier, $model,$modelInstance);
47
-		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false);
45
+	public function __construct($identifier, $model, $modelInstance=NULL) {
46
+		parent::__construct($identifier, $model, $modelInstance);
47
+		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false);
48 48
 		$this->_urls=[];
49
-		$this->_emptyMessage=new HtmlMessage("","nothing to display");
49
+		$this->_emptyMessage=new HtmlMessage("", "nothing to display");
50 50
 		$this->_emptyMessage->setIcon("info circle");
51 51
 	}
52 52
 
53
-	public function run(JsUtils $js){
54
-		if($this->_hasCheckboxes && isset($js)){
53
+	public function run(JsUtils $js) {
54
+		if ($this->_hasCheckboxes && isset($js)) {
55 55
 			$this->_runCheckboxes($js);
56 56
 		}
57
-		if($this->_visibleHover){
58
-			$js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]);
59
-			$js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]);
57
+		if ($this->_visibleHover) {
58
+			$js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]);
59
+			$js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]);
60 60
 		}
61
-		if(\is_array($this->_deleteBehavior))
62
-			$this->_generateBehavior("delete",$this->_deleteBehavior, $js);
63
-		if(\is_array($this->_editBehavior))
64
-			$this->_generateBehavior("edit",$this->_editBehavior,$js);
61
+		if (\is_array($this->_deleteBehavior))
62
+			$this->_generateBehavior("delete", $this->_deleteBehavior, $js);
63
+		if (\is_array($this->_editBehavior))
64
+			$this->_generateBehavior("edit", $this->_editBehavior, $js);
65 65
 		return parent::run($js);
66 66
 	}
67 67
 
68 68
 
69 69
 
70
-	protected function _generateBehavior($op,$params,JsUtils $js){
71
-		if(isset($this->_urls[$op])){
72
-			$params=\array_merge($params,["attr"=>"data-ajax"]);
73
-			$js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params);
70
+	protected function _generateBehavior($op, $params, JsUtils $js) {
71
+		if (isset($this->_urls[$op])) {
72
+			$params=\array_merge($params, ["attr"=>"data-ajax"]);
73
+			$js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params);
74 74
 		}
75 75
 	}
76 76
 
@@ -83,154 +83,154 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 
85 85
 
86
-	public function compile(JsUtils $js=NULL,&$view=NULL){
87
-		if(!$this->_generated){
86
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
87
+		if (!$this->_generated) {
88 88
 			$this->_instanceViewer->setInstance($this->_model);
89 89
 			$captions=$this->_instanceViewer->getCaptions();
90 90
 			$table=$this->content["table"];
91
-			if($this->_hasCheckboxes){
91
+			if ($this->_hasCheckboxes) {
92 92
 				$this->_generateMainCheckbox($captions);
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
 			$this->_applyStyleAttributes($table);
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 _applyStyleAttributes($table){
127
-		if(isset($this->_hiddenColumns))
126
+	protected function _applyStyleAttributes($table) {
127
+		if (isset($this->_hiddenColumns))
128 128
 			$this->_hideColumns();
129
-			if(isset($this->_colWidths)){
130
-				foreach ($this->_colWidths as $colIndex=>$width){
131
-					$table->setColWidth($colIndex,$width);
129
+			if (isset($this->_colWidths)) {
130
+				foreach ($this->_colWidths as $colIndex=>$width) {
131
+					$table->setColWidth($colIndex, $width);
132 132
 				}
133 133
 			}
134 134
 	}
135 135
 
136
-	protected function _hideColumns(){
137
-		foreach ($this->_hiddenColumns as $colIndex){
136
+	protected function _hideColumns() {
137
+		foreach ($this->_hiddenColumns as $colIndex) {
138 138
 			$this->_self->hideColumn($colIndex);
139 139
 		}
140 140
 		return $this;
141 141
 	}
142 142
 
143
-	protected function _generateHeader(HtmlTable $table,$captions){
143
+	protected function _generateHeader(HtmlTable $table, $captions) {
144 144
 		$table->setHeaderValues($captions);
145
-		if(isset($this->_sortable)){
145
+		if (isset($this->_sortable)) {
146 146
 			$table->setSortable($this->_sortable);
147 147
 		}
148 148
 	}
149 149
 
150 150
 
151 151
 
152
-	protected function _generateContent($table){
152
+	protected function _generateContent($table) {
153 153
 		$objects=$this->_modelInstance;
154
-		if(isset($this->_pagination)){
154
+		if (isset($this->_pagination)) {
155 155
 			$objects=$this->_pagination->getObjects($this->_modelInstance);
156 156
 		}
157 157
 			InstanceViewer::setIndex(0);
158 158
 			$table->fromDatabaseObjects($objects, function($instance) use($table){
159 159
 				return $this->_generateRow($instance, $table);
160 160
 			});
161
-		if($table->getRowCount()==0){
161
+		if ($table->getRowCount()==0) {
162 162
 			$result=$table->addRow();
163 163
 			$result->mergeRow();
164 164
 			$result->setValues([$this->_emptyMessage]);
165 165
 		}
166 166
 	}
167 167
 
168
-	protected function _generateRow($instance,&$table,$checkedClass=null){
168
+	protected function _generateRow($instance, &$table, $checkedClass=null) {
169 169
 		$this->_instanceViewer->setInstance($instance);
170 170
 		InstanceViewer::$index++;
171
-		$values= $this->_instanceViewer->getValues();
171
+		$values=$this->_instanceViewer->getValues();
172 172
 		$id=$this->_instanceViewer->getIdentifier();
173
-		if($this->_hasCheckboxes){
174
-			$ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,"");
173
+		if ($this->_hasCheckboxes) {
174
+			$ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, "");
175 175
 			$ck->setOnChange("event.stopPropagation();");
176 176
 			$field=$ck->getField();
177
-			$field->setProperty("value",$id);
177
+			$field->setProperty("value", $id);
178 178
 			$field->setProperty("name", "selection[]");
179
-			if(isset($checkedClass))
179
+			if (isset($checkedClass))
180 180
 				$field->setClass($checkedClass);
181 181
 			\array_unshift($values, $ck);
182 182
 		}
183 183
 		$result=$table->newRow();
184 184
 		$result->setIdentifier($this->identifier."-tr-".$id);
185
-		$result->setProperty("data-ajax",$id);
185
+		$result->setProperty("data-ajax", $id);
186 186
 		$result->setValues($values);
187
-		$result->addToProperty("class",$this->_rowClass);
187
+		$result->addToProperty("class", $this->_rowClass);
188 188
 		return $result;
189 189
 	}
190 190
 
191
-	protected function _generatePagination($table,$js=NULL){
192
-		if(isset($this->_toolbar)){
193
-			if($this->_toolbarPosition==PositionInTable::FOOTER)
191
+	protected function _generatePagination($table, $js=NULL) {
192
+		if (isset($this->_toolbar)) {
193
+			if ($this->_toolbarPosition==PositionInTable::FOOTER)
194 194
 				$this->_toolbar->setFloated("left");
195 195
 		}
196 196
 		$footer=$table->getFooter();
197 197
 		$footer->mergeCol();
198
-		$menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers());
198
+		$menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers());
199 199
 		$menu->floatRight();
200 200
 		$menu->setActiveItem($this->_pagination->getPage()-1);
201 201
 		$footer->addValues($menu);
202
-		$this->_associatePaginationBehavior($menu,$js);
202
+		$this->_associatePaginationBehavior($menu, $js);
203 203
 	}
204 204
 
205
-	protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){
206
-		if(isset($this->_urls["refresh"])){
207
-			$menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith"]);
205
+	protected function _associatePaginationBehavior(HtmlMenu $menu, JsUtils $js=NULL) {
206
+		if (isset($this->_urls["refresh"])) {
207
+			$menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]);
208 208
 		}
209 209
 	}
210 210
 
211
-	protected function _getFieldName($index){
211
+	protected function _getFieldName($index) {
212 212
 		$fieldName=parent::_getFieldName($index);
213
-		if(\is_object($fieldName))
213
+		if (\is_object($fieldName))
214 214
 			$fieldName="field-".$index;
215 215
 		return $fieldName."[]";
216 216
 	}
217 217
 
218
-	protected function _getFieldCaption($index){
218
+	protected function _getFieldCaption($index) {
219 219
 		return null;
220 220
 	}
221 221
 
222
-	protected function _setToolbarPosition($table,$captions=NULL){
223
-		switch ($this->_toolbarPosition){
222
+	protected function _setToolbarPosition($table, $captions=NULL) {
223
+		switch ($this->_toolbarPosition) {
224 224
 			case PositionInTable::BEFORETABLE:
225 225
 			case PositionInTable::AFTERTABLE:
226
-				if(isset($this->_compileParts)===false){
226
+				if (isset($this->_compileParts)===false) {
227 227
 					$this->content[$this->_toolbarPosition]=$this->_toolbar;
228 228
 				}
229 229
 				break;
230 230
 			case PositionInTable::HEADER:
231 231
 			case PositionInTable::FOOTER:
232 232
 			case PositionInTable::BODY:
233
-				$this->addToolbarRow($this->_toolbarPosition,$table, $captions);
233
+				$this->addToolbarRow($this->_toolbarPosition, $table, $captions);
234 234
 				break;
235 235
 		}
236 236
 	}
@@ -242,16 +242,16 @@  discard block
 block discarded – undo
242 242
 	 * @param callable $callback function called after the field compilation
243 243
 	 * @return DataTable
244 244
 	 */
245
-	public function afterCompile($index,$callback){
246
-		$this->_instanceViewer->afterCompile($index,$callback);
245
+	public function afterCompile($index, $callback) {
246
+		$this->_instanceViewer->afterCompile($index, $callback);
247 247
 		return $this;
248 248
 	}
249 249
 
250
-	private function addToolbarRow($part,$table,$captions){
250
+	private function addToolbarRow($part, $table, $captions) {
251 251
 		$hasPart=$table->hasPart($part);
252
-		if($hasPart){
252
+		if ($hasPart) {
253 253
 			$row=$table->getPart($part)->addRow(\sizeof($captions));
254
-		}else{
254
+		} else {
255 255
 			$row=$table->getPart($part)->getRow(0);
256 256
 		}
257 257
 		$row->mergeCol();
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 	 * @see Widget::getHtmlComponent()
264 264
 	 * @return HtmlTable
265 265
 	 */
266
-	public function getHtmlComponent(){
266
+	public function getHtmlComponent() {
267 267
 		return $this->content["table"];
268 268
 	}
269 269
 
@@ -277,12 +277,12 @@  discard block
 block discarded – undo
277 277
 	 * @return DataTable
278 278
 	 */
279 279
 	public function setUrls($urls) {
280
-		if(\is_array($urls)){
281
-			$this->_urls["refresh"]=JArray::getValue($urls, "refresh",0);
282
-			$this->_urls["edit"]=JArray::getValue($urls, "edit",1);
283
-			$this->_urls["delete"]=JArray::getValue($urls, "delete",2);
284
-		}else{
285
-			$this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls];
280
+		if (\is_array($urls)) {
281
+			$this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0);
282
+			$this->_urls["edit"]=JArray::getValue($urls, "edit", 1);
283
+			$this->_urls["delete"]=JArray::getValue($urls, "delete", 2);
284
+		} else {
285
+			$this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls];
286 286
 		}
287 287
 		return $this;
288 288
 	}
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param number $pages_visibles The number of visible pages in the Pagination component
296 296
 	 * @return DataTable
297 297
 	 */
298
-	public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){
299
-		$this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount);
298
+	public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) {
299
+		$this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount);
300 300
 		return $this;
301 301
 	}
302 302
 
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
 	 * @param number $pages_visibles The number of visible pages in the Pagination component
308 308
 	 * @return DataTable
309 309
 	 */
310
-	public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){
311
-		$this->_pagination=new Pagination($items_per_page,$pages_visibles,$page);
310
+	public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) {
311
+		$this->_pagination=new Pagination($items_per_page, $pages_visibles, $page);
312 312
 		return $this;
313 313
 	}
314 314
 
@@ -318,20 +318,20 @@  discard block
 block discarded – undo
318 318
 	 * @param array $compileParts
319 319
 	 * @return DataTable
320 320
 	 */
321
-	public function refresh($compileParts=["tbody"]){
321
+	public function refresh($compileParts=["tbody"]) {
322 322
 		$this->_compileParts=$compileParts;
323 323
 		return $this;
324 324
 	}
325 325
 
326 326
 
327
-	public function addSearchInToolbar($position=Direction::RIGHT){
327
+	public function addSearchInToolbar($position=Direction::RIGHT) {
328 328
 		return $this->addInToolbar($this->getSearchField())->setPosition($position);
329 329
 	}
330 330
 
331
-	public function getSearchField(){
332
-		if(isset($this->_searchField)===false){
333
-			$this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search...");
334
-			$this->_searchField->addIcon("search",Direction::RIGHT);
331
+	public function getSearchField() {
332
+		if (isset($this->_searchField)===false) {
333
+			$this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search...");
334
+			$this->_searchField->addIcon("search", Direction::RIGHT);
335 335
 		}
336 336
 		return $this->_searchField;
337 337
 	}
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		return $this;
348 348
 	}
349 349
 
350
-	public function asForm(){
350
+	public function asForm() {
351 351
 		return $this->getForm();
352 352
 	}
353 353
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 
356 356
 	protected function getTargetSelector() {
357 357
 		$result=$this->_targetSelector;
358
-		if(!isset($result))
358
+		if (!isset($result))
359 359
 			$result="#".$this->identifier;
360 360
 		return $result;
361 361
 	}
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 	}
372 372
 
373 373
 	public function getRefreshSelector() {
374
-		if(isset($this->_refreshSelector))
374
+		if (isset($this->_refreshSelector))
375 375
 			return $this->_refreshSelector;
376 376
 		return "#".$this->identifier." tbody";
377 377
 	}
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
 	 * {@inheritDoc}
390 390
 	 * @see \Ajax\common\Widget::show()
391 391
 	 */
392
-	public function show($modelInstance){
393
-		if(\is_array($modelInstance)){
394
-			if(\is_array(array_values($modelInstance)[0]))
392
+	public function show($modelInstance) {
393
+		if (\is_array($modelInstance)) {
394
+			if (\is_array(array_values($modelInstance)[0]))
395 395
 				$modelInstance=\json_decode(\json_encode($modelInstance), FALSE);
396 396
 		}
397 397
 		$this->_modelInstance=$modelInstance;
@@ -426,24 +426,24 @@  discard block
 block discarded – undo
426 426
 		return $this;
427 427
 	}
428 428
 
429
-	public function setActiveRowSelector($class="active",$event="click",$multiple=false){
430
-		$this->_self->setActiveRowSelector($class,$event,$multiple);
429
+	public function setActiveRowSelector($class="active", $event="click", $multiple=false) {
430
+		$this->_self->setActiveRowSelector($class, $event, $multiple);
431 431
 		return $this;
432 432
 	}
433 433
 
434
-	public function hideColumn($colIndex){
435
-		if(!\is_array($this->_hiddenColumns))
434
+	public function hideColumn($colIndex) {
435
+		if (!\is_array($this->_hiddenColumns))
436 436
 			$this->_hiddenColumns=[];
437 437
 		$this->_hiddenColumns[]=$colIndex;
438 438
 		return $this;
439 439
 	}
440 440
 
441
-	public function setColWidth($colIndex,$width){
441
+	public function setColWidth($colIndex, $width) {
442 442
 		$this->_colWidths[$colIndex]=$width;
443 443
 		return $this;
444 444
 	}
445 445
 	public function setColWidths($_colWidths) {
446
-		$this->_colWidths = $_colWidths;
446
+		$this->_colWidths=$_colWidths;
447 447
 		return $this;
448 448
 	}
449 449
 }
Please login to merge, or discard this patch.
Ajax/semantic/widgets/datatable/DataTableFieldAsTrait.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -12,19 +12,19 @@  discard block
 block discarded – undo
12 12
  * @property boolean $_visibleHover
13 13
  * @property InstanceViewer $_instanceViewer
14 14
  */
15
-trait DataTableFieldAsTrait{
15
+trait DataTableFieldAsTrait {
16 16
 	abstract public function addField($field);
17
-	abstract public function insertField($index,$field);
18
-	abstract public function insertInField($index,$field);
19
-	abstract public function fieldAs($index,$type,$attributes=NULL);
17
+	abstract public function insertField($index, $field);
18
+	abstract public function insertInField($index, $field);
19
+	abstract public function fieldAs($index, $type, $attributes=NULL);
20 20
 	/**
21 21
 	 * @param string $caption
22 22
 	 * @param callable $callback
23 23
 	 * @param boolean $visibleHover
24 24
 	 * @return callable
25 25
 	 */
26
-	private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){
27
-		return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback);
26
+	private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) {
27
+		return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback);
28 28
 	}
29 29
 
30 30
 	/**
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
 	 * @param callable $callback
34 34
 	 * @return callable
35 35
 	 */
36
-	private function getCallable($thisCallback,$parameters,$callback=null){
37
-		$result=function($instance) use($thisCallback,$parameters,$callback){
38
-			$object=call_user_func_array(array($this,$thisCallback), $parameters);
39
-			if(isset($callback)){
40
-				if(\is_callable($callback)){
41
-					$callback($object,$instance);
36
+	private function getCallable($thisCallback, $parameters, $callback=null) {
37
+		$result=function($instance) use($thisCallback, $parameters, $callback){
38
+			$object=call_user_func_array(array($this, $thisCallback), $parameters);
39
+			if (isset($callback)) {
40
+				if (\is_callable($callback)) {
41
+					$callback($object, $instance);
42 42
 				}
43 43
 			}
44
-			if($object instanceof HtmlSemDoubleElement){
45
-				$object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier());
46
-				if($object->propertyContains("class","visibleover")){
44
+			if ($object instanceof HtmlSemDoubleElement) {
45
+				$object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier());
46
+				if ($object->propertyContains("class", "visibleover")) {
47 47
 					$this->_visibleHover=true;
48
-					$object->setProperty("style","visibility:hidden;");
48
+					$object->setProperty("style", "visibility:hidden;");
49 49
 				}
50 50
 			}
51 51
 			return $object;
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * @param string $caption
58 58
 	 * @return HtmlButton
59 59
 	 */
60
-	private function getFieldButton($caption,$visibleHover=true){
61
-		$bt= new HtmlButton("",$caption);
62
-		if($visibleHover)
60
+	private function getFieldButton($caption, $visibleHover=true) {
61
+		$bt=new HtmlButton("", $caption);
62
+		if ($visibleHover)
63 63
 			$this->_visibleOver($bt);
64 64
 			return $bt;
65 65
 	}
@@ -73,19 +73,19 @@  discard block
 block discarded – undo
73 73
 	 * @param array $attributes associative array (<b>ajax</b> key is for ajax post)
74 74
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
75 75
 	 */
76
-	public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){
77
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){
78
-			$button=new HtmlButton($id,$value,$cssStyle);
79
-			$button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]);
80
-			if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"])
76
+	public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) {
77
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $index, $attributes){
78
+			$button=new HtmlButton($id, $value, $cssStyle);
79
+			$button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]);
80
+			if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"])
81 81
 				$this->_visibleOver($button);
82 82
 				return $button;
83
-		}, $index,$attributes);
83
+		}, $index, $attributes);
84 84
 	}
85 85
 
86
-	protected function _visibleOver($element){
86
+	protected function _visibleOver($element) {
87 87
 		$this->_visibleHover=true;
88
-		return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;");
88
+		return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;");
89 89
 	}
90 90
 
91 91
 	/**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	 * @param boolean $visibleHover
96 96
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
97 97
 	 */
98
-	public function addFieldButton($caption,$visibleHover=true,$callback=null){
99
-		$this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback));
98
+	public function addFieldButton($caption, $visibleHover=true, $callback=null) {
99
+		$this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback));
100 100
 		return $this;
101 101
 	}
102 102
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	 * @param callable $callback
108 108
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
109 109
 	 */
110
-	public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){
111
-		$this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback));
110
+	public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) {
111
+		$this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback));
112 112
 		return $this;
113 113
 	}
114 114
 
@@ -119,25 +119,25 @@  discard block
 block discarded – undo
119 119
 	 * @param callable $callback
120 120
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
121 121
 	 */
122
-	public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){
123
-		$this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback));
122
+	public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) {
123
+		$this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback));
124 124
 		return $this;
125 125
 	}
126 126
 
127
-	private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){
128
-		$this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback));
127
+	private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) {
128
+		$this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback));
129 129
 		return $this;
130 130
 	}
131 131
 
132
-	private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){
133
-		$this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback));
132
+	private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) {
133
+		$this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback));
134 134
 		return $this;
135 135
 	}
136 136
 
137
-	private function getDefaultButton($icon,$class=null,$visibleHover=true){
138
-		$bt=$this->getFieldButton("",$visibleHover);
137
+	private function getDefaultButton($icon, $class=null, $visibleHover=true) {
138
+		$bt=$this->getFieldButton("", $visibleHover);
139 139
 		$bt->asIcon($icon);
140
-		if(isset($class))
140
+		if (isset($class))
141 141
 			$bt->addClass($class);
142 142
 		return $bt;
143 143
 	}
@@ -148,30 +148,30 @@  discard block
 block discarded – undo
148 148
 	 * @param callable $callback
149 149
 	 * @return DataTable
150 150
 	 */
151
-	public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){
151
+	public function addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null) {
152 152
 		$this->_deleteBehavior=$deleteBehavior;
153
-		return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback);
153
+		return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback);
154 154
 	}
155 155
 
156
-	public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){
156
+	public function addEditButton($visibleHover=true, $editBehavior=[], $callback=null) {
157 157
 		$this->_editBehavior=$editBehavior;
158
-		return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback);
158
+		return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback);
159 159
 	}
160 160
 
161
-	public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){
162
-		$this->addEditButton($visibleHover,$behavior,$callbackEdit);
161
+	public function addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null) {
162
+		$this->addEditButton($visibleHover, $behavior, $callbackEdit);
163 163
 		$index=$this->_instanceViewer->visiblePropertiesCount()-1;
164
-		$this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete);
164
+		$this->insertDeleteButtonIn($index, $visibleHover, $behavior, $callbackDelete);
165 165
 		return $this;
166 166
 	}
167 167
 
168
-	public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=[],$callback=null){
168
+	public function insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=[], $callback=null) {
169 169
 		$this->_deleteBehavior=$deleteBehavior;
170
-		return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback);
170
+		return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback);
171 171
 	}
172 172
 
173
-	public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){
173
+	public function insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null) {
174 174
 		$this->_editBehavior=$editBehavior;
175
-		return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback);
175
+		return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback);
176 176
 	}
177 177
 }
Please login to merge, or discard this patch.
Ajax/semantic/widgets/base/FieldAsTrait.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -27,23 +27,23 @@  discard block
 block discarded – undo
27 27
  * @property boolean $_edition
28 28
  * @property mixed _modelInstance
29 29
  */
30
-trait FieldAsTrait{
30
+trait FieldAsTrait {
31 31
 
32
-	abstract protected function _getFieldIdentifier($prefix,$name="");
33
-	abstract public function setValueFunction($index,$callback);
32
+	abstract protected function _getFieldIdentifier($prefix, $name="");
33
+	abstract public function setValueFunction($index, $callback);
34 34
 	abstract protected function _getFieldName($index);
35 35
 	abstract protected function _getFieldCaption($index);
36
-	abstract protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL);
36
+	abstract protected function _buttonAsSubmit(BaseHtml&$button, $event, $url, $responseElement=NULL, $parameters=NULL);
37 37
 
38 38
 	/**
39 39
 	 * @param HtmlFormField $element
40 40
 	 * @param array $attributes
41 41
 	 */
42
-	protected function _applyAttributes($element,&$attributes,$index){
43
-		if(isset($attributes["jsCallback"])){
42
+	protected function _applyAttributes($element, &$attributes, $index) {
43
+		if (isset($attributes["jsCallback"])) {
44 44
 			$callback=$attributes["jsCallback"];
45
-			if(\is_callable($callback)){
46
-				$callback($element,$this->_modelInstance,$index);
45
+			if (\is_callable($callback)) {
46
+				$callback($element, $this->_modelInstance, $index);
47 47
 				unset($attributes["jsCallback"]);
48 48
 			}
49 49
 		}
@@ -53,43 +53,43 @@  discard block
 block discarded – undo
53 53
 		$element->fromArray($attributes);
54 54
 	}
55 55
 
56
-	private function _getLabelField($caption,$icon=NULL){
57
-		$label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon);
56
+	private function _getLabelField($caption, $icon=NULL) {
57
+		$label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon);
58 58
 		return $label;
59 59
 	}
60 60
 
61 61
 
62
-	protected function _addRules($element,&$attributes){
63
-		if(isset($attributes["rules"])){
62
+	protected function _addRules($element, &$attributes) {
63
+		if (isset($attributes["rules"])) {
64 64
 			$rules=$attributes["rules"];
65
-			if(\is_array($rules)){
65
+			if (\is_array($rules)) {
66 66
 				$element->addRules($rules);
67 67
 			}
68
-			else{
68
+			else {
69 69
 				$element->addRule($rules);
70 70
 			}
71 71
 			unset($attributes["rules"]);
72 72
 		}
73 73
 	}
74 74
 
75
-	protected function _prepareFormFields(&$field,$name,&$attributes){
75
+	protected function _prepareFormFields(&$field, $name, &$attributes) {
76 76
 		$field->setName($name);
77 77
 		$this->_addRules($field, $attributes);
78 78
 		return $field;
79 79
 	}
80 80
 
81
-	protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){
82
-		$this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){
81
+	protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) {
82
+		$this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){
83 83
 			$caption=$this->_getFieldCaption($index);
84 84
 			$name=$this->_getFieldName($index);
85
-			$id=$this->_getFieldIdentifier($prefix,$name);
86
-			if(isset($attributes["name"])){
85
+			$id=$this->_getFieldIdentifier($prefix, $name);
86
+			if (isset($attributes["name"])) {
87 87
 				$name=$attributes["name"];
88 88
 				unset($attributes["name"]);
89 89
 			}
90
-			$element=$elementCallback($id,$name,$value,$caption);
91
-			if(\is_array($attributes)){
92
-				$this->_applyAttributes($element, $attributes,$index);
90
+			$element=$elementCallback($id, $name, $value, $caption);
91
+			if (\is_array($attributes)) {
92
+				$this->_applyAttributes($element, $attributes, $index);
93 93
 			}
94 94
 			$element->setDisabled(!$this->_edition);
95 95
 			return $element;
@@ -98,178 +98,178 @@  discard block
 block discarded – undo
98 98
 	}
99 99
 
100 100
 
101
-	public function fieldAsProgress($index,$label=NULL, $attributes=array()){
102
-		$this->setValueFunction($index,function($value) use($label,$attributes){
103
-			$pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes);
101
+	public function fieldAsProgress($index, $label=NULL, $attributes=array()) {
102
+		$this->setValueFunction($index, function($value) use($label, $attributes){
103
+			$pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes);
104 104
 			return $pb;
105 105
 		});
106 106
 			return $this;
107 107
 	}
108 108
 
109
-	public function fieldAsRating($index,$max=5, $icon=""){
110
-		$this->setValueFunction($index,function($value) use($max,$icon){
111
-			$rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon);
109
+	public function fieldAsRating($index, $max=5, $icon="") {
110
+		$this->setValueFunction($index, function($value) use($max, $icon){
111
+			$rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon);
112 112
 			return $rating;
113 113
 		});
114 114
 			return $this;
115 115
 	}
116 116
 
117
-	public function fieldAsLabel($index,$icon=NULL,$attributes=NULL){
118
-		return $this->_fieldAs(function($id,$name,$value) use($icon){
119
-			$lbl=new HtmlLabel($id,$value);
120
-			if(isset($icon))
117
+	public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) {
118
+		return $this->_fieldAs(function($id, $name, $value) use($icon){
119
+			$lbl=new HtmlLabel($id, $value);
120
+			if (isset($icon))
121 121
 				$lbl->addIcon($icon);
122 122
 				return $lbl;
123
-		}, $index,$attributes,"label");
123
+		}, $index, $attributes, "label");
124 124
 	}
125 125
 
126
-	public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){
127
-		return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){
128
-			$header=new HtmlHeader($id,$niveau,$value);
129
-			if(isset($icon))
126
+	public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) {
127
+		return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){
128
+			$header=new HtmlHeader($id, $niveau, $value);
129
+			if (isset($icon))
130 130
 				$header->asIcon($icon, $value);
131 131
 			return $header;
132
-		}, $index,$attributes,"header");
132
+		}, $index, $attributes, "header");
133 133
 	}
134 134
 
135 135
 
136
-	public function fieldAsImage($index,$size=Size::MINI,$circular=false){
137
-		$this->setValueFunction($index,function($img) use($size,$circular){
138
-			$image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular();
136
+	public function fieldAsImage($index, $size=Size::MINI, $circular=false) {
137
+		$this->setValueFunction($index, function($img) use($size, $circular){
138
+			$image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular();
139 139
 			return $image;
140 140
 		});
141 141
 			return $this;
142 142
 	}
143 143
 
144
-	public function fieldAsFlag($index){
145
-		$this->setValueFunction($index,function($flag){
146
-			$flag=new HtmlFlag($this->_getFieldIdentifier("flag"),$flag);
144
+	public function fieldAsFlag($index) {
145
+		$this->setValueFunction($index, function($flag) {
146
+			$flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag);
147 147
 			return $flag;
148 148
 		});
149 149
 			return $this;
150 150
 	}
151 151
 
152
-	public function fieldAsAvatar($index,$attributes=NULL){
153
-		return $this->_fieldAs(function($id,$name,$value){
154
-			$img=new HtmlImage($id,$value);
152
+	public function fieldAsAvatar($index, $attributes=NULL) {
153
+		return $this->_fieldAs(function($id, $name, $value) {
154
+			$img=new HtmlImage($id, $value);
155 155
 			$img->asAvatar();
156 156
 			return $img;
157
-		}, $index,$attributes,"avatar");
157
+		}, $index, $attributes, "avatar");
158 158
 	}
159 159
 
160
-	public function fieldAsRadio($index,$attributes=NULL){
161
-		return $this->_fieldAs(function($id,$name,$value) use($attributes){
162
-			$input= new HtmlRadio($id,$name,$value,$value);
160
+	public function fieldAsRadio($index, $attributes=NULL) {
161
+		return $this->_fieldAs(function($id, $name, $value) use($attributes){
162
+			$input=new HtmlRadio($id, $name, $value, $value);
163 163
 			return $this->_prepareFormFields($input, $name, $attributes);
164
-		}, $index,$attributes,"radio");
164
+		}, $index, $attributes, "radio");
165 165
 	}
166 166
 
167
-	public function fieldAsRadios($index,$elements=[],$attributes=NULL){
168
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){
169
-			return HtmlFormFields::radios($name,$elements,$caption,$value);
170
-		}, $index,$attributes,"radios");
167
+	public function fieldAsRadios($index, $elements=[], $attributes=NULL) {
168
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){
169
+			return HtmlFormFields::radios($name, $elements, $caption, $value);
170
+		}, $index, $attributes, "radios");
171 171
 	}
172 172
 
173
-	public function fieldAsInput($index,$attributes=NULL){
174
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){
175
-			$input= new HtmlFormInput($id,$caption,"text",$value);
173
+	public function fieldAsInput($index, $attributes=NULL) {
174
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){
175
+			$input=new HtmlFormInput($id, $caption, "text", $value);
176 176
 			return $this->_prepareFormFields($input, $name, $attributes);
177
-		}, $index,$attributes,"input");
177
+		}, $index, $attributes, "input");
178 178
 	}
179 179
 
180
-	public function fieldAsTextarea($index,$attributes=NULL){
181
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){
182
-			$textarea=new HtmlFormTextarea($id,$caption,$value);
180
+	public function fieldAsTextarea($index, $attributes=NULL) {
181
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){
182
+			$textarea=new HtmlFormTextarea($id, $caption, $value);
183 183
 			return $this->_prepareFormFields($textarea, $name, $attributes);
184
-		}, $index,$attributes,"textarea");
184
+		}, $index, $attributes, "textarea");
185 185
 	}
186 186
 
187
-	public function fieldAsHidden($index,$attributes=NULL){
188
-		if(!\is_array($attributes)){
187
+	public function fieldAsHidden($index, $attributes=NULL) {
188
+		if (!\is_array($attributes)) {
189 189
 			$attributes=[];
190 190
 		}
191 191
 		$attributes["inputType"]="hidden";
192
-		return $this->fieldAsInput($index,$attributes);
192
+		return $this->fieldAsInput($index, $attributes);
193 193
 	}
194 194
 
195
-	public function fieldAsCheckbox($index,$attributes=NULL){
196
-		return $this->_fieldAs(function($id,$name,$value,$caption) use($attributes){
197
-			if($caption===null || $caption==="")
195
+	public function fieldAsCheckbox($index, $attributes=NULL) {
196
+		return $this->_fieldAs(function($id, $name, $value, $caption) use($attributes){
197
+			if ($caption===null || $caption==="")
198 198
 				$caption="";
199
-			$input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier());
199
+			$input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier());
200 200
 			$input->setChecked(JString::isBooleanTrue($value));
201 201
 			return $this->_prepareFormFields($input, $name, $attributes);
202
-		}, $index,$attributes,"ck");
202
+		}, $index, $attributes, "ck");
203 203
 	}
204 204
 
205
-	public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){
206
-		return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple,$attributes){
207
-			$dd=new HtmlFormDropdown($id,$elements,$caption,$value);
208
-			$dd->asSelect($name,$multiple);
205
+	public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) {
206
+		return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple, $attributes){
207
+			$dd=new HtmlFormDropdown($id, $elements, $caption, $value);
208
+			$dd->asSelect($name, $multiple);
209 209
 			return $this->_prepareFormFields($dd, $name, $attributes);
210
-		}, $index,$attributes,"dd");
210
+		}, $index, $attributes, "dd");
211 211
 	}
212 212
 
213
-	public function fieldAsMessage($index,$attributes=NULL){
214
-		return $this->_fieldAs(function($id,$name,$value,$caption){
215
-			$mess= new HtmlMessage("message-".$id,$caption);
213
+	public function fieldAsMessage($index, $attributes=NULL) {
214
+		return $this->_fieldAs(function($id, $name, $value, $caption) {
215
+			$mess=new HtmlMessage("message-".$id, $caption);
216 216
 			$mess->addHeader($value);
217 217
 			return $mess;
218
-		}, $index,$attributes,"message");
218
+		}, $index, $attributes, "message");
219 219
 	}
220 220
 
221
-	public function fieldAsLink($index,$attributes=NULL){
222
-		return $this->_fieldAs(function($id,$name,$value,$caption){
223
-			$lnk= new HtmlLink("message-".$id,"#",$caption);
221
+	public function fieldAsLink($index, $attributes=NULL) {
222
+		return $this->_fieldAs(function($id, $name, $value, $caption) {
223
+			$lnk=new HtmlLink("message-".$id, "#", $caption);
224 224
 			return $lnk;
225
-		}, $index,$attributes,"link");
225
+		}, $index, $attributes, "link");
226 226
 	}
227 227
 
228 228
 	/**Change fields type
229 229
 	 * @param array $types an array or associative array $type=>$attributes
230 230
 	 */
231
-	public function fieldsAs(array $types){
231
+	public function fieldsAs(array $types) {
232 232
 		$i=0;
233
-		if(JArray::isAssociative($types)){
234
-			foreach ($types as $type=>$attributes){
235
-				if(\is_int($type))
236
-					$this->fieldAs($i++,$attributes,[]);
237
-				else{
238
-					$type=preg_replace('/\d/', '', $type );
239
-					$this->fieldAs($i++,$type,$attributes);
233
+		if (JArray::isAssociative($types)) {
234
+			foreach ($types as $type=>$attributes) {
235
+				if (\is_int($type))
236
+					$this->fieldAs($i++, $attributes, []);
237
+				else {
238
+					$type=preg_replace('/\d/', '', $type);
239
+					$this->fieldAs($i++, $type, $attributes);
240 240
 				}
241 241
 			}
242
-		}else{
243
-			foreach ($types as $type){
244
-				$this->fieldAs($i++,$type);
242
+		} else {
243
+			foreach ($types as $type) {
244
+				$this->fieldAs($i++, $type);
245 245
 			}
246 246
 		}
247 247
 	}
248 248
 
249
-	public function fieldAs($index,$type,$attributes=NULL){
249
+	public function fieldAs($index, $type, $attributes=NULL) {
250 250
 		$method="fieldAs".\ucfirst($type);
251
-		if(\method_exists($this, $method)){
252
-			if(!\is_array($attributes)){
251
+		if (\method_exists($this, $method)) {
252
+			if (!\is_array($attributes)) {
253 253
 				$attributes=[$index];
254
-			}else{
254
+			} else {
255 255
 				\array_unshift($attributes, $index);
256 256
 			}
257
-			\call_user_func_array([$this,$method], $attributes);
257
+			\call_user_func_array([$this, $method], $attributes);
258 258
 		}
259 259
 	}
260 260
 
261
-	public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){
262
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){
263
-			$button=new HtmlButton($id,$caption,$cssStyle);
264
-			$this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]);
261
+	public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) {
262
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){
263
+			$button=new HtmlButton($id, $caption, $cssStyle);
264
+			$this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]);
265 265
 			return $button;
266
-		}, $index,$attributes,"submit");
266
+		}, $index, $attributes, "submit");
267 267
 	}
268 268
 
269
-	public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){
270
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){
271
-			$button=new HtmlButton($id,$value,$cssStyle);
269
+	public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) {
270
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){
271
+			$button=new HtmlButton($id, $value, $cssStyle);
272 272
 			return $button;
273
-		}, $index,$attributes,"button");
273
+		}, $index, $attributes, "button");
274 274
 	}
275 275
 }
Please login to merge, or discard this patch.
Ajax/semantic/widgets/dataform/DataForm.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -21,83 +21,83 @@  discard block
 block discarded – undo
21 21
 	use BaseTrait;
22 22
 
23 23
 	public function __construct($identifier, $modelInstance=NULL) {
24
-		parent::__construct($identifier, null,$modelInstance);
24
+		parent::__construct($identifier, null, $modelInstance);
25 25
 		$this->_form=new HtmlForm($identifier);
26 26
 		$this->_init(new FormInstanceViewer($identifier), "form", $this->_form, true);
27 27
 	}
28 28
 
29
-	protected function _getFieldIdentifier($prefix,$name=""){
29
+	protected function _getFieldIdentifier($prefix, $name="") {
30 30
 		return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier();
31 31
 	}
32 32
 
33
-	public function compile(JsUtils $js=NULL,&$view=NULL){
34
-		if(!$this->_generated){
33
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
34
+		if (!$this->_generated) {
35 35
 			$this->_instanceViewer->setInstance($this->_modelInstance);
36 36
 
37 37
 			$form=$this->content["form"];
38 38
 			$this->_generateContent($form);
39 39
 
40
-			if(isset($this->_toolbar)){
40
+			if (isset($this->_toolbar)) {
41 41
 				$this->_setToolbarPosition($form);
42 42
 			}
43
-			$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]);
43
+			$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]);
44 44
 			$this->_generated=true;
45 45
 		}
46
-		return parent::compile($js,$view);
46
+		return parent::compile($js, $view);
47 47
 	}
48 48
 
49 49
 	/**
50 50
 	 * @param HtmlForm $form
51 51
 	 */
52
-	protected function _generateContent($form){
53
-		$values= $this->_instanceViewer->getValues();
52
+	protected function _generateContent($form) {
53
+		$values=$this->_instanceViewer->getValues();
54 54
 		$count=$this->_instanceViewer->count();
55 55
 		$separators=$this->_instanceViewer->getSeparators();
56 56
 		$headers=$this->_instanceViewer->getHeaders();
57 57
 		$wrappers=$this->_instanceViewer->getWrappers();
58 58
 		\sort($separators);
59 59
 		$size=\sizeof($separators);
60
-		if($size===1){
60
+		if ($size===1) {
61 61
 			$i=-1;
62
-			foreach ($values as $v){
62
+			foreach ($values as $v) {
63 63
 				$this->_generateFields($form, [$v], $headers, $i, $wrappers);
64 64
 				$i++;
65 65
 			}
66
-		}else{
66
+		} else {
67 67
 			$separators[]=$count;
68
-			for($i=0;$i<$size;$i++){
69
-				$fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]);
68
+			for ($i=0; $i<$size; $i++) {
69
+				$fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]);
70 70
 				$this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers);
71 71
 			}
72 72
 		}
73 73
 	}
74 74
 
75
-	protected function _generateFields($form,$values,$headers,$sepFirst,$wrappers){
75
+	protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers) {
76 76
 		$wrapper=null;
77
-		if(isset($headers[$sepFirst+1]))
78
-			$form->addHeader($headers[$sepFirst+1],4,true);
79
-		if(isset($wrappers[$sepFirst+1])){
77
+		if (isset($headers[$sepFirst+1]))
78
+			$form->addHeader($headers[$sepFirst+1], 4, true);
79
+		if (isset($wrappers[$sepFirst+1])) {
80 80
 			$wrapper=$wrappers[$sepFirst+1];
81 81
 		}
82
-		if(\sizeof($values)===1){
82
+		if (\sizeof($values)===1) {
83 83
 			$added=$form->addField($values[0]);
84
-		}elseif(\sizeof($values)>1){
84
+		}elseif (\sizeof($values)>1) {
85 85
 			$added=$form->addFields($values);
86
-		}else
86
+		} else
87 87
 			return;
88
-		if(isset($wrapper)){
89
-			$added->wrap($wrapper[0],$wrapper[1]);
88
+		if (isset($wrapper)) {
89
+			$added->wrap($wrapper[0], $wrapper[1]);
90 90
 		}
91 91
 	}
92 92
 
93 93
 	/**
94 94
 	 * @return HtmlForm
95 95
 	 */
96
-	public function getForm(){
96
+	public function getForm() {
97 97
 		return $this->content["form"];
98 98
 	}
99 99
 
100
-	public function addSeparatorAfter($fieldNum){
100
+	public function addSeparatorAfter($fieldNum) {
101 101
 		$fieldNum=$this->_getIndex($fieldNum);
102 102
 		$this->_instanceViewer->addSeparatorAfter($fieldNum);
103 103
 		return $this;
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 		return $this;
113 113
 	}
114 114
 
115
-	public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){
116
-		return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){
117
-			$button=new HtmlButton($id,$value,$cssStyle);
115
+	public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) {
116
+		return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){
117
+			$button=new HtmlButton($id, $value, $cssStyle);
118 118
 			$button->setProperty("type", "reset");
119 119
 			return $button;
120
-		}, $index,$attributes);
120
+		}, $index, $attributes);
121 121
 	}
122 122
 
123 123
 	/**
@@ -136,19 +136,19 @@  discard block
 block discarded – undo
136 136
 		$this->content[$this->_toolbarPosition]=$this->_toolbar;
137 137
 	}
138 138
 
139
-	public function addDividerBefore($index,$title){
139
+	public function addDividerBefore($index, $title) {
140 140
 		$index=$this->_getIndex($index);
141 141
 		$this->_instanceViewer->addHeaderDividerBefore($index, $title);
142 142
 		return $this;
143 143
 	}
144 144
 
145
-	public function addWrapper($index,$contentBefore,$contentAfter=null){
145
+	public function addWrapper($index, $contentBefore, $contentAfter=null) {
146 146
 		$index=$this->_getIndex($index);
147
-		$this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter);
147
+		$this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter);
148 148
 		return $this;
149 149
 	}
150 150
 
151
-	public function run(JsUtils $js){
151
+	public function run(JsUtils $js) {
152 152
 		return parent::run($js);
153 153
 	}
154 154
 }
Please login to merge, or discard this patch.
Ajax/semantic/widgets/business/BusinessForm.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@  discard block
 block discarded – undo
16 16
 	 *
17 17
 	 * @see \Ajax\semantic\widgets\dataform\DataForm::__construct()
18 18
 	 */
19
-	public function __construct($identifier,$modelInstance=null,$fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]) {
20
-		if(!isset($modelInstance)){
19
+	public function __construct($identifier, $modelInstance=null, $fieldsOrder, $fieldsDefinition, $fields=[], $captions=[], $separators=[]) {
20
+		if (!isset($modelInstance)) {
21 21
 			$modelInstance=$this->getDefaultModelInstance();
22 22
 		}
23
-		parent::__construct($identifier,$modelInstance);
24
-		$this->_initForm($fieldsOrder, $fieldsDefinition,$fields,$captions,$separators);
23
+		parent::__construct($identifier, $modelInstance);
24
+		$this->_initForm($fieldsOrder, $fieldsDefinition, $fields, $captions, $separators);
25 25
 	}
26 26
 
27 27
 	abstract protected function getDefaultModelInstance();
28 28
 
29
-	protected function _initForm($fieldsOrder,$fieldsDefinition,$fields=[],$captions=[],$separators=[]){
29
+	protected function _initForm($fieldsOrder, $fieldsDefinition, $fields=[], $captions=[], $separators=[]) {
30 30
 		$this->_fieldsOrder=$fieldsOrder;
31 31
 		$this->setFields($fields);
32 32
 		$this->setSeparators($separators);
@@ -34,26 +34,26 @@  discard block
 block discarded – undo
34 34
 		$this->setCaptions($captions);
35 35
 	}
36 36
 
37
-	protected function _getIndex($fieldName){
37
+	protected function _getIndex($fieldName) {
38 38
 		$index=$fieldName;
39
-		if(\is_string($fieldName)){
39
+		if (\is_string($fieldName)) {
40 40
 			$index=\array_search($fieldName, $this->_fieldsOrder);
41 41
 		}
42 42
 		return $index;
43 43
 	}
44
-	protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){
44
+	protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) {
45 45
 		$index=$this->_getIndex($index);
46
-		return parent::_fieldAs($elementCallback, $index,$attributes,$prefix);
46
+		return parent::_fieldAs($elementCallback, $index, $attributes, $prefix);
47 47
 	}
48 48
 
49 49
 
50
-	public function removeField($fieldName){
50
+	public function removeField($fieldName) {
51 51
 		parent::removeField($fieldName);
52
-		\array_splice($this->_fieldsOrder,$this->_getIndex($fieldName),1);
52
+		\array_splice($this->_fieldsOrder, $this->_getIndex($fieldName), 1);
53 53
 		return $this;
54 54
 	}
55 55
 
56
-	public function compile(JsUtils $js=NULL,&$view=NULL){
57
-		return parent::compile($js,$view);
56
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
57
+		return parent::compile($js, $view);
58 58
 	}
59 59
 }
Please login to merge, or discard this patch.
Ajax/semantic/widgets/business/user/FormLogin.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -10,50 +10,50 @@
 block discarded – undo
10 10
 	 * @param string $identifier
11 11
 	 * @param object $modelInstance
12 12
 	 */
13
-	public function __construct($identifier,$modelInstance=null,$fieldsOrder=[],$fieldsDefinition=[],$fields=[],$captions=[],$separators=[]) {
14
-		parent::__construct($identifier,$modelInstance,$fieldsOrder,$fieldsDefinition,$fields,$captions,$separators);
13
+	public function __construct($identifier, $modelInstance=null, $fieldsOrder=[], $fieldsDefinition=[], $fields=[], $captions=[], $separators=[]) {
14
+		parent::__construct($identifier, $modelInstance, $fieldsOrder, $fieldsDefinition, $fields, $captions, $separators);
15 15
 	}
16 16
 
17
-	protected function getDefaultModelInstance(){
17
+	protected function getDefaultModelInstance() {
18 18
 		return new UserModel();
19 19
 	}
20 20
 
21
-	public static function regular($identifier,$modelInstance=null){
22
-		return new FormLogin($identifier,$modelInstance,
23
-				["message","login","password","remember","forget","submit","error"],
24
-				["message"=>[["icon"=>"sign in"]],"input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"checkbox","link","submit"=>["green fluid"],"message2"=>[["error"=>true]]],
25
-				["Connection","login","password","remember","forget","submit","error"],
26
-				["Please enter login and password to connect","Login","Password","Remember me.","Forgot your password?","Connection"],
27
-				[0,2,4,5,6]);
21
+	public static function regular($identifier, $modelInstance=null) {
22
+		return new FormLogin($identifier, $modelInstance,
23
+				["message", "login", "password", "remember", "forget", "submit", "error"],
24
+				["message"=>[["icon"=>"sign in"]], "input0"=>[["rules"=>"empty"]], "input1"=>[["inputType"=>"password", "rules"=>"empty"]], "checkbox", "link", "submit"=>["green fluid"], "message2"=>[["error"=>true]]],
25
+				["Connection", "login", "password", "remember", "forget", "submit", "error"],
26
+				["Please enter login and password to connect", "Login", "Password", "Remember me.", "Forgot your password?", "Connection"],
27
+				[0, 2, 4, 5, 6]);
28 28
 	}
29 29
 
30
-	public static function smallInline($identifier,$modelInstance=null){
31
-		$result=new FormLogin($identifier,$modelInstance,
32
-				["login","password","submit"],
33
-				["input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"submit"=>["green basic"]],
34
-				["login","password","submit"],
35
-				["","","Connection"],
30
+	public static function smallInline($identifier, $modelInstance=null) {
31
+		$result=new FormLogin($identifier, $modelInstance,
32
+				["login", "password", "submit"],
33
+				["input0"=>[["rules"=>"empty"]], "input1"=>[["inputType"=>"password", "rules"=>"empty"]], "submit"=>["green basic"]],
34
+				["login", "password", "submit"],
35
+				["", "", "Connection"],
36 36
 				[2]);
37 37
 			$result->addDividerBefore(0, "Connection");
38 38
 		return $result;
39 39
 	}
40 40
 
41
-	public static function small($identifier,$modelInstance=null){
42
-		$result=new FormLogin($identifier,$modelInstance,
43
-				["login","password","submit"],
44
-				["input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"submit"=>["green basic"]],
45
-				["login","password","submit"],
46
-				["Login","Password","Connection"],
47
-				[1,2]);
41
+	public static function small($identifier, $modelInstance=null) {
42
+		$result=new FormLogin($identifier, $modelInstance,
43
+				["login", "password", "submit"],
44
+				["input0"=>[["rules"=>"empty"]], "input1"=>[["inputType"=>"password", "rules"=>"empty"]], "submit"=>["green basic"]],
45
+				["login", "password", "submit"],
46
+				["Login", "Password", "Connection"],
47
+				[1, 2]);
48 48
 		$result->addDividerBefore(0, "Connection");
49 49
 		return $result;
50 50
 	}
51 51
 
52
-	public static function attachedSegment($identifier,$modelInstance=null){
53
-		$result=self::regular($identifier,$modelInstance);
54
-		$result->fieldAsMessage("message",["icon"=>"sign in","attached"=>true]);
55
-		$result->addWrapper("message",null,"<div class='ui attached segment'>");
56
-		$result->addWrapper("error", null,"</div>");
52
+	public static function attachedSegment($identifier, $modelInstance=null) {
53
+		$result=self::regular($identifier, $modelInstance);
54
+		$result->fieldAsMessage("message", ["icon"=>"sign in", "attached"=>true]);
55
+		$result->addWrapper("message", null, "<div class='ui attached segment'>");
56
+		$result->addWrapper("error", null, "</div>");
57 57
 		return $result;
58 58
 	}
59 59
 }
Please login to merge, or discard this patch.
Ajax/semantic/components/Form.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 		$this->params["fields"]=[];
21 21
 	}
22 22
 
23
-	public function addField($identifier){
23
+	public function addField($identifier) {
24 24
 		$this->params["fields"][$identifier]=new FieldValidation($identifier);
25 25
 	}
26 26
 
27
-	public function setInline($value){
27
+	public function setInline($value) {
28 28
 		return $this->setParam("inline", true);
29 29
 	}
30 30
 
31
-	public function setOn($value){
31
+	public function setOn($value) {
32 32
 		return $this->setParam("on", $value);
33 33
 	}
34 34
 
@@ -40,33 +40,33 @@  discard block
 block discarded – undo
40 40
 	 * @param mixed $value
41 41
 	 * @param string|NULL $prompt
42 42
 	 */
43
-	public function addFieldRule($identifier,$type,$prompt=NULL,$value=NULL){
44
-		if(isset($this->params["fields"][$identifier])===false){
43
+	public function addFieldRule($identifier, $type, $prompt=NULL, $value=NULL) {
44
+		if (isset($this->params["fields"][$identifier])===false) {
45 45
 			$this->addField($identifier);
46 46
 		}
47
-		$this->params["fields"][$identifier]->addRule($type,$prompt,$value);
47
+		$this->params["fields"][$identifier]->addRule($type, $prompt, $value);
48 48
 	}
49 49
 
50 50
 	/**
51 51
 	 * @param FieldValidation $fieldValidation
52 52
 	 */
53
-	public function addFieldValidation($fieldValidation){
53
+	public function addFieldValidation($fieldValidation) {
54 54
 		$this->params["fields"][$fieldValidation->getIdentifier()]=$fieldValidation;
55 55
 	}
56 56
 
57
-	public function setJs(JsUtils $js){
57
+	public function setJs(JsUtils $js) {
58 58
 		$this->js=$js;
59 59
 	}
60 60
 
61 61
 	public function getScript() {
62 62
 		$allParams=$this->params;
63
-		$this->jquery_code_for_compile=array ();
63
+		$this->jquery_code_for_compile=array();
64 64
 		$this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).");";
65 65
 		$this->compileEvents();
66 66
 		return $this->compileJQueryCode();
67 67
 	}
68 68
 
69
-	public function onValid($jsCode){
69
+	public function onValid($jsCode) {
70 70
 		$this->addComponentEvent("onValid", $jsCode);
71 71
 	}
72 72
 }
Please login to merge, or discard this patch.
Ajax/semantic/components/Dropdown.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * @param string $action one of "select","auto","activate","combo","nothing","hide"
18 18
 	 * @return \Ajax\semantic\components\Dropdown
19 19
 	 */
20
-	public function setAction($action){
21
-		return $this->setParamCtrl("action", $action,array("select","auto","activate","combo","nothing","hide"));
20
+	public function setAction($action) {
21
+		return $this->setParamCtrl("action", $action, array("select", "auto", "activate", "combo", "nothing", "hide"));
22 22
 	}
23 23
 
24 24
 	/**
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
 	 * @param string $event Event used to trigger dropdown (Hover, Click, Custom Event)
27 27
 	 * @return \Ajax\semantic\components\Dropdown
28 28
 	 */
29
-	public function setOn($event){
29
+	public function setOn($event) {
30 30
 		return $this->setParam("on", $event);
31 31
 	}
32 32
 
33
-	public function setFullTextSearch($value){
33
+	public function setFullTextSearch($value) {
34 34
 		return $this->setParam("fullTextSearch", $value);
35 35
 	}
36 36
 }
Please login to merge, or discard this patch.