2013-08-26 20:53:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PHUIFormBoxView extends AphrontView {
|
|
|
|
|
|
|
|
private $headerText;
|
|
|
|
private $formError = null;
|
|
|
|
private $form;
|
2013-09-19 00:31:58 +02:00
|
|
|
private $validationException;
|
2013-08-26 20:53:11 +02:00
|
|
|
|
|
|
|
public function setHeaderText($text) {
|
|
|
|
$this->headerText = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFormError($error) {
|
|
|
|
$this->formError = $error;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-27 00:45:58 +02:00
|
|
|
public function setForm($form) {
|
2013-08-26 20:53:11 +02:00
|
|
|
$this->form = $form;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:31:58 +02:00
|
|
|
public function setValidationException(
|
|
|
|
PhabricatorApplicationTransactionValidationException $ex = null) {
|
|
|
|
$this->validationException = $ex;
|
|
|
|
return $this;
|
|
|
|
}
|
2013-08-26 20:53:11 +02:00
|
|
|
|
2013-09-19 00:31:58 +02:00
|
|
|
public function render() {
|
2013-08-26 20:53:11 +02:00
|
|
|
|
|
|
|
$header = id(new PhabricatorActionHeaderView())
|
|
|
|
->setHeaderTitle($this->headerText)
|
|
|
|
->setHeaderColor(PhabricatorActionHeaderView::HEADER_LIGHTBLUE);
|
|
|
|
|
2013-09-19 00:31:58 +02:00
|
|
|
$ex = $this->validationException;
|
|
|
|
$exception_errors = null;
|
|
|
|
if ($ex) {
|
|
|
|
$messages = array();
|
|
|
|
foreach ($ex->getErrors() as $error) {
|
|
|
|
$messages[] = $error->getMessage();
|
|
|
|
}
|
|
|
|
if ($messages) {
|
|
|
|
$exception_errors = id(new AphrontErrorView())
|
|
|
|
->setErrors($messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 20:53:11 +02:00
|
|
|
$content = id(new PHUIBoxView())
|
2013-09-19 00:31:58 +02:00
|
|
|
->appendChild(
|
|
|
|
array(
|
|
|
|
$header,
|
|
|
|
$this->formError,
|
|
|
|
$exception_errors,
|
|
|
|
$this->form,
|
|
|
|
))
|
2013-08-26 20:53:11 +02:00
|
|
|
->setBorder(true)
|
|
|
|
->addMargin(PHUI::MARGIN_LARGE_TOP)
|
|
|
|
->addMargin(PHUI::MARGIN_LARGE_LEFT)
|
|
|
|
->addMargin(PHUI::MARGIN_LARGE_RIGHT)
|
|
|
|
->addClass('phui-form-box');
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|