3 final class AlmanacServiceEditController
4 extends AlmanacServiceController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $engine = id(new AlmanacServiceEditEngine())
8 ->setController($this);
10 $id = $request->getURIData('id');
12 $this->requireApplicationCapability(
13 AlmanacCreateServicesCapability
::CAPABILITY
);
15 $list_uri = $this->getApplicationURI('service/');
17 $service_type = $request->getStr('serviceType');
18 $service_types = AlmanacServiceType
::getAllServiceTypes();
19 if (empty($service_types[$service_type])) {
20 return $this->buildServiceTypeResponse($list_uri);
24 ->addContextParameter('serviceType', $service_type)
25 ->setServiceType($service_type);
28 return $engine->buildResponse();
31 private function buildServiceTypeResponse($cancel_uri) {
32 $service_types = AlmanacServiceType
::getAllServiceTypes();
34 $request = $this->getRequest();
35 $viewer = $this->getViewer();
39 if ($request->isFormPost()) {
40 $e_service = pht('Required');
42 'To create a new service, you must select a service type.');
45 list($can_cluster, $cluster_link) = $this->explainApplicationCapability(
46 AlmanacManageClusterServicesCapability
::CAPABILITY
,
47 pht('You have permission to create cluster services.'),
48 pht('You do not have permission to create new cluster services.'));
50 $type_control = id(new AphrontFormRadioButtonControl())
51 ->setLabel(pht('Service Type'))
52 ->setName('serviceType')
53 ->setError($e_service);
55 foreach ($service_types as $service_type) {
56 $is_cluster = $service_type->isClusterServiceType();
57 $is_disabled = ($is_cluster && !$can_cluster);
60 $extra = $cluster_link;
65 $type_control->addButton(
66 $service_type->getServiceTypeConstant(),
67 $service_type->getServiceTypeName(),
69 $service_type->getServiceTypeDescription(),
72 $is_disabled ?
'disabled' : null,
76 $crumbs = $this->buildApplicationCrumbs();
77 $crumbs->addTextCrumb(pht('Create Service'));
78 $crumbs->setBorder(true);
80 $title = pht('Choose Service Type');
81 $header = id(new PHUIHeaderView())
82 ->setHeader(pht('Create Service'))
83 ->setHeaderIcon('fa-plus-square');
85 $form = id(new AphrontFormView())
87 ->appendChild($type_control)
89 id(new AphrontFormSubmitControl())
90 ->setValue(pht('Continue'))
91 ->addCancelButton($cancel_uri));
93 $box = id(new PHUIObjectBoxView())
94 ->setFormErrors($errors)
95 ->setHeaderText(pht('Service'))
96 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
99 $view = id(new PHUITwoColumnView())
105 return $this->newPage()
108 ->appendChild($view);