Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / view / control / AphrontTokenizerTemplateView.php
blobfacab93497ee83619e7ad471742d85524bcff0fa
1 <?php
3 final class AphrontTokenizerTemplateView extends AphrontView {
5 private $value;
6 private $name;
7 private $id;
8 private $browseURI;
9 private $initialValue;
11 public function setBrowseURI($browse_uri) {
12 $this->browseURI = $browse_uri;
13 return $this;
16 public function setID($id) {
17 $this->id = $id;
18 return $this;
21 public function setValue(array $value) {
22 assert_instances_of($value, 'PhabricatorTypeaheadTokenView');
23 $this->value = $value;
24 return $this;
27 public function getValue() {
28 return $this->value;
31 public function setName($name) {
32 $this->name = $name;
33 return $this;
36 public function getName() {
37 return $this->name;
40 public function setInitialValue(array $initial_value) {
41 $this->initialValue = $initial_value;
42 return $this;
45 public function getInitialValue() {
46 return $this->initialValue;
49 public function render() {
50 require_celerity_resource('aphront-tokenizer-control-css');
52 $id = $this->id;
53 $name = $this->getName();
54 $tokens = nonempty($this->getValue(), array());
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 ));
68 $content = $tokens;
69 $content[] = $input;
70 $content[] = phutil_tag('div', array('style' => 'clear: both;'), '');
72 $container = javelin_tag(
73 'div',
74 array(
75 'id' => $id,
76 'class' => 'jx-tokenizer-container',
77 'sigil' => 'tokenizer-container',
79 $content);
81 $icon = id(new PHUIIconView())
82 ->setIcon('fa-search');
84 $browse = id(new PHUIButtonView())
85 ->setTag('a')
86 ->setIcon($icon)
87 ->addClass('tokenizer-browse-button')
88 ->setColor(PHUIButtonView::GREY)
89 ->addSigil('tokenizer-browse');
91 $classes = array();
92 $classes[] = 'jx-tokenizer-frame';
94 if ($this->browseURI) {
95 $classes[] = 'has-browse';
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,
112 $frame = javelin_tag(
113 'div',
114 array(
115 'class' => implode(' ', $classes),
116 'sigil' => 'tokenizer-frame',
118 array(
119 $container,
120 $browse,
121 $initial,
124 return $frame;