Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/controller/AlmanacServiceEditController.php
Show All 23 Lines | if ($id) { | ||||
} | } | ||||
$is_new = false; | $is_new = false; | ||||
$service_uri = $service->getURI(); | $service_uri = $service->getURI(); | ||||
$cancel_uri = $service_uri; | $cancel_uri = $service_uri; | ||||
$title = pht('Edit Service'); | $title = pht('Edit Service'); | ||||
$save_button = pht('Save Changes'); | $save_button = pht('Save Changes'); | ||||
} else { | } else { | ||||
$cancel_uri = $list_uri; | |||||
$this->requireApplicationCapability( | $this->requireApplicationCapability( | ||||
AlmanacCreateServicesCapability::CAPABILITY); | AlmanacCreateServicesCapability::CAPABILITY); | ||||
$service_class = $request->getStr('serviceClass'); | |||||
$service_types = AlmanacServiceType::getAllServiceTypes(); | |||||
if (empty($service_types[$service_class])) { | |||||
return $this->buildServiceTypeResponse($service_types, $cancel_uri); | |||||
} | |||||
$service_type = $service_types[$service_class]; | |||||
if ($service_type->isClusterServiceType()) { | |||||
$this->requireApplicationCapability( | |||||
AlmanacCreateClusterServicesCapability::CAPABILITY); | |||||
} | |||||
$service = AlmanacService::initializeNewService(); | $service = AlmanacService::initializeNewService(); | ||||
$service->setServiceClass($service_class); | |||||
$service->attachServiceType($service_type); | |||||
$is_new = true; | $is_new = true; | ||||
$cancel_uri = $list_uri; | |||||
$title = pht('Create Service'); | $title = pht('Create Service'); | ||||
$save_button = pht('Create Service'); | $save_button = pht('Create Service'); | ||||
} | } | ||||
$v_name = $service->getName(); | $v_name = $service->getName(); | ||||
$e_name = true; | $e_name = true; | ||||
$validation_exception = null; | $validation_exception = null; | ||||
if ($is_new) { | if ($is_new) { | ||||
$v_projects = array(); | $v_projects = array(); | ||||
} else { | } else { | ||||
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | ||||
$service->getPHID(), | $service->getPHID(), | ||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | ||||
$v_projects = array_reverse($v_projects); | $v_projects = array_reverse($v_projects); | ||||
} | } | ||||
if ($request->isFormPost()) { | if ($request->isFormPost() && $request->getStr('edit')) { | ||||
$v_name = $request->getStr('name'); | $v_name = $request->getStr('name'); | ||||
$v_view = $request->getStr('viewPolicy'); | $v_view = $request->getStr('viewPolicy'); | ||||
$v_edit = $request->getStr('editPolicy'); | $v_edit = $request->getStr('editPolicy'); | ||||
$v_projects = $request->getArr('projects'); | $v_projects = $request->getArr('projects'); | ||||
$type_name = AlmanacServiceTransaction::TYPE_NAME; | $type_name = AlmanacServiceTransaction::TYPE_NAME; | ||||
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; | $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; | ||||
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; | $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
if ($v_projects) { | if ($v_projects) { | ||||
$project_handles = $this->loadViewerHandles($v_projects); | $project_handles = $this->loadViewerHandles($v_projects); | ||||
} else { | } else { | ||||
$project_handles = array(); | $project_handles = array(); | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->addHiddenInput('edit', true) | |||||
->addHiddenInput('serviceClass', $service->getServiceClass()) | |||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setName('name') | ->setName('name') | ||||
->setValue($v_name) | ->setValue($v_name) | ||||
->setError($e_name)) | ->setError($e_name)) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormPolicyControl()) | id(new AphrontFormPolicyControl()) | ||||
Show All 36 Lines | return $this->buildApplicationPage( | ||||
$crumbs, | $crumbs, | ||||
$box, | $box, | ||||
), | ), | ||||
array( | array( | ||||
'title' => $title, | 'title' => $title, | ||||
)); | )); | ||||
} | } | ||||
private function buildServiceTypeResponse(array $service_types, $cancel_uri) { | |||||
$request = $this->getRequest(); | |||||
$viewer = $this->getViewer(); | |||||
$e_service = null; | |||||
$errors = array(); | |||||
if ($request->isFormPost()) { | |||||
$e_service = pht('Required'); | |||||
$errors[] = pht( | |||||
'To create a new service, you must select a service type.'); | |||||
} | |||||
list($can_cluster, $cluster_link) = $this->explainApplicationCapability( | |||||
AlmanacCreateClusterServicesCapability::CAPABILITY, | |||||
pht('You have permission to create cluster services.'), | |||||
pht('You do not have permission to create new cluster services.')); | |||||
$type_control = id(new AphrontFormRadioButtonControl()) | |||||
->setLabel(pht('Service Type')) | |||||
->setName('serviceClass') | |||||
->setError($e_service); | |||||
foreach ($service_types as $service_type) { | |||||
$is_cluster = $service_type->isClusterServiceType(); | |||||
$is_disabled = ($is_cluster && !$can_cluster); | |||||
if ($is_cluster) { | |||||
$extra = $cluster_link; | |||||
} else { | |||||
$extra = null; | |||||
} | |||||
$type_control->addButton( | |||||
get_class($service_type), | |||||
$service_type->getServiceTypeName(), | |||||
array( | |||||
$service_type->getServiceTypeDescription(), | |||||
$extra, | |||||
), | |||||
$is_disabled ? 'disabled' : null, | |||||
$is_disabled); | |||||
} | |||||
$crumbs = $this->buildApplicationCrumbs(); | |||||
$crumbs->addTextCrumb(pht('Create Service')); | |||||
$title = pht('Choose Service Type'); | |||||
$form = id(new AphrontFormView()) | |||||
->setUser($viewer) | |||||
->appendChild($type_control) | |||||
->appendChild( | |||||
id(new AphrontFormSubmitControl()) | |||||
->setValue(pht('Continue')) | |||||
->addCancelButton($cancel_uri)); | |||||
$box = id(new PHUIObjectBoxView()) | |||||
->setFormErrors($errors) | |||||
->setHeaderText($title) | |||||
->appendChild($form); | |||||
return $this->buildApplicationPage( | |||||
array( | |||||
$crumbs, | |||||
$box, | |||||
), | |||||
array( | |||||
'title' => $title, | |||||
)); | |||||
} | |||||
} | } |