[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AlmanacInterfaceEditController 4 extends AlmanacDeviceController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 9 $id = $request->getURIData('id'); 10 if ($id) { 11 $interface = id(new AlmanacInterfaceQuery()) 12 ->setViewer($viewer) 13 ->withIDs(array($id)) 14 ->requireCapabilities( 15 array( 16 PhabricatorPolicyCapability::CAN_VIEW, 17 PhabricatorPolicyCapability::CAN_EDIT, 18 )) 19 ->executeOne(); 20 if (!$interface) { 21 return new Aphront404Response(); 22 } 23 24 $device = $interface->getDevice(); 25 26 $is_new = false; 27 $title = pht('Edit Interface'); 28 $save_button = pht('Save Changes'); 29 } else { 30 $device = id(new AlmanacDeviceQuery()) 31 ->setViewer($viewer) 32 ->withIDs(array($request->getStr('deviceID'))) 33 ->requireCapabilities( 34 array( 35 PhabricatorPolicyCapability::CAN_VIEW, 36 PhabricatorPolicyCapability::CAN_EDIT, 37 )) 38 ->executeOne(); 39 if (!$device) { 40 return new Aphront404Response(); 41 } 42 43 $interface = AlmanacInterface::initializeNewInterface(); 44 $is_new = true; 45 46 $title = pht('Create Interface'); 47 $save_button = pht('Create Interface'); 48 } 49 50 $device_uri = $device->getURI(); 51 $cancel_uri = $device_uri; 52 53 $v_network = $interface->getNetworkPHID(); 54 55 $v_address = $interface->getAddress(); 56 $e_address = true; 57 58 $v_port = $interface->getPort(); 59 60 $validation_exception = null; 61 62 if ($request->isFormPost()) { 63 $v_network = $request->getStr('networkPHID'); 64 $v_address = $request->getStr('address'); 65 $v_port = $request->getStr('port'); 66 67 $type_interface = AlmanacDeviceTransaction::TYPE_INTERFACE; 68 69 $address = AlmanacAddress::newFromParts($v_network, $v_address, $v_port); 70 71 $xaction = id(new AlmanacDeviceTransaction()) 72 ->setTransactionType($type_interface) 73 ->setNewValue($address->toDictionary()); 74 75 if ($interface->getID()) { 76 $xaction->setOldValue(array( 77 'id' => $interface->getID(), 78 ) + $interface->toAddress()->toDictionary()); 79 } else { 80 $xaction->setOldValue(array()); 81 } 82 83 $xactions = array(); 84 $xactions[] = $xaction; 85 86 $editor = id(new AlmanacDeviceEditor()) 87 ->setActor($viewer) 88 ->setContentSourceFromRequest($request) 89 ->setContinueOnNoEffect(true) 90 ->setContinueOnMissingFields(true); 91 92 try { 93 $editor->applyTransactions($device, $xactions); 94 95 $device_uri = $device->getURI(); 96 return id(new AphrontRedirectResponse())->setURI($device_uri); 97 } catch (PhabricatorApplicationTransactionValidationException $ex) { 98 $validation_exception = $ex; 99 $e_address = $ex->getShortMessage($type_interface); 100 } 101 } 102 103 $networks = id(new AlmanacNetworkQuery()) 104 ->setViewer($viewer) 105 ->execute(); 106 107 $form = id(new AphrontFormView()) 108 ->setUser($viewer) 109 ->appendChild( 110 id(new AphrontFormSelectControl()) 111 ->setLabel(pht('Network')) 112 ->setName('networkPHID') 113 ->setValue($v_network) 114 ->setOptions(mpull($networks, 'getName', 'getPHID'))) 115 ->appendChild( 116 id(new AphrontFormTextControl()) 117 ->setLabel(pht('Address')) 118 ->setName('address') 119 ->setValue($v_address) 120 ->setError($e_address)) 121 ->appendChild( 122 id(new AphrontFormTextControl()) 123 ->setLabel(pht('Port')) 124 ->setName('port') 125 ->setValue($v_port) 126 ->setError($e_address)) 127 ->appendChild( 128 id(new AphrontFormSubmitControl()) 129 ->addCancelButton($cancel_uri) 130 ->setValue($save_button)); 131 132 $box = id(new PHUIObjectBoxView()) 133 ->setValidationException($validation_exception) 134 ->setHeaderText($title) 135 ->appendChild($form); 136 137 $crumbs = $this->buildApplicationCrumbs(); 138 $crumbs->addTextCrumb($device->getName(), $device_uri); 139 if ($is_new) { 140 $crumbs->addTextCrumb(pht('Create Interface')); 141 } else { 142 $crumbs->addTextCrumb(pht('Edit Interface')); 143 } 144 145 return $this->buildApplicationPage( 146 array( 147 $crumbs, 148 $box, 149 ), 150 array( 151 'title' => $title, 152 )); 153 } 154 155 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |