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