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