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
|
|
|
use Ajax\semantic\html\modules\HtmlRating; |
13
|
|
|
use Ajax\semantic\html\elements\HtmlHeader; |
14
|
|
|
/** |
15
|
|
|
* @author jc |
16
|
|
|
* @property InstanceViewer $_instanceViewer |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
trait FieldAsTrait{ |
20
|
|
|
|
21
|
|
|
abstract protected function _getFieldIdentifier($prefix); |
22
|
|
|
abstract public function setValueFunction($index,$callback); |
23
|
|
|
|
24
|
|
|
private function _getLabelField($caption,$icon=NULL){ |
25
|
|
|
$label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
26
|
|
|
return $label; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function _addRules($element,&$attributes){} |
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){ |
32
|
|
|
$this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback,$prefix){ |
33
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
34
|
|
|
if(isset($attributes["name"])===true){ |
35
|
|
|
$name=$attributes["name"]; |
36
|
|
|
} |
37
|
|
|
$element=$elementCallback($this->_getFieldIdentifier($prefix),$name,$value,""); |
38
|
|
|
if(\is_array($attributes)) |
39
|
|
|
$this->_applyAttributes($element, $attributes,$index); |
|
|
|
|
40
|
|
|
return $element; |
41
|
|
|
}); |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
View Code Duplication |
public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
|
|
|
47
|
|
|
$this->setValueFunction($index,function($value) use($label,$attributes){ |
48
|
|
|
$pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
49
|
|
|
return $pb; |
50
|
|
|
}); |
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function fieldAsRating($index,$max=5, $icon=""){ |
|
|
|
|
55
|
|
|
$this->setValueFunction($index,function($value) use($max,$icon){ |
56
|
|
|
$rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
57
|
|
|
return $rating; |
58
|
|
|
}); |
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function fieldAsLabel($index,$icon=NULL){ |
63
|
|
|
$this->setValueFunction($index,function($caption) use($icon){ |
64
|
|
|
$lbl=$this->_getLabelField($caption,$icon); |
65
|
|
|
return $lbl; |
66
|
|
|
}); |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
71
|
|
|
return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
72
|
|
|
$header=new HtmlHeader($id,$niveau,$value); |
73
|
|
|
if(isset($icon)) |
74
|
|
|
$header->asIcon($icon, $value); |
75
|
|
|
return $header; |
76
|
|
|
}, $index,$attributes,"header"); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
81
|
|
|
$this->setValueFunction($index,function($img) use($size,$circular){ |
82
|
|
|
$image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
83
|
|
|
return $image; |
84
|
|
|
}); |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function fieldAsAvatar($index,$attributes=NULL){ |
89
|
|
|
return $this->_fieldAs(function($id,$name,$value){ |
90
|
|
|
$img=new HtmlImage($id,$value); |
91
|
|
|
$img->asAvatar(); |
92
|
|
|
return $img; |
93
|
|
|
}, $index,$attributes,"avatar"); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function fieldAsRadio($index,$attributes=NULL){ |
97
|
|
|
return $this->_fieldAs(function($id,$name,$value){ |
98
|
|
|
$input= new HtmlRadio($id,$name,$value,$value); |
99
|
|
|
return $input; |
100
|
|
|
}, $index,$attributes,"radio"); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
View Code Duplication |
public function fieldAsInput($index,$attributes=NULL){ |
|
|
|
|
104
|
|
|
return $this->_fieldAs(function($id,$name,$value){ |
105
|
|
|
$input= new HtmlInput($id,"text",$value); |
106
|
|
|
//TODO check getField |
107
|
|
|
$input->setName($name); |
108
|
|
|
return $input; |
109
|
|
|
}, $index,$attributes,"input"); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function fieldAsHidden($index,$attributes=NULL){ |
113
|
|
|
if(\is_array($attributes)===false){ |
114
|
|
|
$attributes=[]; |
115
|
|
|
} |
116
|
|
|
$attributes["imputType"]="hidden"; |
117
|
|
|
return $this->fieldAsInput($index,$attributes); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function fieldAsCheckbox($index,$attributes=NULL){ |
121
|
|
|
return $this->_fieldAs(function($id,$name,$value){ |
122
|
|
|
$input=new HtmlCheckbox($id,"",$this->_instanceViewer->getIdentifier()); |
123
|
|
|
$input->setChecked(JString::isBooleanTrue($value)); |
124
|
|
|
$input->getField()->setProperty("name", $name); |
125
|
|
|
return $input; |
126
|
|
|
}, $index,$attributes,"ck"); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
View Code Duplication |
public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
|
|
|
130
|
|
|
return $this->_fieldAs(function($id,$name,$value) use($elements,$multiple){ |
131
|
|
|
$dd=new HtmlDropdown($id,$value,$elements); |
132
|
|
|
$dd->asSelect($name,$multiple); |
133
|
|
|
return $dd; |
134
|
|
|
}, $index,$attributes,"dd"); |
135
|
|
|
} |
136
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.