Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/control/PhabricatorObjectSelectorDialog.php
12241 views
1
<?php
2
3
final class PhabricatorObjectSelectorDialog extends Phobject {
4
5
private $user;
6
private $filters = array();
7
private $handles = array();
8
private $cancelURI;
9
private $submitURI;
10
private $searchURI;
11
private $selectedFilter;
12
private $excluded;
13
private $initialPHIDs;
14
private $maximumSelectionSize;
15
16
private $title;
17
private $header;
18
private $buttonText;
19
private $instructions;
20
21
public function setUser($user) {
22
$this->user = $user;
23
return $this;
24
}
25
26
public function setFilters(array $filters) {
27
$this->filters = $filters;
28
return $this;
29
}
30
31
public function setSelectedFilter($selected_filter) {
32
$this->selectedFilter = $selected_filter;
33
return $this;
34
}
35
36
public function setExcluded($excluded_phid) {
37
$this->excluded = $excluded_phid;
38
return $this;
39
}
40
41
public function setHandles(array $handles) {
42
assert_instances_of($handles, 'PhabricatorObjectHandle');
43
$this->handles = $handles;
44
return $this;
45
}
46
47
public function setCancelURI($cancel_uri) {
48
$this->cancelURI = $cancel_uri;
49
return $this;
50
}
51
52
public function setSubmitURI($submit_uri) {
53
$this->submitURI = $submit_uri;
54
return $this;
55
}
56
57
public function setSearchURI($search_uri) {
58
$this->searchURI = $search_uri;
59
return $this;
60
}
61
62
public function setTitle($title) {
63
$this->title = $title;
64
return $this;
65
}
66
67
public function setHeader($header) {
68
$this->header = $header;
69
return $this;
70
}
71
72
public function setButtonText($button_text) {
73
$this->buttonText = $button_text;
74
return $this;
75
}
76
77
public function setInstructions($instructions) {
78
$this->instructions = $instructions;
79
return $this;
80
}
81
82
public function setInitialPHIDs(array $initial_phids) {
83
$this->initialPHIDs = $initial_phids;
84
return $this;
85
}
86
87
public function getInitialPHIDs() {
88
return $this->initialPHIDs;
89
}
90
91
public function setMaximumSelectionSize($maximum_selection_size) {
92
$this->maximumSelectionSize = $maximum_selection_size;
93
return $this;
94
}
95
96
public function getMaximumSelectionSize() {
97
return $this->maximumSelectionSize;
98
}
99
100
public function buildDialog() {
101
$user = $this->user;
102
103
$filter_id = celerity_generate_unique_node_id();
104
$query_id = celerity_generate_unique_node_id();
105
$results_id = celerity_generate_unique_node_id();
106
$current_id = celerity_generate_unique_node_id();
107
$search_id = celerity_generate_unique_node_id();
108
$form_id = celerity_generate_unique_node_id();
109
110
require_celerity_resource('phabricator-object-selector-css');
111
112
$options = array();
113
foreach ($this->filters as $key => $label) {
114
$options[] = phutil_tag(
115
'option',
116
array(
117
'value' => $key,
118
'selected' => ($key == $this->selectedFilter)
119
? 'selected'
120
: null,
121
),
122
$label);
123
}
124
125
$instructions = null;
126
if ($this->instructions) {
127
$instructions = phutil_tag(
128
'p',
129
array('class' => 'phabricator-object-selector-instructions'),
130
$this->instructions);
131
}
132
133
$search_box = phabricator_form(
134
$user,
135
array(
136
'method' => 'POST',
137
'action' => $this->submitURI,
138
'id' => $search_id,
139
),
140
phutil_tag(
141
'table',
142
array('class' => 'phabricator-object-selector-search'),
143
phutil_tag('tr', array(), array(
144
phutil_tag(
145
'td',
146
array('class' => 'phabricator-object-selector-search-filter'),
147
phutil_tag('select', array('id' => $filter_id), $options)),
148
phutil_tag(
149
'td',
150
array('class' => 'phabricator-object-selector-search-text'),
151
phutil_tag('input', array('id' => $query_id, 'type' => 'text'))),
152
))));
153
154
$result_box = phutil_tag(
155
'div',
156
array(
157
'class' => 'phabricator-object-selector-results',
158
'id' => $results_id,
159
),
160
'');
161
162
$attached_box = phutil_tag_div(
163
'phabricator-object-selector-current',
164
phutil_tag_div(
165
'phabricator-object-selector-currently-attached',
166
array(
167
phutil_tag_div('phabricator-object-selector-header', $this->header),
168
phutil_tag('div', array('id' => $current_id)),
169
$instructions,
170
)));
171
172
$dialog = new AphrontDialogView();
173
$dialog
174
->setUser($this->user)
175
->setTitle($this->title)
176
->setClass('phabricator-object-selector-dialog')
177
->appendChild($search_box)
178
->appendChild($result_box)
179
->appendChild($attached_box)
180
->setRenderDialogAsDiv()
181
->setFormID($form_id)
182
->addSubmitButton($this->buttonText);
183
184
if ($this->cancelURI) {
185
$dialog->addCancelButton($this->cancelURI);
186
}
187
188
$handle_views = array();
189
foreach ($this->handles as $handle) {
190
$phid = $handle->getPHID();
191
$view = new PhabricatorHandleObjectSelectorDataView($handle);
192
$handle_views[$phid] = $view->renderData();
193
}
194
195
$dialog->addHiddenInput('phids', implode(';', array_keys($this->handles)));
196
197
$initial_phids = $this->getInitialPHIDs();
198
if ($initial_phids) {
199
$initial_phids = implode(', ', $initial_phids);
200
$dialog->addHiddenInput('initialPHIDs', $initial_phids);
201
}
202
203
$maximum = $this->getMaximumSelectionSize();
204
205
Javelin::initBehavior(
206
'phabricator-object-selector',
207
array(
208
'filter' => $filter_id,
209
'query' => $query_id,
210
'search' => $search_id,
211
'results' => $results_id,
212
'current' => $current_id,
213
'form' => $form_id,
214
'exclude' => $this->excluded,
215
'uri' => $this->searchURI,
216
'handles' => $handle_views,
217
'maximum' => $maximum,
218
));
219
220
$dialog->setResizeX(true);
221
$dialog->setResizeY($results_id);
222
223
return $dialog;
224
}
225
226
}
227
228