2014-01-10 01:09:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectBoardEditController
|
2014-03-26 22:40:47 +01:00
|
|
|
extends PhabricatorProjectBoardController {
|
2014-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
private $projectID;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->projectID = $data['projectID'];
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->withIDs(array($this->projectID))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-03-26 22:40:47 +01:00
|
|
|
$this->setProject($project);
|
2014-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
$is_new = ($this->id ? false : true);
|
|
|
|
|
|
|
|
if (!$is_new) {
|
2014-01-12 03:16:26 +01:00
|
|
|
$column = id(new PhabricatorProjectColumnQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$column) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-01-10 01:09:38 +01:00
|
|
|
} else {
|
2014-01-13 06:40:02 +01:00
|
|
|
$column = PhabricatorProjectColumn::initializeNewColumn($viewer);
|
2014-01-10 01:09:38 +01:00
|
|
|
}
|
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$e_name = null;
|
|
|
|
$validation_exception = null;
|
|
|
|
$base_uri = '/board/'.$this->projectID.'/';
|
|
|
|
if ($is_new) {
|
|
|
|
// we want to go back to the board
|
|
|
|
$view_uri = $this->getApplicationURI($base_uri);
|
|
|
|
} else {
|
|
|
|
$view_uri = $this->getApplicationURI($base_uri.'column/'.$this->id.'/');
|
|
|
|
}
|
2014-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$new_name = $request->getStr('name');
|
|
|
|
|
2014-01-12 03:16:26 +01:00
|
|
|
if ($is_new) {
|
|
|
|
$column->setProjectPHID($project->getPHID());
|
|
|
|
$column->attachProject($project);
|
|
|
|
|
|
|
|
$columns = id(new PhabricatorProjectColumnQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withProjectPHIDs(array($project->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$new_sequence = 1;
|
|
|
|
if ($columns) {
|
|
|
|
$values = mpull($columns, 'getSequence');
|
|
|
|
$new_sequence = max($values) + 1;
|
|
|
|
}
|
|
|
|
$column->setSequence($new_sequence);
|
|
|
|
}
|
2014-01-10 01:09:38 +01:00
|
|
|
|
2014-03-26 22:40:47 +01:00
|
|
|
$type_name = PhabricatorProjectColumnTransaction::TYPE_NAME;
|
|
|
|
$xactions = array(id(new PhabricatorProjectColumnTransaction())
|
|
|
|
->setTransactionType($type_name)
|
|
|
|
->setNewValue($new_name));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor = id(new PhabricatorProjectColumnTransactionEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->applyTransactions($column, $xactions);
|
2014-01-10 01:09:38 +01:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
2014-03-26 22:40:47 +01:00
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$e_name = $ex->getShortMessage($type_name);
|
|
|
|
$validation_exception = $ex;
|
2014-01-10 01:09:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form->setUser($request->getUser())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setValue($column->getName())
|
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setName('name')
|
|
|
|
->setError($e_name)
|
|
|
|
->setCaption(
|
|
|
|
pht('This will be displayed as the header of the column.')));
|
|
|
|
|
|
|
|
if ($is_new) {
|
|
|
|
$title = pht('Create Column');
|
|
|
|
$submit = pht('Create Column');
|
2014-06-25 21:30:43 +02:00
|
|
|
$crumb_text = pht('Create Column');
|
2014-01-10 01:09:38 +01:00
|
|
|
} else {
|
2014-06-25 21:30:43 +02:00
|
|
|
$title = pht('Edit %s', $column->getDisplayName());
|
2014-01-10 01:09:38 +01:00
|
|
|
$submit = pht('Save Column');
|
2014-06-25 21:30:43 +02:00
|
|
|
$crumb_text = pht('Edit');
|
2014-01-10 01:09:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue($submit)
|
|
|
|
->addCancelButton($view_uri));
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2014-01-13 06:39:50 +01:00
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
pht('Board'),
|
|
|
|
$this->getApplicationURI('board/'.$project->getID().'/'));
|
2014-06-25 21:30:43 +02:00
|
|
|
|
|
|
|
if (!$is_new) {
|
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
$column->getDisplayName(),
|
|
|
|
$view_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$crumbs->addTextCrumb($crumb_text);
|
2014-01-10 01:09:38 +01:00
|
|
|
|
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText($title)
|
2014-03-26 22:40:47 +01:00
|
|
|
->setValidationException($validation_exception)
|
2014-01-10 01:09:38 +01:00
|
|
|
->setForm($form);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$form_box,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|