3 final class PhabricatorObjectSelectorDialog
extends Phobject
{
6 private $filters = array();
7 private $handles = array();
11 private $selectedFilter;
13 private $initialPHIDs;
14 private $maximumSelectionSize;
19 private $instructions;
21 public function setUser($user) {
26 public function setFilters(array $filters) {
27 $this->filters
= $filters;
31 public function setSelectedFilter($selected_filter) {
32 $this->selectedFilter
= $selected_filter;
36 public function setExcluded($excluded_phid) {
37 $this->excluded
= $excluded_phid;
41 public function setHandles(array $handles) {
42 assert_instances_of($handles, 'PhabricatorObjectHandle');
43 $this->handles
= $handles;
47 public function setCancelURI($cancel_uri) {
48 $this->cancelURI
= $cancel_uri;
52 public function setSubmitURI($submit_uri) {
53 $this->submitURI
= $submit_uri;
57 public function setSearchURI($search_uri) {
58 $this->searchURI
= $search_uri;
62 public function setTitle($title) {
63 $this->title
= $title;
67 public function setHeader($header) {
68 $this->header
= $header;
72 public function setButtonText($button_text) {
73 $this->buttonText
= $button_text;
77 public function setInstructions($instructions) {
78 $this->instructions
= $instructions;
82 public function setInitialPHIDs(array $initial_phids) {
83 $this->initialPHIDs
= $initial_phids;
87 public function getInitialPHIDs() {
88 return $this->initialPHIDs
;
91 public function setMaximumSelectionSize($maximum_selection_size) {
92 $this->maximumSelectionSize
= $maximum_selection_size;
96 public function getMaximumSelectionSize() {
97 return $this->maximumSelectionSize
;
100 public function buildDialog() {
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();
110 require_celerity_resource('phabricator-object-selector-css');
113 foreach ($this->filters
as $key => $label) {
114 $options[] = phutil_tag(
118 'selected' => ($key == $this->selectedFilter
)
125 $instructions = null;
126 if ($this->instructions
) {
127 $instructions = phutil_tag(
129 array('class' => 'phabricator-object-selector-instructions'),
130 $this->instructions
);
133 $search_box = phabricator_form(
137 'action' => $this->submitURI
,
142 array('class' => 'phabricator-object-selector-search'),
143 phutil_tag('tr', array(), array(
146 array('class' => 'phabricator-object-selector-search-filter'),
147 phutil_tag('select', array('id' => $filter_id), $options)),
150 array('class' => 'phabricator-object-selector-search-text'),
151 phutil_tag('input', array('id' => $query_id, 'type' => 'text'))),
154 $result_box = phutil_tag(
157 'class' => 'phabricator-object-selector-results',
162 $attached_box = phutil_tag_div(
163 'phabricator-object-selector-current',
165 'phabricator-object-selector-currently-attached',
167 phutil_tag_div('phabricator-object-selector-header', $this->header
),
168 phutil_tag('div', array('id' => $current_id)),
172 $dialog = new AphrontDialogView();
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
);
184 if ($this->cancelURI
) {
185 $dialog->addCancelButton($this->cancelURI
);
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();
195 $dialog->addHiddenInput('phids', implode(';', array_keys($this->handles
)));
197 $initial_phids = $this->getInitialPHIDs();
198 if ($initial_phids) {
199 $initial_phids = implode(', ', $initial_phids);
200 $dialog->addHiddenInput('initialPHIDs', $initial_phids);
203 $maximum = $this->getMaximumSelectionSize();
205 Javelin
::initBehavior(
206 'phabricator-object-selector',
208 'filter' => $filter_id,
209 'query' => $query_id,
210 'search' => $search_id,
211 'results' => $results_id,
212 'current' => $current_id,
214 'exclude' => $this->excluded
,
215 'uri' => $this->searchURI
,
216 'handles' => $handle_views,
217 'maximum' => $maximum,
220 $dialog->setResizeX(true);
221 $dialog->setResizeY($results_id);