2011-01-16 13:51:39 -08:00
|
|
|
<?php
|
|
|
|
|
2015-03-01 14:45:56 -08:00
|
|
|
final class PHUIInfoView extends AphrontView {
|
2011-01-16 13:51:39 -08:00
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
const SEVERITY_ERROR = 'error';
|
|
|
|
const SEVERITY_WARNING = 'warning';
|
2011-02-05 22:36:21 -08:00
|
|
|
const SEVERITY_NOTICE = 'notice';
|
2012-02-27 19:21:41 -08:00
|
|
|
const SEVERITY_NODATA = 'nodata';
|
2015-02-23 11:03:09 -08:00
|
|
|
const SEVERITY_SUCCESS = 'success';
|
2011-02-05 16:43:28 -08:00
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
private $title;
|
|
|
|
private $errors;
|
2011-02-05 16:43:28 -08:00
|
|
|
private $severity;
|
2011-06-09 18:56:47 -07:00
|
|
|
private $id;
|
2015-02-23 11:03:09 -08:00
|
|
|
private $buttons = array();
|
2011-01-16 13:51:39 -08:00
|
|
|
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
public function setSeverity($severity) {
|
|
|
|
$this->severity = $severity;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
public function setErrors(array $errors) {
|
|
|
|
$this->errors = $errors;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-06-09 18:56:47 -07:00
|
|
|
public function setID($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-03-02 09:01:04 -08:00
|
|
|
public function addButton(PHUIButtonView $button) {
|
|
|
|
|
2015-02-23 11:03:09 -08:00
|
|
|
$this->buttons[] = $button;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-05-20 07:06:07 +10:00
|
|
|
public function render() {
|
2015-03-01 14:45:56 -08:00
|
|
|
require_celerity_resource('phui-info-view-css');
|
2011-02-05 16:43:28 -08:00
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
$errors = $this->errors;
|
|
|
|
if ($errors) {
|
|
|
|
$list = array();
|
|
|
|
foreach ($errors as $error) {
|
2013-01-17 18:43:35 -08:00
|
|
|
$list[] = phutil_tag(
|
2011-01-16 13:51:39 -08:00
|
|
|
'li',
|
|
|
|
array(),
|
2013-01-17 18:43:35 -08:00
|
|
|
$error);
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
2013-01-18 00:32:58 -08:00
|
|
|
$list = phutil_tag(
|
2012-09-11 09:55:27 -07:00
|
|
|
'ul',
|
|
|
|
array(
|
2015-03-01 14:45:56 -08:00
|
|
|
'class' => 'phui-info-view-list',
|
2012-09-11 09:55:27 -07:00
|
|
|
),
|
2013-01-18 00:32:58 -08:00
|
|
|
$list);
|
2011-01-16 13:51:39 -08:00
|
|
|
} else {
|
|
|
|
$list = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $this->title;
|
|
|
|
if (strlen($title)) {
|
2013-01-17 18:43:35 -08:00
|
|
|
$title = phutil_tag(
|
2012-09-11 09:55:27 -07:00
|
|
|
'h1',
|
|
|
|
array(
|
2015-03-01 14:45:56 -08:00
|
|
|
'class' => 'phui-info-view-head',
|
2012-09-11 09:55:27 -07:00
|
|
|
),
|
2013-01-17 18:43:35 -08:00
|
|
|
$title);
|
2011-01-16 13:51:39 -08:00
|
|
|
} else {
|
|
|
|
$title = null;
|
|
|
|
}
|
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
$this->severity = nonempty($this->severity, self::SEVERITY_ERROR);
|
|
|
|
|
2013-01-26 17:14:58 -08:00
|
|
|
$classes = array();
|
2015-03-01 14:45:56 -08:00
|
|
|
$classes[] = 'phui-info-view';
|
|
|
|
$classes[] = 'phui-info-severity-'.$this->severity;
|
2015-02-23 11:03:09 -08:00
|
|
|
$classes[] = 'grouped';
|
2013-01-26 17:14:58 -08:00
|
|
|
$classes = implode(' ', $classes);
|
2011-02-05 16:43:28 -08:00
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
$children = $this->renderChildren();
|
2015-02-01 20:14:56 -08:00
|
|
|
if ($list) {
|
|
|
|
$children[] = $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
$body = null;
|
|
|
|
if (!empty($children)) {
|
|
|
|
$body = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2015-03-01 14:45:56 -08:00
|
|
|
'class' => 'phui-info-view-body',
|
2015-02-01 20:14:56 -08:00
|
|
|
),
|
|
|
|
$children);
|
|
|
|
}
|
2013-02-06 16:53:49 -08:00
|
|
|
|
2015-02-23 11:03:09 -08:00
|
|
|
$buttons = null;
|
|
|
|
if (!empty($this->buttons)) {
|
|
|
|
$buttons = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2015-03-01 14:45:56 -08:00
|
|
|
'class' => 'phui-info-view-actions',
|
2015-02-23 11:03:09 -08:00
|
|
|
),
|
|
|
|
$this->buttons);
|
|
|
|
}
|
|
|
|
|
2013-02-06 16:53:49 -08:00
|
|
|
return phutil_tag(
|
2012-10-16 09:44:43 -07:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $this->id,
|
2013-01-26 17:14:58 -08:00
|
|
|
'class' => $classes,
|
2012-10-16 09:44:43 -07:00
|
|
|
),
|
2013-01-18 00:32:58 -08:00
|
|
|
array(
|
2015-02-23 11:03:09 -08:00
|
|
|
$buttons,
|
2013-01-18 00:32:58 -08:00
|
|
|
$title,
|
2015-02-01 20:14:56 -08:00
|
|
|
$body,
|
2013-01-18 00:32:58 -08:00
|
|
|
));
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
|
|
|
}
|