Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/control/AphrontTokenizerTemplateView.php
12241 views
1
<?php
2
3
final class AphrontTokenizerTemplateView extends AphrontView {
4
5
private $value;
6
private $name;
7
private $id;
8
private $browseURI;
9
private $initialValue;
10
11
public function setBrowseURI($browse_uri) {
12
$this->browseURI = $browse_uri;
13
return $this;
14
}
15
16
public function setID($id) {
17
$this->id = $id;
18
return $this;
19
}
20
21
public function setValue(array $value) {
22
assert_instances_of($value, 'PhabricatorTypeaheadTokenView');
23
$this->value = $value;
24
return $this;
25
}
26
27
public function getValue() {
28
return $this->value;
29
}
30
31
public function setName($name) {
32
$this->name = $name;
33
return $this;
34
}
35
36
public function getName() {
37
return $this->name;
38
}
39
40
public function setInitialValue(array $initial_value) {
41
$this->initialValue = $initial_value;
42
return $this;
43
}
44
45
public function getInitialValue() {
46
return $this->initialValue;
47
}
48
49
public function render() {
50
require_celerity_resource('aphront-tokenizer-control-css');
51
52
$id = $this->id;
53
$name = $this->getName();
54
$tokens = nonempty($this->getValue(), array());
55
56
$input = javelin_tag(
57
'input',
58
array(
59
'mustcapture' => true,
60
'name' => $name,
61
'class' => 'jx-tokenizer-input',
62
'sigil' => 'tokenizer-input',
63
'style' => 'width: 0px;',
64
'disabled' => 'disabled',
65
'type' => 'text',
66
));
67
68
$content = $tokens;
69
$content[] = $input;
70
$content[] = phutil_tag('div', array('style' => 'clear: both;'), '');
71
72
$container = javelin_tag(
73
'div',
74
array(
75
'id' => $id,
76
'class' => 'jx-tokenizer-container',
77
'sigil' => 'tokenizer-container',
78
),
79
$content);
80
81
$icon = id(new PHUIIconView())
82
->setIcon('fa-search');
83
84
$browse = id(new PHUIButtonView())
85
->setTag('a')
86
->setIcon($icon)
87
->addClass('tokenizer-browse-button')
88
->setColor(PHUIButtonView::GREY)
89
->addSigil('tokenizer-browse');
90
91
$classes = array();
92
$classes[] = 'jx-tokenizer-frame';
93
94
if ($this->browseURI) {
95
$classes[] = 'has-browse';
96
}
97
98
$initial = array();
99
$initial_value = $this->getInitialValue();
100
if ($initial_value) {
101
foreach ($this->getInitialValue() as $value) {
102
$initial[] = phutil_tag(
103
'input',
104
array(
105
'type' => 'hidden',
106
'name' => $name.'.initial[]',
107
'value' => $value,
108
));
109
}
110
}
111
112
$frame = javelin_tag(
113
'div',
114
array(
115
'class' => implode(' ', $classes),
116
'sigil' => 'tokenizer-frame',
117
),
118
array(
119
$container,
120
$browse,
121
$initial,
122
));
123
124
return $frame;
125
}
126
127
}
128
129