2011-01-16 22:51:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontFormView extends AphrontView {
|
|
|
|
|
|
|
|
private $action;
|
|
|
|
private $method = 'POST';
|
|
|
|
private $header;
|
|
|
|
private $data = array();
|
2011-01-23 03:33:00 +01:00
|
|
|
private $encType;
|
2011-01-31 03:52:29 +01:00
|
|
|
private $user;
|
2011-02-06 07:36:21 +01:00
|
|
|
private $workflow;
|
2011-03-23 01:08:08 +01:00
|
|
|
private $id;
|
2012-08-15 23:15:12 +02:00
|
|
|
private $flexible;
|
|
|
|
|
|
|
|
public function setFlexible($flexible) {
|
|
|
|
$this->flexible = $flexible;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-03-23 01:08:08 +01:00
|
|
|
|
|
|
|
public function setID($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-01-31 03:52:29 +01:00
|
|
|
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-01-16 22:51:39 +01:00
|
|
|
|
|
|
|
public function setAction($action) {
|
|
|
|
$this->action = $action;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMethod($method) {
|
|
|
|
$this->method = $method;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-23 03:33:00 +01:00
|
|
|
public function setEncType($enc_type) {
|
|
|
|
$this->encType = $enc_type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
public function addHiddenInput($key, $value) {
|
|
|
|
$this->data[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-06 07:36:21 +01:00
|
|
|
public function setWorkflow($workflow) {
|
|
|
|
$this->workflow = $workflow;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
public function render() {
|
2012-08-15 23:15:12 +02:00
|
|
|
if ($this->flexible) {
|
|
|
|
require_celerity_resource('phabricator-form-view-css');
|
|
|
|
}
|
2011-01-25 20:31:40 +01:00
|
|
|
require_celerity_resource('aphront-form-view-css');
|
2011-05-23 23:33:54 +02:00
|
|
|
|
2011-05-31 19:23:31 +02:00
|
|
|
Javelin::initBehavior('aphront-form-disable-on-submit');
|
2011-05-23 23:33:54 +02:00
|
|
|
|
2012-08-15 23:15:12 +02:00
|
|
|
$layout = new AphrontFormLayoutView();
|
|
|
|
|
|
|
|
if (!$this->flexible) {
|
|
|
|
$layout
|
|
|
|
->setBackgroundShading(true)
|
|
|
|
->setPadded(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$layout
|
2011-06-10 00:28:29 +02:00
|
|
|
->appendChild($this->renderDataInputs())
|
|
|
|
->appendChild($this->renderChildren());
|
|
|
|
|
2012-02-03 03:09:51 +01:00
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception('You must pass the user to AphrontFormView.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return phabricator_render_form(
|
|
|
|
$this->user,
|
2011-01-16 22:51:39 +01:00
|
|
|
array(
|
2012-08-15 23:15:12 +02:00
|
|
|
'class' => $this->flexible ? 'phabricator-form-view' : null,
|
2011-01-23 03:33:00 +01:00
|
|
|
'action' => $this->action,
|
|
|
|
'method' => $this->method,
|
|
|
|
'enctype' => $this->encType,
|
2011-02-06 07:36:21 +01:00
|
|
|
'sigil' => $this->workflow ? 'workflow' : null,
|
2011-03-23 01:08:08 +01:00
|
|
|
'id' => $this->id,
|
2011-01-16 22:51:39 +01:00
|
|
|
),
|
2011-06-10 00:28:29 +02:00
|
|
|
$layout->render());
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderDataInputs() {
|
|
|
|
$inputs = array();
|
2012-02-03 03:09:51 +01:00
|
|
|
foreach ($this->data as $key => $value) {
|
2011-01-26 02:17:19 +01:00
|
|
|
if ($value === null) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-16 22:51:39 +01:00
|
|
|
$inputs[] = phutil_render_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => $key,
|
|
|
|
'value' => $value,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return implode("\n", $inputs);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|