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
|
|
|
|
10
|
|
|
abstract class Widget extends HtmlDoubleElement { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string classname |
14
|
|
|
*/ |
15
|
|
|
protected $_model; |
16
|
|
|
protected $_modelInstance; |
17
|
|
|
/** |
18
|
|
|
* @var InstanceViewer |
19
|
|
|
*/ |
20
|
|
|
protected $_instanceViewer; |
21
|
|
|
/** |
22
|
|
|
* @var boolean |
23
|
|
|
*/ |
24
|
|
|
protected $_toolbar; |
25
|
|
|
/** |
26
|
|
|
* @var PositionInTable |
27
|
|
|
*/ |
28
|
|
|
protected $_toolbarPosition; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function __construct($identifier,$model,$modelInstance=NULL) { |
32
|
|
|
parent::__construct($identifier); |
33
|
|
|
$this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
34
|
|
|
$this->setModel($model); |
35
|
|
|
if(isset($modelInstance)); |
36
|
|
|
$this->show($modelInstance); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function show($modelInstance){ |
40
|
|
|
$this->_modelInstance=$modelInstance; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getModel() { |
44
|
|
|
return $this->_model; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setModel($_model) { |
48
|
|
|
$this->_model=$_model; |
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getInstanceViewer() { |
53
|
|
|
return $this->_instanceViewer; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setInstanceViewer($_instanceViewer) { |
57
|
|
|
$this->_instanceViewer=$_instanceViewer; |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public abstract function getHtmlComponent(); |
|
|
|
|
62
|
|
|
|
63
|
|
|
public function setColor($color){ |
64
|
|
|
return $this->getHtmlComponent()->setColor($color); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \Ajax\semantic\html\collections\menus\HtmlMenu |
69
|
|
|
*/ |
70
|
|
|
public function getToolbar(){ |
71
|
|
|
if(isset($this->_toolbar)===false){ |
72
|
|
|
$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
|
|
|
|
73
|
|
|
$this->_toolbar->setSecondary(); |
74
|
|
|
} |
75
|
|
|
return $this->_toolbar; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Adds a new element in toolbar |
80
|
|
|
* @param mixed $element |
81
|
|
|
* @return \Ajax\common\html\HtmlDoubleElement |
82
|
|
|
*/ |
83
|
|
|
public function addInToolbar($element){ |
84
|
|
|
$tb=$this->getToolbar(); |
85
|
|
|
return $tb->addItem($element); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function addItemInToolbar($caption,$icon=NULL){ |
89
|
|
|
$result=$this->addInToolbar($caption); |
90
|
|
|
$result->addIcon($icon); |
91
|
|
|
return $result; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function addButtonInToolbar($caption){ |
95
|
|
|
$bt=new HtmlButton("",$caption); |
96
|
|
|
return $this->addInToolbar($bt); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
100
|
|
|
$bt=new HtmlButton("",$caption); |
101
|
|
|
$bt->addIcon($icon,$before,$labeled); |
102
|
|
|
return $this->addInToolbar($bt); |
103
|
|
|
} |
104
|
|
|
} |