|
11 | 11 | use Ajax\semantic\html\elements\HtmlButton;
|
12 | 12 | use Ajax\semantic\html\base\constants\Direction;
|
13 | 13 | use Ajax\service\JArray;
|
14 |
| -use Ajax\semantic\html\base\HtmlSemDoubleElement; |
15 | 14 | use Ajax\semantic\widgets\base\InstanceViewer;
|
16 | 15 | use Ajax\semantic\html\collections\table\traits\TableTrait;
|
17 | 16 | use Ajax\semantic\html\elements\HtmlLabel;
|
|
24 | 23 | *
|
25 | 24 | */
|
26 | 25 | class DataTable extends Widget {
|
27 |
| - use TableTrait; |
| 26 | + use TableTrait,DataTableFieldAsTrait; |
28 | 27 | protected $_searchField;
|
29 | 28 | protected $_urls;
|
30 | 29 | protected $_pagination;
|
@@ -114,7 +113,7 @@ public function compile(JsUtils $js=NULL,&$view=NULL){
|
114 | 113 | $this->_generateContent($table);
|
115 | 114 |
|
116 | 115 | if($this->_hasCheckboxes && $table->hasPart("thead")){
|
117 |
| - $table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort"); |
| 116 | + $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
118 | 117 | }
|
119 | 118 |
|
120 | 119 | if(isset($this->_pagination) && $this->_pagination->getVisible()){
|
@@ -263,133 +262,7 @@ public function refresh($compileParts=["tbody"]){
|
263 | 262 | $this->_compileParts=$compileParts;
|
264 | 263 | return $this;
|
265 | 264 | }
|
266 |
| - /** |
267 |
| - * @param string $caption |
268 |
| - * @param callable $callback |
269 |
| - * @param boolean $visibleHover |
270 |
| - * @return callable |
271 |
| - */ |
272 |
| - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
273 |
| - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
274 |
| - } |
275 |
| - |
276 |
| - /** |
277 |
| - * @param callable $thisCallback |
278 |
| - * @param array $parameters |
279 |
| - * @param callable $callback |
280 |
| - * @return callable |
281 |
| - */ |
282 |
| - private function getCallable($thisCallback,$parameters,$callback=null){ |
283 |
| - $result=function($instance) use($thisCallback,$parameters,$callback){ |
284 |
| - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
285 |
| - if(isset($callback)){ |
286 |
| - if(\is_callable($callback)){ |
287 |
| - $callback($object,$instance); |
288 |
| - } |
289 |
| - } |
290 |
| - if($object instanceof HtmlSemDoubleElement){ |
291 |
| - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
292 |
| - if($object->propertyContains("class","visibleover")){ |
293 |
| - $this->_visibleHover=true; |
294 |
| - $object->setProperty("style","visibility:hidden;"); |
295 |
| - } |
296 |
| - } |
297 |
| - return $object; |
298 |
| - }; |
299 |
| - return $result; |
300 |
| - } |
301 |
| - |
302 |
| - /** |
303 |
| - * @param string $caption |
304 |
| - * @return HtmlButton |
305 |
| - */ |
306 |
| - private function getFieldButton($caption,$visibleHover=true){ |
307 |
| - $bt= new HtmlButton("",$caption); |
308 |
| - if($visibleHover) |
309 |
| - $this->_visibleOver($bt); |
310 |
| - return $bt; |
311 |
| - } |
312 | 265 |
|
313 |
| - /** |
314 |
| - * Inserts a new Button for each row |
315 |
| - * @param string $caption |
316 |
| - * @param callable $callback |
317 |
| - * @param boolean $visibleHover |
318 |
| - * @return \Ajax\semantic\widgets\datatable\DataTable |
319 |
| - */ |
320 |
| - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
321 |
| - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
322 |
| - return $this; |
323 |
| - } |
324 |
| - |
325 |
| - /** |
326 |
| - * Inserts a new Button for each row at col $index |
327 |
| - * @param int $index |
328 |
| - * @param string $caption |
329 |
| - * @param callable $callback |
330 |
| - * @return \Ajax\semantic\widgets\datatable\DataTable |
331 |
| - */ |
332 |
| - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
333 |
| - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
334 |
| - return $this; |
335 |
| - } |
336 |
| - |
337 |
| - /** |
338 |
| - * Inserts a new Button for each row in col at $index |
339 |
| - * @param int $index |
340 |
| - * @param string $caption |
341 |
| - * @param callable $callback |
342 |
| - * @return \Ajax\semantic\widgets\datatable\DataTable |
343 |
| - */ |
344 |
| - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
345 |
| - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
346 |
| - return $this; |
347 |
| - } |
348 |
| - |
349 |
| - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
350 |
| - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
351 |
| - return $this; |
352 |
| - } |
353 |
| - |
354 |
| - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
355 |
| - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
356 |
| - return $this; |
357 |
| - } |
358 |
| - |
359 |
| - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
360 |
| - $bt=$this->getFieldButton("",$visibleHover); |
361 |
| - $bt->asIcon($icon); |
362 |
| - if(isset($class)) |
363 |
| - $bt->addToProperty("class", $class); |
364 |
| - return $bt; |
365 |
| - } |
366 |
| - |
367 |
| - public function addDeleteButton($visibleHover=true,$generateBehavior=true,$callback=null){ |
368 |
| - $this->_hasDelete=$generateBehavior; |
369 |
| - return $this->addDefaultButton("remove","delete red basic",$visibleHover,$callback); |
370 |
| - } |
371 |
| - |
372 |
| - public function addEditButton($visibleHover=true,$generateBehavior=true,$callback=null){ |
373 |
| - $this->_hasEdit=$generateBehavior; |
374 |
| - return $this->addDefaultButton("edit","edit basic",$visibleHover,$callback); |
375 |
| - } |
376 |
| - |
377 |
| - public function addEditDeleteButtons($visibleHover=true,$generateBehavior=true,$callbackEdit=null,$callbackDelete=null){ |
378 |
| - $this->addEditButton($visibleHover,$generateBehavior,$callbackEdit); |
379 |
| - $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
380 |
| - $this->insertDeleteButtonIn($index,$visibleHover,$generateBehavior,$callbackDelete); |
381 |
| - return $this; |
382 |
| - } |
383 |
| - |
384 |
| - public function insertDeleteButtonIn($index,$visibleHover=true,$generateBehavior=true,$callback=null){ |
385 |
| - $this->_hasDelete=$generateBehavior; |
386 |
| - return $this->insertDefaultButtonIn($index,"remove","delete red basic",$visibleHover,$callback); |
387 |
| - } |
388 |
| - |
389 |
| - public function insertEditButtonIn($index,$visibleHover=true,$generateBehavior=true,$callback=null){ |
390 |
| - $this->_hasEdit=$generateBehavior; |
391 |
| - return $this->insertDefaultButtonIn($index,"edit","edit basic",$visibleHover,$callback); |
392 |
| - } |
393 | 266 |
|
394 | 267 | public function addSearchInToolbar($position=Direction::RIGHT){
|
395 | 268 | return $this->addInToolbar($this->getSearchField())->setPosition($position);
|
@@ -424,7 +297,7 @@ public function asForm(){
|
424 | 297 | * @param string $cssStyle
|
425 | 298 | * @param string $url
|
426 | 299 | * @param string $responseElement
|
427 |
| - * @param array $attributes |
| 300 | + * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
428 | 301 | * @return \Ajax\semantic\widgets\datatable\DataTable
|
429 | 302 | */
|
430 | 303 | public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){
|
|
0 commit comments