Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/controller/HeraldNewController.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public function processRequest() { | ||||
if ($errors) { | if ($errors) { | ||||
$errors = id(new AphrontErrorView())->setErrors($errors); | $errors = id(new AphrontErrorView())->setErrors($errors); | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setUser($user) | ||||
->setAction($this->getApplicationURI('new/')); | ->setAction($this->getApplicationURI('new/')); | ||||
$rule_types = $this->renderRuleTypeControl($rule_type_map, $e_rule); | $content_types = $this->renderContentTypeControl( | ||||
$content_type_map, | |||||
$e_type); | |||||
$rule_types = $this->renderRuleTypeControl( | |||||
$rule_type_map, | |||||
$e_rule); | |||||
switch ($step) { | switch ($step) { | ||||
case 0: | case 0: | ||||
default: | default: | ||||
$form | $form | ||||
->addHiddenInput('step', 1) | ->addHiddenInput('step', 1) | ||||
->appendChild( | ->appendChild($content_types); | ||||
id(new AphrontFormSelectControl()) | |||||
->setLabel(pht('New Rule for')) | |||||
->setName('content_type') | |||||
->setValue($request->getStr('content_type')) | |||||
->setOptions($content_type_map)); | |||||
$cancel_text = null; | $cancel_text = null; | ||||
$cancel_uri = $this->getApplicationURI(); | $cancel_uri = $this->getApplicationURI(); | ||||
break; | break; | ||||
case 1: | case 1: | ||||
$form | $form | ||||
->addHiddenInput('content_type', $request->getStr('content_type')) | ->addHiddenInput('content_type', $request->getStr('content_type')) | ||||
->addHiddenInput('step', 2) | ->addHiddenInput('step', 2) | ||||
->appendChild( | |||||
id(new AphrontFormStaticControl()) | |||||
->setLabel(pht('Rule for')) | |||||
->setValue( | |||||
phutil_tag( | |||||
'strong', | |||||
array(), | |||||
idx($content_type_map, $content_type)))) | |||||
->appendChild($rule_types); | ->appendChild($rule_types); | ||||
$cancel_text = pht('Back'); | $cancel_text = pht('Back'); | ||||
$cancel_uri = id(new PhutilURI('new/')) | $cancel_uri = id(new PhutilURI('new/')) | ||||
->setQueryParams( | ->setQueryParams( | ||||
array( | array( | ||||
'content_type' => $request->getStr('content_type'), | 'content_type' => $request->getStr('content_type'), | ||||
'step' => 1, | 'step' => 1, | ||||
)); | )); | ||||
$cancel_uri = $this->getApplicationURI($cancel_uri); | $cancel_uri = $this->getApplicationURI($cancel_uri); | ||||
Show All 22 Lines | return $this->buildApplicationPage( | ||||
$form_box, | $form_box, | ||||
), | ), | ||||
array( | array( | ||||
'title' => pht('Create Herald Rule'), | 'title' => pht('Create Herald Rule'), | ||||
'device' => true, | 'device' => true, | ||||
)); | )); | ||||
} | } | ||||
private function renderContentTypeControl(array $content_type_map, $e_type) { | |||||
$request = $this->getRequest(); | |||||
$radio = id(new AphrontFormRadioButtonControl()) | |||||
->setLabel(pht('New Rule for')) | |||||
->setName('content_type') | |||||
->setValue($request->getStr('content_type')) | |||||
->setError($e_type); | |||||
foreach ($content_type_map as $value => $name) { | |||||
$adapter = HeraldAdapter::getAdapterForContentType($value); | |||||
$radio->addButton( | |||||
$value, | |||||
$name, | |||||
phutil_escape_html_newlines($adapter->getAdapterContentDescription())); | |||||
} | |||||
return $radio; | |||||
} | |||||
private function renderRuleTypeControl(array $rule_type_map, $e_rule) { | private function renderRuleTypeControl(array $rule_type_map, $e_rule) { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
// Reorder array to put "personal" first. | // Reorder array to put "personal" first. | ||||
$rule_type_map = array_select_keys( | $rule_type_map = array_select_keys( | ||||
$rule_type_map, | $rule_type_map, | ||||
array( | array( | ||||
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL, | HeraldRuleTypeConfig::RULE_TYPE_PERSONAL, | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |