Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/controller/AlmanacServiceEditController.php
12256 views
1
<?php
2
3
final class AlmanacServiceEditController
4
extends AlmanacServiceController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$engine = id(new AlmanacServiceEditEngine())
8
->setController($this);
9
10
$id = $request->getURIData('id');
11
if (!$id) {
12
$this->requireApplicationCapability(
13
AlmanacCreateServicesCapability::CAPABILITY);
14
15
$list_uri = $this->getApplicationURI('service/');
16
17
$service_type = $request->getStr('serviceType');
18
$service_types = AlmanacServiceType::getAllServiceTypes();
19
if (empty($service_types[$service_type])) {
20
return $this->buildServiceTypeResponse($list_uri);
21
}
22
23
$engine
24
->addContextParameter('serviceType', $service_type)
25
->setServiceType($service_type);
26
}
27
28
return $engine->buildResponse();
29
}
30
31
private function buildServiceTypeResponse($cancel_uri) {
32
$service_types = AlmanacServiceType::getAllServiceTypes();
33
34
$request = $this->getRequest();
35
$viewer = $this->getViewer();
36
37
$e_service = null;
38
$errors = array();
39
if ($request->isFormPost()) {
40
$e_service = pht('Required');
41
$errors[] = pht(
42
'To create a new service, you must select a service type.');
43
}
44
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.'));
49
50
$type_control = id(new AphrontFormRadioButtonControl())
51
->setLabel(pht('Service Type'))
52
->setName('serviceType')
53
->setError($e_service);
54
55
foreach ($service_types as $service_type) {
56
$is_cluster = $service_type->isClusterServiceType();
57
$is_disabled = ($is_cluster && !$can_cluster);
58
59
if ($is_cluster) {
60
$extra = $cluster_link;
61
} else {
62
$extra = null;
63
}
64
65
$type_control->addButton(
66
$service_type->getServiceTypeConstant(),
67
$service_type->getServiceTypeName(),
68
array(
69
$service_type->getServiceTypeDescription(),
70
$extra,
71
),
72
$is_disabled ? 'disabled' : null,
73
$is_disabled);
74
}
75
76
$crumbs = $this->buildApplicationCrumbs();
77
$crumbs->addTextCrumb(pht('Create Service'));
78
$crumbs->setBorder(true);
79
80
$title = pht('Choose Service Type');
81
$header = id(new PHUIHeaderView())
82
->setHeader(pht('Create Service'))
83
->setHeaderIcon('fa-plus-square');
84
85
$form = id(new AphrontFormView())
86
->setUser($viewer)
87
->appendChild($type_control)
88
->appendChild(
89
id(new AphrontFormSubmitControl())
90
->setValue(pht('Continue'))
91
->addCancelButton($cancel_uri));
92
93
$box = id(new PHUIObjectBoxView())
94
->setFormErrors($errors)
95
->setHeaderText(pht('Service'))
96
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
97
->setForm($form);
98
99
$view = id(new PHUITwoColumnView())
100
->setHeader($header)
101
->setFooter(array(
102
$box,
103
));
104
105
return $this->newPage()
106
->setTitle($title)
107
->setCrumbs($crumbs)
108
->appendChild($view);
109
110
}
111
112
}
113
114