Path: blob/master/src/applications/almanac/controller/AlmanacServiceEditController.php
12256 views
<?php12final class AlmanacServiceEditController3extends AlmanacServiceController {45public function handleRequest(AphrontRequest $request) {6$engine = id(new AlmanacServiceEditEngine())7->setController($this);89$id = $request->getURIData('id');10if (!$id) {11$this->requireApplicationCapability(12AlmanacCreateServicesCapability::CAPABILITY);1314$list_uri = $this->getApplicationURI('service/');1516$service_type = $request->getStr('serviceType');17$service_types = AlmanacServiceType::getAllServiceTypes();18if (empty($service_types[$service_type])) {19return $this->buildServiceTypeResponse($list_uri);20}2122$engine23->addContextParameter('serviceType', $service_type)24->setServiceType($service_type);25}2627return $engine->buildResponse();28}2930private function buildServiceTypeResponse($cancel_uri) {31$service_types = AlmanacServiceType::getAllServiceTypes();3233$request = $this->getRequest();34$viewer = $this->getViewer();3536$e_service = null;37$errors = array();38if ($request->isFormPost()) {39$e_service = pht('Required');40$errors[] = pht(41'To create a new service, you must select a service type.');42}4344list($can_cluster, $cluster_link) = $this->explainApplicationCapability(45AlmanacManageClusterServicesCapability::CAPABILITY,46pht('You have permission to create cluster services.'),47pht('You do not have permission to create new cluster services.'));4849$type_control = id(new AphrontFormRadioButtonControl())50->setLabel(pht('Service Type'))51->setName('serviceType')52->setError($e_service);5354foreach ($service_types as $service_type) {55$is_cluster = $service_type->isClusterServiceType();56$is_disabled = ($is_cluster && !$can_cluster);5758if ($is_cluster) {59$extra = $cluster_link;60} else {61$extra = null;62}6364$type_control->addButton(65$service_type->getServiceTypeConstant(),66$service_type->getServiceTypeName(),67array(68$service_type->getServiceTypeDescription(),69$extra,70),71$is_disabled ? 'disabled' : null,72$is_disabled);73}7475$crumbs = $this->buildApplicationCrumbs();76$crumbs->addTextCrumb(pht('Create Service'));77$crumbs->setBorder(true);7879$title = pht('Choose Service Type');80$header = id(new PHUIHeaderView())81->setHeader(pht('Create Service'))82->setHeaderIcon('fa-plus-square');8384$form = id(new AphrontFormView())85->setUser($viewer)86->appendChild($type_control)87->appendChild(88id(new AphrontFormSubmitControl())89->setValue(pht('Continue'))90->addCancelButton($cancel_uri));9192$box = id(new PHUIObjectBoxView())93->setFormErrors($errors)94->setHeaderText(pht('Service'))95->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)96->setForm($form);9798$view = id(new PHUITwoColumnView())99->setHeader($header)100->setFooter(array(101$box,102));103104return $this->newPage()105->setTitle($title)106->setCrumbs($crumbs)107->appendChild($view);108109}110111}112113114