|
1
|
|
|
<?php |
|
2
|
|
|
namespace rtens\domin\delivery\web\renderers\dashboard\types; |
|
3
|
|
|
|
|
4
|
|
|
use rtens\domin\delivery\RendererRegistry; |
|
5
|
|
|
use rtens\domin\delivery\web\Element; |
|
6
|
|
|
use rtens\domin\delivery\web\HeadElements; |
|
7
|
|
|
use rtens\domin\delivery\web\renderers\dashboard\DashboardItem; |
|
8
|
|
|
use rtens\domin\delivery\web\WebRenderer; |
|
9
|
|
|
|
|
10
|
|
|
class Panel implements DashboardItem { |
|
11
|
|
|
|
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
private $heading; |
|
14
|
|
|
|
|
15
|
|
|
/** @var mixed */ |
|
16
|
|
|
private $content; |
|
17
|
|
|
|
|
18
|
|
|
/** @var array|Element[] */ |
|
19
|
|
|
public $rightHeading = []; |
|
20
|
|
|
|
|
21
|
|
|
/** @var null|string */ |
|
22
|
|
|
private $maxHeight; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $heading |
|
26
|
|
|
* @param mixed $content |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($heading, $content) { |
|
29
|
|
|
$this->heading = $heading; |
|
30
|
|
|
$this->content = $content; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param RendererRegistry $renderers |
|
35
|
|
|
* @return Element |
|
36
|
|
|
* @throws \Exception |
|
37
|
|
|
*/ |
|
38
|
|
|
public function render(RendererRegistry $renderers) { |
|
39
|
|
|
$content = [ |
|
40
|
|
|
new Element('div', ['class' => 'panel-heading'], [ |
|
41
|
|
|
$this->heading, |
|
42
|
|
|
new Element('div', ['class' => 'pull-right'], |
|
43
|
|
|
$this->rightHeading |
|
44
|
|
|
) |
|
45
|
|
|
]) |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
if ($this->maxHeight) { |
|
|
|
|
|
|
49
|
|
|
$content[] = new Element('div', [ |
|
50
|
|
|
'class' => 'panel-body', |
|
51
|
|
|
'style' => 'overflow-x: auto; overflow-y: hidden; max-height: ' . $this->maxHeight, |
|
52
|
|
|
'data-maxheight' => $this->maxHeight |
|
53
|
|
|
], [ |
|
54
|
|
|
$renderers->getRenderer($this->content)->render($this->content) |
|
55
|
|
|
]); |
|
56
|
|
|
$content[] = new Element('div', ['class' => 'panel-footer clearfix'], [ |
|
57
|
|
|
new Element('div', ['class' => 'pull-right'], [ |
|
58
|
|
|
new Element('a', [ |
|
59
|
|
|
'href' => 'javascript:', |
|
60
|
|
|
'onclick' => "var body = $(this).closest('.panel').find('.panel-body');" . |
|
61
|
|
|
"body.css('max-height', 'none');" . |
|
62
|
|
|
"body.css('overflow-y', 'visible');" . |
|
63
|
|
|
"$(this).hide(); " . |
|
64
|
|
|
"$(this).next().show();", |
|
65
|
|
|
'class' => 'show-all' |
|
66
|
|
|
], [ |
|
67
|
|
|
'Show all', |
|
68
|
|
|
new Element('span', ['class' => 'glyphicon glyphicon-chevron-down']) |
|
69
|
|
|
]), |
|
70
|
|
|
new Element('a', [ |
|
71
|
|
|
'href' => 'javascript:', |
|
72
|
|
|
'onclick' => "var body = $(this).closest('.panel').find('.panel-body');" . |
|
73
|
|
|
"body.css('max-height', body.data('maxheight'));" . |
|
74
|
|
|
"body.css('overflow-y', 'hidden');" . |
|
75
|
|
|
"$(this).hide();" . |
|
76
|
|
|
"$(this).prev().show();", |
|
77
|
|
|
'class' => 'show-less', |
|
78
|
|
|
'style' => 'display: none' |
|
79
|
|
|
], [ |
|
80
|
|
|
'Show less', |
|
81
|
|
|
new Element('span', ['class' => 'glyphicon glyphicon-chevron-up']) |
|
82
|
|
|
]) |
|
83
|
|
|
]) |
|
84
|
|
|
]); |
|
85
|
|
|
} else { |
|
86
|
|
|
$content[] = new Element('div', ['class' => 'panel-body'], [ |
|
87
|
|
|
$renderers->getRenderer($this->content)->render($this->content) |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return new Element('div', ['class' => 'panel panel-default'], $content); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param RendererRegistry $renderers |
|
96
|
|
|
* @return \rtens\domin\delivery\web\Element[] |
|
97
|
|
|
*/ |
|
98
|
|
|
public function headElements(RendererRegistry $renderers) { |
|
99
|
|
|
$elements = [HeadElements::jquery()]; |
|
100
|
|
|
|
|
101
|
|
|
$renderer = $renderers->getRenderer($this->content); |
|
102
|
|
|
if ($renderer instanceof WebRenderer) { |
|
103
|
|
|
$elements = array_merge($elements, $renderer->headElements($this->content)); |
|
104
|
|
|
} |
|
105
|
|
|
return $elements; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param array|Element[] $rightHeading |
|
110
|
|
|
* @return static |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setRightHeading(array $rightHeading) { |
|
113
|
|
|
$this->rightHeading = $rightHeading; |
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param string $height e.g. "20px" |
|
119
|
|
|
* @return static |
|
120
|
|
|
*/ |
|
121
|
|
|
public function setMaxHeight($height) { |
|
122
|
|
|
$this->maxHeight = $height; |
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
} |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: