1
|
|
|
<?php |
2
|
|
|
namespace Ajax\semantic\widgets\datatable; |
3
|
|
|
use Ajax\semantic\html\elements\HtmlButton; |
4
|
|
|
use Ajax\semantic\widgets\base\InstanceViewer; |
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author jc |
9
|
|
|
* @property boolean $_hasDelete |
10
|
|
|
* @property boolean $_hasEdit |
11
|
|
|
* @property boolean $_visibleHover; |
12
|
|
|
* @property InstanceViewer $_instanceViewer |
13
|
|
|
*/ |
14
|
|
|
trait DataTableFieldAsTrait{ |
15
|
|
|
abstract public function addField($field); |
16
|
|
|
abstract public function insertField($index,$field); |
17
|
|
|
abstract public function insertInField($index,$field); |
18
|
|
|
/** |
19
|
|
|
* @param string $caption |
20
|
|
|
* @param callable $callback |
21
|
|
|
* @param boolean $visibleHover |
22
|
|
|
* @return callable |
23
|
|
|
*/ |
24
|
|
|
private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
25
|
|
|
return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param callable $thisCallback |
30
|
|
|
* @param array $parameters |
31
|
|
|
* @param callable $callback |
32
|
|
|
* @return callable |
33
|
|
|
*/ |
34
|
|
|
private function getCallable($thisCallback,$parameters,$callback=null){ |
35
|
|
|
$result=function($instance) use($thisCallback,$parameters,$callback){ |
36
|
|
|
$object=call_user_func_array(array($this,$thisCallback), $parameters); |
37
|
|
|
if(isset($callback)){ |
38
|
|
|
if(\is_callable($callback)){ |
39
|
|
|
$callback($object,$instance); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
if($object instanceof HtmlSemDoubleElement){ |
43
|
|
|
$object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
44
|
|
|
if($object->propertyContains("class","visibleover")){ |
45
|
|
|
$this->_visibleHover=true; |
|
|
|
|
46
|
|
|
$object->setProperty("style","visibility:hidden;"); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
return $object; |
50
|
|
|
}; |
51
|
|
|
return $result; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $caption |
56
|
|
|
* @return HtmlButton |
57
|
|
|
*/ |
58
|
|
|
private function getFieldButton($caption,$visibleHover=true){ |
59
|
|
|
$bt= new HtmlButton("",$caption); |
60
|
|
|
if($visibleHover) |
61
|
|
|
$this->_visibleOver($bt); |
62
|
|
|
return $bt; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Creates a submit button at $index position |
67
|
|
|
* @param int $index |
68
|
|
|
* @param string $cssStyle |
69
|
|
|
* @param string $url |
70
|
|
|
* @param string $responseElement |
71
|
|
|
* @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
72
|
|
|
* @return \Ajax\semantic\widgets\datatable\DataTable |
73
|
|
|
*/ |
74
|
|
|
public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
75
|
|
|
return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
|
|
|
|
76
|
|
|
$button=new HtmlButton($id,$value,$cssStyle); |
77
|
|
|
$button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
78
|
|
|
if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
79
|
|
|
$this->_visibleOver($button); |
80
|
|
|
return $button; |
81
|
|
|
}, $index,$attributes); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function _visibleOver($element){ |
85
|
|
|
$this->_visibleHover=true; |
|
|
|
|
86
|
|
|
return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Inserts a new Button for each row |
91
|
|
|
* @param string $caption |
92
|
|
|
* @param callable $callback |
93
|
|
|
* @param boolean $visibleHover |
94
|
|
|
* @return \Ajax\semantic\widgets\datatable\DataTable |
95
|
|
|
*/ |
96
|
|
|
public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
97
|
|
|
$this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Inserts a new Button for each row at col $index |
103
|
|
|
* @param int $index |
104
|
|
|
* @param string $caption |
105
|
|
|
* @param callable $callback |
106
|
|
|
* @return \Ajax\semantic\widgets\datatable\DataTable |
107
|
|
|
*/ |
108
|
|
|
public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
109
|
|
|
$this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Inserts a new Button for each row in col at $index |
115
|
|
|
* @param int $index |
116
|
|
|
* @param string $caption |
117
|
|
|
* @param callable $callback |
118
|
|
|
* @return \Ajax\semantic\widgets\datatable\DataTable |
119
|
|
|
*/ |
120
|
|
|
public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
121
|
|
|
$this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
126
|
|
|
$this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
131
|
|
|
$this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
|
|
|
136
|
|
|
$bt=$this->getFieldButton("",$visibleHover); |
137
|
|
|
$bt->asIcon($icon); |
138
|
|
|
if(isset($class)) |
139
|
|
|
$bt->addClass($class); |
140
|
|
|
return $bt; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function addDeleteButton($visibleHover=true,$generateBehavior=true,$callback=null){ |
144
|
|
|
$this->_hasDelete=$generateBehavior; |
145
|
|
|
return $this->addDefaultButton("remove","delete red basic",$visibleHover,$callback); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function addEditButton($visibleHover=true,$generateBehavior=true,$callback=null){ |
149
|
|
|
$this->_hasEdit=$generateBehavior; |
150
|
|
|
return $this->addDefaultButton("edit","edit basic",$visibleHover,$callback); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function addEditDeleteButtons($visibleHover=true,$generateBehavior=true,$callbackEdit=null,$callbackDelete=null){ |
154
|
|
|
$this->addEditButton($visibleHover,$generateBehavior,$callbackEdit); |
155
|
|
|
$index=$this->_instanceViewer->visiblePropertiesCount()-1; |
156
|
|
|
$this->insertDeleteButtonIn($index,$visibleHover,$generateBehavior,$callbackDelete); |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function insertDeleteButtonIn($index,$visibleHover=true,$generateBehavior=true,$callback=null){ |
161
|
|
|
$this->_hasDelete=$generateBehavior; |
162
|
|
|
return $this->insertDefaultButtonIn($index,"remove","delete red basic",$visibleHover,$callback); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function insertEditButtonIn($index,$visibleHover=true,$generateBehavior=true,$callback=null){ |
166
|
|
|
$this->_hasEdit=$generateBehavior; |
167
|
|
|
return $this->insertDefaultButtonIn($index,"edit","edit basic",$visibleHover,$callback); |
168
|
|
|
} |
169
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.