|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\common; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\common\html\HtmlDoubleElement; |
|
6
|
|
|
use Ajax\semantic\html\elements\HtmlButton; |
|
7
|
|
|
use Ajax\semantic\widgets\datatable\PositionInTable; |
|
8
|
|
|
use Ajax\semantic\html\collections\menus\HtmlMenu; |
|
9
|
|
|
use Ajax\semantic\widgets\base\FieldAsTrait; |
|
10
|
|
|
use Ajax\semantic\html\elements\HtmlButtonGroups; |
|
11
|
|
|
use Ajax\semantic\widgets\base\InstanceViewer; |
|
12
|
|
|
use Ajax\semantic\html\modules\HtmlDropdown; |
|
13
|
|
|
use Ajax\service\JArray; |
|
14
|
|
|
|
|
15
|
|
|
abstract class Widget extends HtmlDoubleElement { |
|
16
|
|
|
use FieldAsTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string classname |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $_model; |
|
22
|
|
|
protected $_modelInstance; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var InstanceViewer |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $_instanceViewer; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var boolean |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $_toolbar; |
|
31
|
|
|
/** |
|
32
|
|
|
* @var PositionInTable |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $_toolbarPosition; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function __construct($identifier,$model,$modelInstance=NULL) { |
|
38
|
|
|
parent::__construct($identifier); |
|
39
|
|
|
$this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
|
40
|
|
|
$this->setModel($model); |
|
41
|
|
|
if(isset($modelInstance)); |
|
42
|
|
|
$this->show($modelInstance); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function _getFieldIdentifier($prefix){ |
|
46
|
|
|
return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
50
|
|
|
|
|
51
|
|
|
public function show($modelInstance){ |
|
52
|
|
|
$this->_modelInstance=$modelInstance; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getModel() { |
|
56
|
|
|
return $this->_model; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function setModel($_model) { |
|
60
|
|
|
$this->_model=$_model; |
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getInstanceViewer() { |
|
65
|
|
|
return $this->_instanceViewer; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function setInstanceViewer($_instanceViewer) { |
|
69
|
|
|
$this->_instanceViewer=$_instanceViewer; |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public abstract function getHtmlComponent(); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
public function setColor($color){ |
|
76
|
|
|
return $this->getHtmlComponent()->setColor($color); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function setCaptions($captions){ |
|
81
|
|
|
$this->_instanceViewer->setCaptions($captions); |
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function setFields($fields){ |
|
86
|
|
|
$this->_instanceViewer->setVisibleProperties($fields); |
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function addField($field){ |
|
91
|
|
|
$this->_instanceViewer->addField($field); |
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function insertField($index,$field){ |
|
96
|
|
|
$this->_instanceViewer->insertField($index, $field); |
|
97
|
|
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function insertInField($index,$field){ |
|
101
|
|
|
$this->_instanceViewer->insertInField($index, $field); |
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function setValueFunction($index,$callback){ |
|
106
|
|
|
$this->_instanceViewer->setValueFunction($index, $callback); |
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function setIdentifierFunction($callback){ |
|
111
|
|
|
$this->_instanceViewer->setIdentifierFunction($callback); |
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return \Ajax\semantic\html\collections\menus\HtmlMenu |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getToolbar(){ |
|
119
|
|
|
if(isset($this->_toolbar)===false){ |
|
120
|
|
|
$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
|
|
|
|
|
|
121
|
|
|
//$this->_toolbar->setSecondary(); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
return $this->_toolbar; |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Adds a new element in toolbar |
|
128
|
|
|
* @param mixed $element |
|
129
|
|
|
* @param callable $callback function to call on $element |
|
130
|
|
|
* @return \Ajax\common\html\HtmlDoubleElement |
|
131
|
|
|
*/ |
|
132
|
|
|
public function addInToolbar($element,$callback=NULL){ |
|
133
|
|
|
$tb=$this->getToolbar(); |
|
134
|
|
|
if(isset($callback)){ |
|
135
|
|
|
if(\is_callable($callback)){ |
|
136
|
|
|
$callback($element); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
return $tb->addItem($element); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
143
|
|
|
$result=$this->addInToolbar($caption,$callback); |
|
144
|
|
|
if(isset($icon)) |
|
145
|
|
|
$result->addIcon($icon); |
|
146
|
|
|
return $result; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function addItemsInToolbar(array $items,$callback=NULL){ |
|
150
|
|
|
if(JArray::isAssociative($items)){ |
|
151
|
|
|
foreach ($items as $icon=>$item){ |
|
152
|
|
|
$this->addItemInToolbar($item,$icon,$callback); |
|
153
|
|
|
} |
|
154
|
|
|
}else{ |
|
155
|
|
|
foreach ($items as $item){ |
|
156
|
|
|
$this->addItemInToolbar($item,null,$callback); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
return $this; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
View Code Duplication |
public function addDropdownInToolbar($value,$items=NULL,$callback=NULL){ |
|
|
|
|
|
|
163
|
|
|
$dd=$value; |
|
164
|
|
|
if (\is_string($value)) { |
|
165
|
|
|
$dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
166
|
|
|
} |
|
167
|
|
|
return $this->addInToolbar($dd,$callback); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function addButtonInToolbar($caption,$callback=NULL){ |
|
171
|
|
|
$bt=new HtmlButton("",$caption); |
|
172
|
|
|
return $this->addInToolbar($bt,$callback); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
176
|
|
|
$bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
177
|
|
|
return $this->addInToolbar($bts,$callback); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
181
|
|
|
$bt=new HtmlButton("",$caption); |
|
182
|
|
|
$bt->addIcon($icon,$before,$labeled); |
|
183
|
|
|
return $this->addInToolbar($bt); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Defines a callback function to call for modifying captions |
|
188
|
|
|
* function parameters are $captions: the captions to modify and $instance: the active model instance |
|
189
|
|
|
* @param callable $captionCallback |
|
190
|
|
|
* @return Widget |
|
191
|
|
|
*/ |
|
192
|
|
|
public function setCaptionCallback($captionCallback) { |
|
193
|
|
|
$this->_instanceViewer->setCaptionCallback($captionCallback); |
|
194
|
|
|
return $this; |
|
195
|
|
|
} |
|
196
|
|
|
} |