Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUIRemarkupPreviewPanel.php
12249 views
1
<?php
2
3
/**
4
* Render a simple preview panel for a bound Remarkup text control.
5
*/
6
final class PHUIRemarkupPreviewPanel extends AphrontTagView {
7
8
private $header;
9
private $loadingText;
10
private $controlID;
11
private $previewURI;
12
private $previewType;
13
14
const DOCUMENT = 'document';
15
16
protected function canAppendChild() {
17
return false;
18
}
19
20
public function setPreviewURI($preview_uri) {
21
$this->previewURI = $preview_uri;
22
return $this;
23
}
24
25
public function setControlID($control_id) {
26
$this->controlID = $control_id;
27
return $this;
28
}
29
30
public function setHeader($header) {
31
$this->header = $header;
32
return $this;
33
}
34
35
public function setLoadingText($loading_text) {
36
$this->loadingText = $loading_text;
37
return $this;
38
}
39
40
public function setPreviewType($type) {
41
$this->previewType = $type;
42
return $this;
43
}
44
45
protected function getTagName() {
46
return 'div';
47
}
48
49
protected function getTagAttributes() {
50
$classes = array();
51
$classes[] = 'phui-remarkup-preview';
52
53
return array(
54
'class' => $classes,
55
);
56
}
57
58
protected function getTagContent() {
59
if ($this->previewURI === null) {
60
throw new PhutilInvalidStateException('setPreviewURI');
61
}
62
if ($this->controlID === null) {
63
throw new PhutilInvalidStateException('setControlID');
64
}
65
66
$preview_id = celerity_generate_unique_node_id();
67
68
require_celerity_resource('phui-remarkup-preview-css');
69
Javelin::initBehavior(
70
'remarkup-preview',
71
array(
72
'previewID' => $preview_id,
73
'controlID' => $this->controlID,
74
'uri' => $this->previewURI,
75
));
76
77
$loading = phutil_tag(
78
'div',
79
array(
80
'class' => 'phui-preview-loading-text',
81
),
82
nonempty($this->loadingText, pht('Loading preview...')));
83
84
$preview = phutil_tag(
85
'div',
86
array(
87
'id' => $preview_id,
88
'class' => 'phabricator-remarkup phui-preview-body',
89
),
90
$loading);
91
92
if (!$this->previewType) {
93
$header = null;
94
if ($this->header) {
95
$header = phutil_tag(
96
'div',
97
array(
98
'class' => 'phui-preview-header',
99
),
100
$this->header);
101
}
102
$content = array($header, $preview);
103
104
} else if ($this->previewType == self::DOCUMENT) {
105
$header = id(new PHUIHeaderView())
106
->setHeader(pht('%s (Preview)', $this->header));
107
108
$content = id(new PHUIDocumentView())
109
->setHeader($header)
110
->appendChild($preview);
111
}
112
113
return id(new PHUIObjectBoxView())
114
->appendChild($content)
115
->setCollapsed(true);
116
}
117
118
}
119
120