@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | */ |
25 | 25 | class DataTable extends Widget { |
26 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait; |
|
26 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait; |
|
27 | 27 | protected $_searchField; |
28 | 28 | protected $_urls; |
29 | 29 | protected $_pagination; |
@@ -41,35 +41,35 @@ discard block |
||
41 | 41 | protected $_colWidths; |
42 | 42 | |
43 | 43 | |
44 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
45 | - parent::__construct($identifier, $model,$modelInstance); |
|
46 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
44 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
45 | + parent::__construct($identifier, $model, $modelInstance); |
|
46 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
47 | 47 | $this->_urls=[]; |
48 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
48 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
49 | 49 | $this->_emptyMessage->setIcon("info circle"); |
50 | 50 | } |
51 | 51 | |
52 | - public function run(JsUtils $js){ |
|
53 | - if($this->_hasCheckboxes && isset($js)){ |
|
52 | + public function run(JsUtils $js) { |
|
53 | + if ($this->_hasCheckboxes && isset($js)) { |
|
54 | 54 | $this->_runCheckboxes($js); |
55 | 55 | } |
56 | - if($this->_visibleHover){ |
|
57 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
58 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
56 | + if ($this->_visibleHover) { |
|
57 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
58 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
59 | 59 | } |
60 | - if(\is_array($this->_deleteBehavior)) |
|
61 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
62 | - if(\is_array($this->_editBehavior)) |
|
63 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
60 | + if (\is_array($this->_deleteBehavior)) |
|
61 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
62 | + if (\is_array($this->_editBehavior)) |
|
63 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
64 | 64 | return parent::run($js); |
65 | 65 | } |
66 | 66 | |
67 | 67 | |
68 | 68 | |
69 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
70 | - if(isset($this->_urls[$op])){ |
|
71 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
72 | - $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params); |
|
69 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
70 | + if (isset($this->_urls[$op])) { |
|
71 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
72 | + $js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -82,155 +82,155 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | |
85 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
86 | - if(!$this->_generated){ |
|
85 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
86 | + if (!$this->_generated) { |
|
87 | 87 | $this->_instanceViewer->setInstance($this->_model); |
88 | 88 | $captions=$this->_instanceViewer->getCaptions(); |
89 | 89 | $table=$this->content["table"]; |
90 | - if($this->_hasCheckboxes){ |
|
90 | + if ($this->_hasCheckboxes) { |
|
91 | 91 | $this->_generateMainCheckbox($captions); |
92 | 92 | } |
93 | 93 | $table->setRowCount(0, \sizeof($captions)); |
94 | - $this->_generateHeader($table,$captions); |
|
94 | + $this->_generateHeader($table, $captions); |
|
95 | 95 | |
96 | - if(isset($this->_compileParts)) |
|
96 | + if (isset($this->_compileParts)) |
|
97 | 97 | $table->setCompileParts($this->_compileParts); |
98 | 98 | |
99 | - if(isset($this->_searchField) && isset($js)){ |
|
100 | - if(isset($this->_urls["refresh"])) |
|
101 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
99 | + if (isset($this->_searchField) && isset($js)) { |
|
100 | + if (isset($this->_urls["refresh"])) |
|
101 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $this->_generateContent($table); |
105 | 105 | |
106 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
106 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
107 | 107 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
108 | 108 | } |
109 | 109 | |
110 | - if(isset($this->_toolbar)){ |
|
110 | + if (isset($this->_toolbar)) { |
|
111 | 111 | $this->_setToolbarPosition($table, $captions); |
112 | 112 | } |
113 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
114 | - $this->_generatePagination($table,$js); |
|
113 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
114 | + $this->_generatePagination($table, $js); |
|
115 | 115 | } |
116 | 116 | |
117 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
117 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
118 | 118 | $this->_compileForm(); |
119 | 119 | $this->_applyStyleAttributes($table); |
120 | 120 | $this->_generated=true; |
121 | 121 | } |
122 | - return parent::compile($js,$view); |
|
122 | + return parent::compile($js, $view); |
|
123 | 123 | } |
124 | 124 | |
125 | - protected function _applyStyleAttributes($table){ |
|
126 | - if(isset($this->_hiddenColumns)) |
|
125 | + protected function _applyStyleAttributes($table) { |
|
126 | + if (isset($this->_hiddenColumns)) |
|
127 | 127 | $this->_hideColumns(); |
128 | - if(isset($this->_colWidths)){ |
|
129 | - foreach ($this->_colWidths as $colIndex=>$width){ |
|
130 | - $table->setColWidth($colIndex,$width); |
|
128 | + if (isset($this->_colWidths)) { |
|
129 | + foreach ($this->_colWidths as $colIndex=>$width) { |
|
130 | + $table->setColWidth($colIndex, $width); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | - protected function _hideColumns(){ |
|
135 | + protected function _hideColumns() { |
|
136 | 136 | $table=$this->getTable(); |
137 | - foreach ($this->_hiddenColumns as $colIndex){ |
|
137 | + foreach ($this->_hiddenColumns as $colIndex) { |
|
138 | 138 | $table->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,23 +242,23 @@ discard block |
||
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(); |
258 | 258 | $row->setValues([$this->_toolbar]); |
259 | 259 | } |
260 | 260 | |
261 | - public function getHtmlComponent(){ |
|
261 | + public function getHtmlComponent() { |
|
262 | 262 | return $this->content["table"]; |
263 | 263 | } |
264 | 264 | |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * @return DataTable |
273 | 273 | */ |
274 | 274 | public function setUrls($urls) { |
275 | - if(\is_array($urls)){ |
|
276 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
277 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
278 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
279 | - }else{ |
|
280 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
275 | + if (\is_array($urls)) { |
|
276 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
277 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
278 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
279 | + } else { |
|
280 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
281 | 281 | } |
282 | 282 | return $this; |
283 | 283 | } |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param number $pages_visibles The number of visible pages in the Pagination component |
291 | 291 | * @return DataTable |
292 | 292 | */ |
293 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
294 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
293 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
294 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
295 | 295 | return $this; |
296 | 296 | } |
297 | 297 | |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param number $pages_visibles The number of visible pages in the Pagination component |
303 | 303 | * @return DataTable |
304 | 304 | */ |
305 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
306 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
305 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
306 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
307 | 307 | return $this; |
308 | 308 | } |
309 | 309 | |
@@ -313,20 +313,20 @@ discard block |
||
313 | 313 | * @param array $compileParts |
314 | 314 | * @return DataTable |
315 | 315 | */ |
316 | - public function refresh($compileParts=["tbody"]){ |
|
316 | + public function refresh($compileParts=["tbody"]) { |
|
317 | 317 | $this->_compileParts=$compileParts; |
318 | 318 | return $this; |
319 | 319 | } |
320 | 320 | |
321 | 321 | |
322 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
322 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
323 | 323 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
324 | 324 | } |
325 | 325 | |
326 | - public function getSearchField(){ |
|
327 | - if(isset($this->_searchField)===false){ |
|
328 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
329 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
326 | + public function getSearchField() { |
|
327 | + if (isset($this->_searchField)===false) { |
|
328 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
329 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
330 | 330 | } |
331 | 331 | return $this->_searchField; |
332 | 332 | } |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | return $this; |
343 | 343 | } |
344 | 344 | |
345 | - public function asForm(){ |
|
345 | + public function asForm() { |
|
346 | 346 | return $this->getForm(); |
347 | 347 | } |
348 | 348 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | |
351 | 351 | protected function getTargetSelector() { |
352 | 352 | $result=$this->_targetSelector; |
353 | - if(!isset($result)) |
|
353 | + if (!isset($result)) |
|
354 | 354 | $result="#".$this->identifier; |
355 | 355 | return $result; |
356 | 356 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | |
368 | 368 | public function getRefreshSelector() { |
369 | - if(isset($this->_refreshSelector)) |
|
369 | + if (isset($this->_refreshSelector)) |
|
370 | 370 | return $this->_refreshSelector; |
371 | 371 | return "#".$this->identifier." tbody"; |
372 | 372 | } |
@@ -384,9 +384,9 @@ discard block |
||
384 | 384 | * {@inheritDoc} |
385 | 385 | * @see \Ajax\common\Widget::show() |
386 | 386 | */ |
387 | - public function show($modelInstance){ |
|
388 | - if(\is_array($modelInstance)){ |
|
389 | - if(\is_array(array_values($modelInstance)[0])) |
|
387 | + public function show($modelInstance) { |
|
388 | + if (\is_array($modelInstance)) { |
|
389 | + if (\is_array(array_values($modelInstance)[0])) |
|
390 | 390 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
391 | 391 | } |
392 | 392 | $this->_modelInstance=$modelInstance; |
@@ -421,24 +421,24 @@ discard block |
||
421 | 421 | return $this; |
422 | 422 | } |
423 | 423 | |
424 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
425 | - $this->getTable()->setActiveRowSelector($class,$event,$multiple); |
|
424 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
425 | + $this->getTable()->setActiveRowSelector($class, $event, $multiple); |
|
426 | 426 | return $this; |
427 | 427 | } |
428 | 428 | |
429 | - public function hideColumn($colIndex){ |
|
430 | - if(!\is_array($this->_hiddenColumns)) |
|
429 | + public function hideColumn($colIndex) { |
|
430 | + if (!\is_array($this->_hiddenColumns)) |
|
431 | 431 | $this->_hiddenColumns=[]; |
432 | 432 | $this->_hiddenColumns[]=$colIndex; |
433 | 433 | return $this; |
434 | 434 | } |
435 | 435 | |
436 | - public function setColWidth($colIndex,$width){ |
|
436 | + public function setColWidth($colIndex, $width) { |
|
437 | 437 | $this->_colWidths[$colIndex]=$width; |
438 | 438 | return $this; |
439 | 439 | } |
440 | 440 | public function setColWidths($_colWidths) { |
441 | - $this->_colWidths = $_colWidths; |
|
441 | + $this->_colWidths=$_colWidths; |
|
442 | 442 | return $this; |
443 | 443 | } |
444 | 444 | } |
445 | 445 | \ No newline at end of file |