|
| 1 | +<?php |
| 2 | + |
| 3 | +final class PhabricatorDashboardPanelEditproController |
| 4 | + extends PhabricatorDashboardController { |
| 5 | + |
| 6 | + public function handleRequest(AphrontRequest $request) { |
| 7 | + $engine = id(new PhabricatorDashboardPanelEditEngine()) |
| 8 | + ->setController($this); |
| 9 | + |
| 10 | + $id = $request->getURIData('id'); |
| 11 | + if (!$id) { |
| 12 | + $list_uri = $this->getApplicationURI('panel/'); |
| 13 | + |
| 14 | + $panel_type = $request->getStr('panelType'); |
| 15 | + $panel_types = PhabricatorDashboardPanelType::getAllPanelTypes(); |
| 16 | + if (empty($panel_types[$panel_type])) { |
| 17 | + return $this->buildPanelTypeResponse($list_uri); |
| 18 | + } |
| 19 | + |
| 20 | + $engine |
| 21 | + ->addContextParameter('panelType', $panel_type) |
| 22 | + ->setPanelType($panel_type); |
| 23 | + } |
| 24 | + |
| 25 | + return $engine->buildResponse(); |
| 26 | + } |
| 27 | + |
| 28 | + private function buildPanelTypeResponse($cancel_uri) { |
| 29 | + $panel_types = PhabricatorDashboardPanelType::getAllPanelTypes(); |
| 30 | + |
| 31 | + $viewer = $this->getViewer(); |
| 32 | + $request = $this->getRequest(); |
| 33 | + |
| 34 | + $e_type = null; |
| 35 | + $errors = array(); |
| 36 | + if ($request->isFormPost()) { |
| 37 | + $e_type = pht('Required'); |
| 38 | + $errors[] = pht( |
| 39 | + 'To create a new dashboard panel, you must select a panel type.'); |
| 40 | + } |
| 41 | + |
| 42 | + $type_control = id(new AphrontFormRadioButtonControl()) |
| 43 | + ->setLabel(pht('Panel Type')) |
| 44 | + ->setName('panelType') |
| 45 | + ->setError($e_type); |
| 46 | + |
| 47 | + foreach ($panel_types as $key => $type) { |
| 48 | + $type_control->addButton( |
| 49 | + $key, |
| 50 | + $type->getPanelTypeName(), |
| 51 | + $type->getPanelTypeDescription()); |
| 52 | + } |
| 53 | + |
| 54 | + $form = id(new AphrontFormView()) |
| 55 | + ->setUser($viewer) |
| 56 | + ->appendRemarkupInstructions( |
| 57 | + pht('Choose the type of dashboard panel to create:')) |
| 58 | + ->appendChild($type_control); |
| 59 | + |
| 60 | + if ($request->isAjax()) { |
| 61 | + return $this->newDialog() |
| 62 | + ->setTitle(pht('Add New Panel')) |
| 63 | + ->setWidth(AphrontDialogView::WIDTH_FORM) |
| 64 | + ->setErrors($errors) |
| 65 | + ->appendForm($form) |
| 66 | + ->addCancelButton($cancel_uri) |
| 67 | + ->addSubmitButton(pht('Continue')); |
| 68 | + } |
| 69 | + |
| 70 | + $form->appendChild( |
| 71 | + id(new AphrontFormSubmitControl()) |
| 72 | + ->setValue(pht('Continue')) |
| 73 | + ->addCancelButton($cancel_uri)); |
| 74 | + |
| 75 | + $title = pht('Create Dashboard Panel'); |
| 76 | + $header_icon = 'fa-plus-square'; |
| 77 | + |
| 78 | + $crumbs = $this->buildApplicationCrumbs(); |
| 79 | + $crumbs->addTextCrumb( |
| 80 | + pht('Panels'), |
| 81 | + $this->getApplicationURI('panel/')); |
| 82 | + $crumbs->addTextCrumb(pht('New Panel')); |
| 83 | + $crumbs->setBorder(true); |
| 84 | + |
| 85 | + $box = id(new PHUIObjectBoxView()) |
| 86 | + ->setHeaderText(pht('Panel')) |
| 87 | + ->setFormErrors($errors) |
| 88 | + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) |
| 89 | + ->setForm($form); |
| 90 | + |
| 91 | + $header = id(new PHUIHeaderView()) |
| 92 | + ->setHeader($title) |
| 93 | + ->setHeaderIcon($header_icon); |
| 94 | + |
| 95 | + $view = id(new PHUITwoColumnView()) |
| 96 | + ->setHeader($header) |
| 97 | + ->setFooter($box); |
| 98 | + |
| 99 | + return $this->newPage() |
| 100 | + ->setTitle($title) |
| 101 | + ->setCrumbs($crumbs) |
| 102 | + ->appendChild($view); |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments