Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / PHUIObjectBoxView.php
blob4d421874790b404cfe3be7517046f520d1dadb1a
1 <?php
3 final class PHUIObjectBoxView extends AphrontTagView {
5 private $headerText;
6 private $color;
7 private $background;
8 private $tabGroups = array();
9 private $formErrors = null;
10 private $infoView;
11 private $form;
12 private $validationException;
13 private $header;
14 private $flush;
15 private $actionListID;
16 private $objectList;
17 private $table;
18 private $collapsed = false;
19 private $anchor;
20 private $pager;
22 private $showAction;
23 private $hideAction;
24 private $showHideHref;
25 private $showHideContent;
26 private $showHideOpen;
28 private $propertyLists = array();
29 private $tailButtons = array();
31 const COLOR_RED = 'red';
32 const COLOR_BLUE = 'blue';
33 const COLOR_GREEN = 'green';
34 const COLOR_YELLOW = 'yellow';
36 const BLUE = 'phui-box-blue';
37 const BLUE_PROPERTY = 'phui-box-blue-property';
38 const WHITE_CONFIG = 'phui-box-white-config';
39 const GREY = 'phui-box-grey';
41 public function addPropertyList(PHUIPropertyListView $property_list) {
42 $this->propertyLists[] = $property_list;
44 $action_list = $property_list->getActionList();
45 if ($action_list) {
46 $this->actionListID = celerity_generate_unique_node_id();
47 $action_list->setId($this->actionListID);
50 return $this;
53 public function setHeaderText($text) {
54 $this->headerText = $text;
55 return $this;
58 public function setColor($color) {
59 $this->color = $color;
60 return $this;
63 public function setBackground($color) {
64 $this->background = $color;
65 return $this;
68 public function setFormErrors(array $errors, $title = null) {
69 if ($errors) {
70 $this->formErrors = id(new PHUIInfoView())
71 ->setTitle($title)
72 ->setErrors($errors);
74 return $this;
77 public function addTabGroup(PHUITabGroupView $view) {
78 $this->tabGroups[] = $view;
79 return $this;
82 public function setInfoView(PHUIInfoView $view) {
83 $this->infoView = $view;
84 return $this;
87 public function setForm($form) {
88 $this->form = $form;
89 return $this;
92 public function setHeader($header) {
93 $this->header = $header;
94 return $this;
97 public function setFlush($flush) {
98 $this->flush = $flush;
99 return $this;
102 public function setObjectList($list) {
103 $this->objectList = $list;
104 return $this;
107 public function setTable($table) {
108 $this->collapsed = true;
109 $this->table = $table;
110 return $this;
113 public function setCollapsed($collapsed) {
114 $this->collapsed = $collapsed;
115 return $this;
118 public function setPager(PHUIPagerView $pager) {
119 $this->pager = $pager;
120 return $this;
123 public function setAnchor(PhabricatorAnchorView $anchor) {
124 $this->anchor = $anchor;
125 return $this;
128 public function setShowHide($show, $hide, $content, $href, $open = false) {
129 $this->showAction = $show;
130 $this->hideAction = $hide;
131 $this->showHideContent = $content;
132 $this->showHideHref = $href;
133 $this->showHideOpen = $open;
134 return $this;
137 public function setValidationException(
138 PhabricatorApplicationTransactionValidationException $ex = null) {
139 $this->validationException = $ex;
140 return $this;
143 public function newTailButton() {
144 $button = id(new PHUIButtonView())
145 ->setTag('a')
146 ->setColor(PHUIButtonView::GREY);
148 $this->tailButtons[] = $button;
150 return $button;
153 protected function getTagAttributes() {
154 $classes = array();
155 $classes[] = 'phui-box';
156 $classes[] = 'phui-box-border';
157 $classes[] = 'phui-object-box';
158 $classes[] = 'mlt mll mlr';
160 if ($this->color) {
161 $classes[] = 'phui-object-box-'.$this->color;
164 if ($this->collapsed) {
165 $classes[] = 'phui-object-box-collapsed';
168 if ($this->flush) {
169 $classes[] = 'phui-object-box-flush';
172 if ($this->background) {
173 $classes[] = $this->background;
176 return array(
177 'class' => implode(' ', $classes),
181 protected function getTagContent() {
182 require_celerity_resource('phui-box-css');
183 require_celerity_resource('phui-object-box-css');
185 $header = $this->header;
187 if ($this->headerText) {
188 $header = id(new PHUIHeaderView())
189 ->setHeader($this->headerText);
192 $showhide = null;
193 if ($this->showAction !== null) {
194 if (!$header) {
195 $header = id(new PHUIHeaderView());
198 Javelin::initBehavior('phabricator-reveal-content');
200 $hide_action_id = celerity_generate_unique_node_id();
201 $show_action_id = celerity_generate_unique_node_id();
202 $content_id = celerity_generate_unique_node_id();
204 $hide_style = ($this->showHideOpen ? 'display: none;': null);
205 $show_style = ($this->showHideOpen ? null : 'display: none;');
206 $hide_action = id(new PHUIButtonView())
207 ->setTag('a')
208 ->addSigil('reveal-content')
209 ->setID($hide_action_id)
210 ->setStyle($hide_style)
211 ->setIcon('fa-search')
212 ->setHref($this->showHideHref)
213 ->setMetaData(
214 array(
215 'hideIDs' => array($hide_action_id),
216 'showIDs' => array($content_id, $show_action_id),
218 ->setText($this->showAction);
220 $show_action = id(new PHUIButtonView())
221 ->setTag('a')
222 ->addSigil('reveal-content')
223 ->setStyle($show_style)
224 ->setIcon('fa-search')
225 ->setHref('#')
226 ->setID($show_action_id)
227 ->setMetaData(
228 array(
229 'hideIDs' => array($content_id, $show_action_id),
230 'showIDs' => array($hide_action_id),
232 ->setText($this->hideAction);
234 $header->addActionLink($hide_action);
235 $header->addActionLink($show_action);
237 $showhide = array(
238 phutil_tag(
239 'div',
240 array(
241 'class' => 'phui-object-box-hidden-content',
242 'id' => $content_id,
243 'style' => $show_style,
245 $this->showHideContent),
250 if ($this->actionListID) {
251 $icon_id = celerity_generate_unique_node_id();
252 $icon = id(new PHUIIconView())
253 ->setIcon('fa-bars');
254 $meta = array(
255 'map' => array(
256 $this->actionListID => 'phabricator-action-list-toggle',
257 $icon_id => 'phuix-dropdown-open',
260 $mobile_menu = id(new PHUIButtonView())
261 ->setTag('a')
262 ->setText(pht('Actions'))
263 ->setHref('#')
264 ->setIcon($icon)
265 ->addClass('phui-mobile-menu')
266 ->setID($icon_id)
267 ->addSigil('jx-toggle-class')
268 ->setMetadata($meta);
269 $header->addActionLink($mobile_menu);
272 $ex = $this->validationException;
273 $exception_errors = null;
274 if ($ex) {
275 $messages = array();
276 foreach ($ex->getErrors() as $error) {
277 $messages[] = $error->getMessage();
279 if ($messages) {
280 $exception_errors = id(new PHUIInfoView())
281 ->setErrors($messages);
285 if ($this->propertyLists) {
286 $lists = new PHUIPropertyGroupView();
288 $ii = 0;
289 foreach ($this->propertyLists as $list) {
290 if ($ii > 0 || $this->tabGroups) {
291 $list->addClass('phui-property-list-section-noninitial');
294 $lists->addPropertyList($list);
295 $ii++;
297 } else {
298 $lists = null;
301 $pager = null;
302 if ($this->pager) {
303 if ($this->pager->willShowPagingControls()) {
304 $pager = phutil_tag_div('phui-object-box-pager', $this->pager);
308 $content = array(
309 ($this->showHideOpen == false ? $this->anchor : null),
310 $header,
311 $this->infoView,
312 $this->formErrors,
313 $exception_errors,
314 $this->form,
315 $this->tabGroups,
316 $showhide,
317 ($this->showHideOpen == true ? $this->anchor : null),
318 $lists,
319 $this->table,
320 $pager,
321 $this->renderChildren(),
324 if ($this->objectList) {
325 $content[] = $this->objectList;
328 if ($this->tailButtons) {
329 $content[] = phutil_tag(
330 'div',
331 array(
332 'class' => 'phui-object-box-tail-buttons',
334 $this->tailButtons);
337 return $content;