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\html\elements\HtmlLabel; |
11
|
|
|
use Ajax\semantic\html\modules\HtmlProgress; |
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
|
|
|
|
29
|
|
|
public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
30
|
|
|
$this->setValueFunction($index,function($value) use($label,$attributes){ |
31
|
|
|
$pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
32
|
|
|
return $pb; |
33
|
|
|
}); |
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function fieldAsLabel($index,$icon=NULL){ |
38
|
|
|
$this->setValueFunction($index,function($caption) use($icon){ |
39
|
|
|
$lbl=$this->_getLabelField($caption,$icon); |
40
|
|
|
return $lbl; |
41
|
|
|
}); |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
46
|
|
|
$this->setValueFunction($index,function($img) use($size,$circular){ |
47
|
|
|
$image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
48
|
|
|
return $image; |
49
|
|
|
}); |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function fieldAsAvatar($index){ |
54
|
|
|
$this->setValueFunction($index,function($img){return (new HtmlImage("",$img))->asAvatar();}); |
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function fieldAsRadio($index,$name=NULL){ |
59
|
|
|
$this->setValueFunction($index,function($value)use ($index,$name){ |
60
|
|
|
if(isset($name)===false){ |
61
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
$radio=new HtmlRadio($this->_getFieldIdentifier("radio"),$name,$value,$value); |
64
|
|
|
return $radio; |
65
|
|
|
}); |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public function fieldAsInput($index,$name=NULL,$type="text",$placeholder=""){ |
|
|
|
|
70
|
|
|
$this->setValueFunction($index,function($value) use($index,$name,$type,$placeholder){ |
71
|
|
|
$input=new HtmlInput($this->_getFieldIdentifier("input"),$type,$value,$placeholder); |
72
|
|
|
if(isset($name)===false){ |
73
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
74
|
|
|
} |
75
|
|
|
$input->getField()->setProperty("name", $name); |
76
|
|
|
return $input; |
77
|
|
|
}); |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function fieldAsCheckbox($index,$name=NULL){ |
|
|
|
|
82
|
|
|
$this->setValueFunction($index,function($value) use($index,$name){ |
83
|
|
|
$checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"),"",$value); |
84
|
|
|
$checkbox->setChecked(JString::isBooleanTrue($value)); |
85
|
|
|
if(isset($name)===false){ |
86
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
87
|
|
|
} |
88
|
|
|
$checkbox->getField()->setProperty("name", $name); |
89
|
|
|
return $checkbox; |
90
|
|
|
}); |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function fieldAsDropDown($index,$elements=[],$multiple=false,$name=NULL){ |
95
|
|
|
$this->setValueFunction($index,function($value) use($index,$elements,$multiple,$name){ |
96
|
|
|
$dd=new HtmlDropdown($this->_getFieldIdentifier("dd"),$value,$elements); |
97
|
|
|
if(isset($name)===false){ |
98
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
$dd->asSelect($name,$multiple); |
101
|
|
|
return $dd; |
102
|
|
|
}); |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
} |
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