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
|
|
|
|
11
|
|
|
abstract class Widget extends HtmlDoubleElement { |
12
|
|
|
use FieldAsTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string classname |
16
|
|
|
*/ |
17
|
|
|
protected $_model; |
18
|
|
|
protected $_modelInstance; |
19
|
|
|
/** |
20
|
|
|
* @var InstanceViewer |
21
|
|
|
*/ |
22
|
|
|
protected $_instanceViewer; |
23
|
|
|
/** |
24
|
|
|
* @var boolean |
25
|
|
|
*/ |
26
|
|
|
protected $_toolbar; |
27
|
|
|
/** |
28
|
|
|
* @var PositionInTable |
29
|
|
|
*/ |
30
|
|
|
protected $_toolbarPosition; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function __construct($identifier,$model,$modelInstance=NULL) { |
34
|
|
|
parent::__construct($identifier); |
35
|
|
|
$this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
36
|
|
|
$this->setModel($model); |
37
|
|
|
if(isset($modelInstance)); |
38
|
|
|
$this->show($modelInstance); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function _getFieldIdentifier($prefix){ |
42
|
|
|
return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected abstract function _setToolbarPosition($table,$captions=NULL); |
|
|
|
|
46
|
|
|
|
47
|
|
|
public function show($modelInstance){ |
48
|
|
|
$this->_modelInstance=$modelInstance; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getModel() { |
52
|
|
|
return $this->_model; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setModel($_model) { |
56
|
|
|
$this->_model=$_model; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getInstanceViewer() { |
61
|
|
|
return $this->_instanceViewer; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setInstanceViewer($_instanceViewer) { |
65
|
|
|
$this->_instanceViewer=$_instanceViewer; |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public abstract function getHtmlComponent(); |
|
|
|
|
70
|
|
|
|
71
|
|
|
public function setColor($color){ |
72
|
|
|
return $this->getHtmlComponent()->setColor($color); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function setCaptions($captions){ |
77
|
|
|
$this->_instanceViewer->setCaptions($captions); |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setFields($fields){ |
82
|
|
|
$this->_instanceViewer->setVisibleProperties($fields); |
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function addField($field){ |
87
|
|
|
$this->_instanceViewer->addField($field); |
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function insertField($index,$field){ |
92
|
|
|
$this->_instanceViewer->insertField($index, $field); |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function insertInField($index,$field){ |
97
|
|
|
$this->_instanceViewer->insertInField($index, $field); |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setValueFunction($index,$callback){ |
102
|
|
|
$this->_instanceViewer->setValueFunction($index, $callback); |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setIdentifierFunction($callback){ |
107
|
|
|
$this->_instanceViewer->setIdentifierFunction($callback); |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return \Ajax\semantic\html\collections\menus\HtmlMenu |
113
|
|
|
*/ |
114
|
|
|
public function getToolbar(){ |
115
|
|
|
if(isset($this->_toolbar)===false){ |
116
|
|
|
$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
|
|
|
|
117
|
|
|
$this->_toolbar->setSecondary(); |
118
|
|
|
} |
119
|
|
|
return $this->_toolbar; |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Adds a new element in toolbar |
124
|
|
|
* @param mixed $element |
125
|
|
|
* @param callable $callback function to call on $element |
126
|
|
|
* @return \Ajax\common\html\HtmlDoubleElement |
127
|
|
|
*/ |
128
|
|
|
public function addInToolbar($element,$callback=NULL){ |
129
|
|
|
$tb=$this->getToolbar(); |
130
|
|
|
if(isset($callback)){ |
131
|
|
|
if(\is_callable($callback)){ |
132
|
|
|
$callback($element); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
return $tb->addItem($element); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function addItemInToolbar($caption,$icon=NULL){ |
139
|
|
|
$result=$this->addInToolbar($caption); |
140
|
|
|
$result->addIcon($icon); |
141
|
|
|
return $result; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function addButtonInToolbar($caption,$callback=NULL){ |
145
|
|
|
$bt=new HtmlButton("",$caption); |
146
|
|
|
return $this->addInToolbar($bt,$callback); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
150
|
|
|
$bt=new HtmlButton("",$caption); |
151
|
|
|
$bt->addIcon($icon,$before,$labeled); |
152
|
|
|
return $this->addInToolbar($bt); |
153
|
|
|
} |
154
|
|
|
} |