1
|
|
|
<?php |
2
|
|
|
namespace Ajax\semantic\widgets\base; |
3
|
|
|
use Ajax\semantic\html\elements\HtmlInput; |
4
|
|
|
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox; |
5
|
|
|
use Ajax\service\JString; |
6
|
|
|
use Ajax\semantic\html\modules\HtmlDropdown; |
7
|
|
|
use Ajax\semantic\html\elements\HtmlImage; |
8
|
|
|
use Ajax\semantic\html\modules\checkbox\HtmlRadio; |
9
|
|
|
use Ajax\semantic\html\base\constants\Size; |
10
|
|
|
use Ajax\semantic\widgets\datatable\InstanceViewer; |
11
|
|
|
use Ajax\semantic\html\elements\HtmlLabel; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author jc |
15
|
|
|
* @property InstanceViewer $_instanceViewer |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
trait FieldAsTrait{ |
19
|
|
|
|
20
|
|
|
protected abstract function _getFieldIdentifier($prefix); |
21
|
|
|
public abstract function setValueFunction($index,$callback); |
22
|
|
|
|
23
|
|
|
private function _getLabelField($caption,$icon=NULL){ |
24
|
|
|
$label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
25
|
|
|
return $label; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function fieldAsLabel($index,$icon=NULL){ |
29
|
|
|
$this->setValueFunction($index,function($caption) use($icon){ |
30
|
|
|
$lbl=$this->_getLabelField($caption,$icon); |
31
|
|
|
return $lbl; |
32
|
|
|
} |
33
|
|
|
); |
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
38
|
|
|
$this->setValueFunction($index,function($img) use($size,$circular){ |
39
|
|
|
$image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
40
|
|
|
return $image; |
41
|
|
|
} |
42
|
|
|
); |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function fieldAsAvatar($index){ |
47
|
|
|
$this->setValueFunction($index,function($img){return (new HtmlImage("",$img))->asAvatar();}); |
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function fieldAsRadio($index,$name=NULL){ |
52
|
|
|
$this->setValueFunction($index,function($value)use ($index,$name){ |
53
|
|
|
if(isset($name)===false){ |
54
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
$radio=new HtmlRadio($this->_getFieldIdentifier("radio"),$name,$value,$value); |
57
|
|
|
return $radio; |
58
|
|
|
} |
59
|
|
|
); |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function fieldAsInput($index,$name=NULL,$type="text",$placeholder=""){ |
|
|
|
|
64
|
|
|
$this->setValueFunction($index,function($value) use($index,$name,$type,$placeholder){ |
65
|
|
|
$input=new HtmlInput($this->_getFieldIdentifier("input"),$type,$value,$placeholder); |
66
|
|
|
if(isset($name)===false){ |
67
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
$input->getField()->setProperty("name", $name); |
70
|
|
|
return $input; |
71
|
|
|
} |
72
|
|
|
); |
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function fieldAsCheckbox($index,$name=NULL){ |
|
|
|
|
77
|
|
|
$this->setValueFunction($index,function($value) use($index,$name){ |
78
|
|
|
$checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"),"",$value); |
79
|
|
|
$checkbox->setChecked(JString::isBooleanTrue($value)); |
80
|
|
|
if(isset($name)===false){ |
81
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
$checkbox->getField()->setProperty("name", $name); |
84
|
|
|
return $checkbox;} |
85
|
|
|
); |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function fieldAsDropDown($index,$elements=[],$multiple=false,$name=NULL){ |
90
|
|
|
$this->setValueFunction($index,function($value) use($index,$elements,$multiple,$name){ |
91
|
|
|
$dd=new HtmlDropdown($this->_getFieldIdentifier("dd"),$value,$elements); |
92
|
|
|
if(isset($name)===false){ |
93
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
$dd->asSelect($name,$multiple); |
96
|
|
|
return $dd;} |
97
|
|
|
); |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
} |
It seems like you are assigning to a variable which was imported through a
use
statement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope