phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
DataTableFieldAsTrait.php
Go to the documentation of this file.
1<?php
7
18 protected $_buttons=["display","edit","delete"];
19 protected $_buttonsColumn;
20 abstract public function addField($field,$key=null);
21 abstract public function insertField($index,$field,$key=null);
22 abstract public function insertInField($index,$field,$key=null);
23 abstract public function fieldAs($index,$type,$attributes=NULL);
24 abstract protected function cleanIdentifier($id);
25 abstract protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null);
26
33 private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){
34 return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback);
35 }
36
43 private function getCallable($thisCallback,$parameters,$callback=null){
44 $result=function($instance) use($thisCallback,$parameters,$callback){
45 $object=call_user_func_array(array($this,$thisCallback), $parameters);
46 if(isset($callback)){
47 if(\is_callable($callback)){
48 $callback($object,$instance,$this->_instanceViewer->count()+1);
49 }
50 }
51 if($object instanceof HtmlSemDoubleElement){
52 $id=$this->_instanceViewer->getIdentifier();
53 $object->setProperty("data-ajax",$id);
54 if($object->propertyContains("class","visibleover")){
55 $this->_visibleHover=true;
56 $object->setProperty("style","visibility:hidden;");
57 }
58 }
59 return $object;
60 };
61 return $result;
62 }
63
68 private function getFieldButton($caption,$visibleHover=true,$icon=null){
69 $id=$this->_instanceViewer->getIdentifier();
70 $bt= new HtmlButton($this->cleanIdentifier($icon??$caption).'-'.$id,$caption);
71 if($visibleHover)
72 $this->_visibleOver($bt);
73 return $bt;
74 }
75
76 private function getFieldButtons($buttons,$visibleHover=true){
77 $bts=new HtmlButtonGroups("",$buttons);
78 if($visibleHover)
79 $this->_visibleOver($bts);
80 return $bts;
81 }
82
92 public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){
93 return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){
94 $button=new HtmlButton($id,$value,$cssStyle);
95 $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]);
96 if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"])
97 $this->_visibleOver($button);
98 return $button;
99 }, $index,$attributes);
100 }
101
102 protected function _visibleOver(BaseHtml $element){
103 $this->_visibleHover=true;
104 return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;");
105 }
106
114 public function addFieldButton($caption,$visibleHover=true,$callback=null){
115 $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback));
116 return $this;
117 }
118
126 public function addFieldButtons($buttons,$visibleHover=true,$callback=null){
127 $this->addField($this->getCallable("getFieldButtons",[$buttons,$visibleHover],$callback));
128 return $this;
129 }
130
138 public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){
139 $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback));
140 return $this;
141 }
142
150 public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null,$key=null){
151 $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback),$key);
152 return $this;
153 }
154
155 public function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null,$key=null){
156 $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback),$key);
157 return $this;
158 }
159
160 public function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null,$key=null){
161 $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback),$key);
162 return $this;
163 }
164
165 private function getDefaultButton($icon,$class=null,$visibleHover=true){
166 $bt=$this->getFieldButton("",$visibleHover,$icon);
167 $bt->asIcon($icon);
168 if(isset($class))
169 $bt->addClass($class);
170 return $bt;
171 }
172
180 public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){
181 $this->_deleteBehavior=$deleteBehavior;
182 return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback,"delete");
183 }
184
192 public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){
193 $this->_editBehavior=$editBehavior;
194 return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback,"edit");
195 }
196
204 public function addDisplayButton($visibleHover=true,$displayBehavior=[],$callback=null){
205 $this->_displayBehavior=$displayBehavior;
206 return $this->addDefaultButton("eye","_display basic",$visibleHover,$callback,"display");
207 }
208
217 public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){
218 $this->addEditButton($visibleHover,$behavior,$callbackEdit);
219 $index=$this->_instanceViewer->visiblePropertiesCount()-1;
220 $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete);
221 return $this;
222 }
223
233 public function addAllButtons($visibleHover=true,$behavior=[],$callbackDisplay=null,$callbackEdit=null,$callbackDelete=null){
234 $this->addDisplayButton($visibleHover,$behavior,$callbackDisplay);
235 $index=$this->_instanceViewer->visiblePropertiesCount()-1;
236 $this->_buttonsColumn=$index;
237 $this->insertEditButtonIn($index,$visibleHover,$behavior,$callbackEdit);
238 $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete);
239 return $this;
240 }
241
242 public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=[],$callback=null){
243 $this->_deleteBehavior=$deleteBehavior;
244 return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback,"delete");
245 }
246
247 public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){
248 $this->_editBehavior=$editBehavior;
249 return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback,"edit");
250 }
251
252 public function insertDisplayButtonIn($index,$visibleHover=true,$displayBehavior=[],$callback=null){
253 $this->_displayBehavior=$displayBehavior;
254 return $this->insertDefaultButtonIn($index,"eye","_display basic",$visibleHover,$callback,"display");
255 }
256
260 public function getButtonsColumn() {
262 }
263
267 public function setButtons($_buttons) {
268 $this->_buttons = $_buttons;
269 return $this;
270 }
271
275 public function getButtons(): array {
276 return $this->_buttons;
277 }
278}
BaseHtml for HTML components.
Definition BaseHtml.php:17
Base class for Semantic double elements.
Semantic UI Buttongroups component.
Semantic Button component.
insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=[], $callback=null)
addEditButton($visibleHover=true, $editBehavior=[], $callback=null)
Adds an edit button.
insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null, $key=null)
addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null, $key=null)
insertDisplayButtonIn($index, $visibleHover=true, $displayBehavior=[], $callback=null)
_fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null)
addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null)
Adds an edit and a delete button.
getDefaultButton($icon, $class=null, $visibleHover=true)
getFieldButton($caption, $visibleHover=true, $icon=null)
addFieldButton($caption, $visibleHover=true, $callback=null)
Inserts a new Button for each row.
insertFieldButton($index, $caption, $visibleHover=true, $callback=null)
Inserts a new Button for each row at col $index.
insertInFieldButton($index, $caption, $visibleHover=true, $callback=null, $key=null)
Inserts a new Button for each row in col at $index.
addAllButtons($visibleHover=true, $behavior=[], $callbackDisplay=null, $callbackEdit=null, $callbackDelete=null)
Adds an edit and a delete button.
insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null)
addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null)
Adds a delete button.
addDisplayButton($visibleHover=true, $displayBehavior=[], $callback=null)
Adds a button for displaying an object.
getCallable($thisCallback, $parameters, $callback=null)
fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL)
Creates a submit button at $index position.
addFieldButtons($buttons, $visibleHover=true, $callback=null)
Inserts a new ButtonGroups for each row.
getFieldButtonCallable($caption, $visibleHover=true, $callback=null)