Differential D9719 Diff 23354 src/applications/project/controller/PhabricatorProjectBoardDeleteController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectBoardDeleteController.php
Show All 35 Lines | $column = id(new PhabricatorProjectColumnQuery()) | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT)) | PhabricatorPolicyCapability::CAN_EDIT)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$column) { | if (!$column) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$error_view = null; | |||||
$column_phid = $column->getPHID(); | $column_phid = $column->getPHID(); | ||||
$has_task_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
$column_phid, | |||||
PhabricatorEdgeConfig::TYPE_COLUMN_HAS_OBJECT); | |||||
if ($has_task_phids) { | |||||
$error_view = id(new AphrontErrorView()) | |||||
->setTitle(pht('Column has Tasks!')); | |||||
if ($column->isDeleted()) { | |||||
$error_view->setErrors(array(pht( | |||||
'A column can not be activated if it has tasks '. | |||||
'in it. Please remove the tasks and try again.'))); | |||||
} else { | |||||
$error_view->setErrors(array(pht( | |||||
'A column can not be deleted if it has tasks '. | |||||
'in it. Please remove the tasks and try again.'))); | |||||
} | |||||
} | |||||
$view_uri = $this->getApplicationURI( | $view_uri = $this->getApplicationURI( | ||||
'/board/'.$this->projectID.'/column/'.$this->id.'/'); | '/board/'.$this->projectID.'/column/'.$this->id.'/'); | ||||
if ($request->isFormPost() && !$error_view) { | if ($request->isFormPost()) { | ||||
if ($column->isDeleted()) { | if ($column->isHidden()) { | ||||
$new_status = PhabricatorProjectColumn::STATUS_ACTIVE; | $new_status = PhabricatorProjectColumn::STATUS_ACTIVE; | ||||
} else { | } else { | ||||
$new_status = PhabricatorProjectColumn::STATUS_DELETED; | $new_status = PhabricatorProjectColumn::STATUS_HIDDEN; | ||||
} | } | ||||
$type_status = PhabricatorProjectColumnTransaction::TYPE_STATUS; | $type_status = PhabricatorProjectColumnTransaction::TYPE_STATUS; | ||||
$xactions = array(id(new PhabricatorProjectColumnTransaction()) | $xactions = array(id(new PhabricatorProjectColumnTransaction()) | ||||
->setTransactionType($type_status) | ->setTransactionType($type_status) | ||||
->setNewValue($new_status)); | ->setNewValue($new_status)); | ||||
$editor = id(new PhabricatorProjectColumnTransactionEditor()) | $editor = id(new PhabricatorProjectColumnTransactionEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->applyTransactions($column, $xactions); | ->applyTransactions($column, $xactions); | ||||
return id(new AphrontRedirectResponse())->setURI($view_uri); | return id(new AphrontRedirectResponse())->setURI($view_uri); | ||||
} | } | ||||
if ($column->isDeleted()) { | if ($column->isHidden()) { | ||||
$title = pht('Activate Column'); | $title = pht('Show Column'); | ||||
} else { | } else { | ||||
$title = pht('Delete Column'); | $title = pht('Hide Column'); | ||||
} | } | ||||
$submit = $title; | |||||
if ($error_view) { | if ($column->isHidden()) { | ||||
$body = $error_view; | $body = pht( | ||||
} else if ($column->isDeleted()) { | 'Are you sure you want to show this column?'); | ||||
$body = pht('Are you sure you want to activate this column?'); | |||||
} else { | } else { | ||||
$body = pht('Are you sure you want to delete this column?'); | $body = pht( | ||||
'Are you sure you want to hide this column? It will no longer '. | |||||
'appear on the workboard.'); | |||||
} | } | ||||
$dialog = id(new AphrontDialogView()) | $dialog = $this->newDialog() | ||||
->setUser($viewer) | |||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->setTitle($title) | ->setTitle($title) | ||||
->appendChild($body) | ->appendChild($body) | ||||
->setDisableWorkflowOnCancel(true) | ->setDisableWorkflowOnCancel(true) | ||||
->addSubmitButton($title) | ->addCancelButton($view_uri) | ||||
->addCancelButton($view_uri); | ->addSubmitButton($title); | ||||
return id(new AphrontDialogResponse()) | |||||
->setDialog($dialog); | |||||
return $dialog; | |||||
} | } | ||||
} | } |