[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorProjectEditDetailsController 4 extends PhabricatorProjectController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = idx($data, 'id'); 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $viewer = $request->getUser(); 15 16 if ($this->id) { 17 $is_new = false; 18 19 $project = id(new PhabricatorProjectQuery()) 20 ->setViewer($viewer) 21 ->withIDs(array($this->id)) 22 ->needSlugs(true) 23 ->requireCapabilities( 24 array( 25 PhabricatorPolicyCapability::CAN_VIEW, 26 PhabricatorPolicyCapability::CAN_EDIT, 27 )) 28 ->executeOne(); 29 if (!$project) { 30 return new Aphront404Response(); 31 } 32 33 } else { 34 $is_new = true; 35 36 $this->requireApplicationCapability( 37 ProjectCreateProjectsCapability::CAPABILITY); 38 39 $project = PhabricatorProject::initializeNewProject($viewer); 40 } 41 42 $field_list = PhabricatorCustomField::getObjectFields( 43 $project, 44 PhabricatorCustomField::ROLE_EDIT); 45 $field_list 46 ->setViewer($viewer) 47 ->readFieldsFromStorage($project); 48 49 $e_name = true; 50 $e_slugs = false; 51 $e_edit = null; 52 53 $v_name = $project->getName(); 54 $project_slugs = $project->getSlugs(); 55 $project_slugs = mpull($project_slugs, 'getSlug', 'getSlug'); 56 $v_primary_slug = $project->getPrimarySlug(); 57 unset($project_slugs[$v_primary_slug]); 58 $v_slugs = $project_slugs; 59 $v_color = $project->getColor(); 60 $v_icon = $project->getIcon(); 61 $v_locked = $project->getIsMembershipLocked(); 62 63 $validation_exception = null; 64 65 if ($request->isFormPost()) { 66 $e_name = null; 67 $e_slugs = null; 68 69 $v_name = $request->getStr('name'); 70 $v_slugs = $request->getStrList('slugs'); 71 $v_view = $request->getStr('can_view'); 72 $v_edit = $request->getStr('can_edit'); 73 $v_join = $request->getStr('can_join'); 74 $v_color = $request->getStr('color'); 75 $v_icon = $request->getStr('icon'); 76 $v_locked = $request->getInt('is_membership_locked', 0); 77 78 $xactions = $field_list->buildFieldTransactionsFromRequest( 79 new PhabricatorProjectTransaction(), 80 $request); 81 82 $type_name = PhabricatorProjectTransaction::TYPE_NAME; 83 $type_slugs = PhabricatorProjectTransaction::TYPE_SLUGS; 84 $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 85 $type_icon = PhabricatorProjectTransaction::TYPE_ICON; 86 $type_color = PhabricatorProjectTransaction::TYPE_COLOR; 87 $type_locked = PhabricatorProjectTransaction::TYPE_LOCKED; 88 89 $xactions[] = id(new PhabricatorProjectTransaction()) 90 ->setTransactionType($type_name) 91 ->setNewValue($v_name); 92 93 $xactions[] = id(new PhabricatorProjectTransaction()) 94 ->setTransactionType($type_slugs) 95 ->setNewValue($v_slugs); 96 97 $xactions[] = id(new PhabricatorProjectTransaction()) 98 ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 99 ->setNewValue($v_view); 100 101 $xactions[] = id(new PhabricatorProjectTransaction()) 102 ->setTransactionType($type_edit) 103 ->setNewValue($v_edit); 104 105 $xactions[] = id(new PhabricatorProjectTransaction()) 106 ->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY) 107 ->setNewValue($v_join); 108 109 $xactions[] = id(new PhabricatorProjectTransaction()) 110 ->setTransactionType($type_icon) 111 ->setNewValue($v_icon); 112 113 $xactions[] = id(new PhabricatorProjectTransaction()) 114 ->setTransactionType($type_color) 115 ->setNewValue($v_color); 116 117 $xactions[] = id(new PhabricatorProjectTransaction()) 118 ->setTransactionType($type_locked) 119 ->setNewValue($v_locked); 120 121 $editor = id(new PhabricatorProjectTransactionEditor()) 122 ->setActor($viewer) 123 ->setContentSourceFromRequest($request) 124 ->setContinueOnNoEffect(true); 125 126 if ($is_new) { 127 $xactions[] = id(new PhabricatorProjectTransaction()) 128 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 129 ->setMetadataValue( 130 'edge:type', 131 PhabricatorEdgeConfig::TYPE_PROJ_MEMBER) 132 ->setNewValue( 133 array( 134 '+' => array($viewer->getPHID() => $viewer->getPHID()), 135 )); 136 } 137 138 try { 139 140 $editor->applyTransactions($project, $xactions); 141 142 if ($request->isAjax()) { 143 return id(new AphrontAjaxResponse()) 144 ->setContent(array( 145 'phid' => $project->getPHID(), 146 'name' => $project->getName(), 147 )); 148 } 149 150 if ($is_new) { 151 $redirect_uri = 152 $this->getApplicationURI('view/'.$project->getID().'/'); 153 } else { 154 $redirect_uri = 155 $this->getApplicationURI('edit/'.$project->getID().'/'); 156 } 157 158 return id(new AphrontRedirectResponse())->setURI($redirect_uri); 159 } catch (PhabricatorApplicationTransactionValidationException $ex) { 160 $validation_exception = $ex; 161 162 $e_name = $ex->getShortMessage($type_name); 163 $e_slugs = $ex->getShortMessage($type_slugs); 164 $e_edit = $ex->getShortMessage($type_edit); 165 166 $project->setViewPolicy($v_view); 167 $project->setEditPolicy($v_edit); 168 $project->setJoinPolicy($v_join); 169 } 170 } 171 172 if ($is_new) { 173 $header_name = pht('Create a New Project'); 174 $title = pht('Create Project'); 175 } else { 176 $header_name = pht('Edit Project'); 177 $title = pht('Edit Project'); 178 } 179 180 $policies = id(new PhabricatorPolicyQuery()) 181 ->setViewer($viewer) 182 ->setObject($project) 183 ->execute(); 184 $v_slugs = implode(', ', $v_slugs); 185 186 $form = id(new AphrontFormView()) 187 ->setUser($viewer) 188 ->appendChild( 189 id(new AphrontFormTextControl()) 190 ->setLabel(pht('Name')) 191 ->setName('name') 192 ->setValue($v_name) 193 ->setError($e_name)); 194 $field_list->appendFieldsToForm($form); 195 196 $shades = PhabricatorProjectIcon::getColorMap(); 197 198 if ($is_new) { 199 $icon_uri = $this->getApplicationURI('icon/'); 200 } else { 201 $icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/'); 202 } 203 $icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon); 204 list($can_lock, $lock_message) = $this->explainApplicationCapability( 205 ProjectCanLockProjectsCapability::CAPABILITY, 206 pht('You can update the Lock Project setting.'), 207 pht('You can not update the Lock Project setting.')); 208 209 $form 210 ->appendChild( 211 id(new AphrontFormChooseButtonControl()) 212 ->setLabel(pht('Icon')) 213 ->setName('icon') 214 ->setDisplayValue($icon_display) 215 ->setButtonText(pht('Choose Icon...')) 216 ->setChooseURI($icon_uri) 217 ->setValue($v_icon)) 218 ->appendChild( 219 id(new AphrontFormSelectControl()) 220 ->setLabel(pht('Color')) 221 ->setName('color') 222 ->setValue($v_color) 223 ->setOptions($shades)) 224 ->appendChild( 225 id(new AphrontFormStaticControl()) 226 ->setLabel(pht('Primary Hashtag')) 227 ->setCaption(pht('The primary hashtag is derived from the name.')) 228 ->setValue($v_primary_slug)) 229 ->appendChild( 230 id(new AphrontFormTextControl()) 231 ->setLabel(pht('Additional Hashtags')) 232 ->setCaption(pht( 233 'Specify a comma-separated list of additional hashtags.')) 234 ->setName('slugs') 235 ->setValue($v_slugs) 236 ->setError($e_slugs)) 237 ->appendChild( 238 id(new AphrontFormPolicyControl()) 239 ->setUser($viewer) 240 ->setName('can_view') 241 ->setPolicyObject($project) 242 ->setPolicies($policies) 243 ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) 244 ->appendChild( 245 id(new AphrontFormPolicyControl()) 246 ->setUser($viewer) 247 ->setName('can_edit') 248 ->setPolicyObject($project) 249 ->setPolicies($policies) 250 ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 251 ->setError($e_edit)) 252 ->appendChild( 253 id(new AphrontFormPolicyControl()) 254 ->setUser($viewer) 255 ->setName('can_join') 256 ->setCaption( 257 pht('Users who can edit a project can always join a project.')) 258 ->setPolicyObject($project) 259 ->setPolicies($policies) 260 ->setCapability(PhabricatorPolicyCapability::CAN_JOIN)) 261 ->appendChild( 262 id(new AphrontFormCheckboxControl()) 263 ->setLabel(pht('Lock Project')) 264 ->setDisabled(!$can_lock) 265 ->addCheckbox( 266 'is_membership_locked', 267 1, 268 pht('Prevent members from leaving this project.'), 269 $v_locked) 270 ->setCaption($lock_message)); 271 272 if ($request->isAjax()) { 273 $errors = array(); 274 if ($validation_exception) { 275 $errors = mpull($ex->getErrors(), 'getMessage'); 276 } 277 $dialog = id(new AphrontDialogView()) 278 ->setUser($viewer) 279 ->setWidth(AphrontDialogView::WIDTH_FULL) 280 ->setTitle($header_name) 281 ->setErrors($errors) 282 ->appendForm($form) 283 ->addSubmitButton($title) 284 ->addCancelButton('/project/'); 285 return id(new AphrontDialogResponse())->setDialog($dialog); 286 } 287 288 $form->appendChild( 289 id(new AphrontFormSubmitControl()) 290 ->addCancelButton($this->getApplicationURI()) 291 ->setValue(pht('Save'))); 292 293 $form_box = id(new PHUIObjectBoxView()) 294 ->setHeaderText($title) 295 ->setValidationException($validation_exception) 296 ->setForm($form); 297 298 $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()); 299 if ($is_new) { 300 $crumbs->addTextCrumb($title); 301 } else { 302 $crumbs 303 ->addTextCrumb($project->getName(), 304 $this->getApplicationURI('view/'.$project->getID().'/')) 305 ->addTextCrumb(pht('Edit'), 306 $this->getApplicationURI('edit/'.$project->getID().'/')) 307 ->addTextCrumb(pht('Details')); 308 } 309 310 return $this->buildApplicationPage( 311 array( 312 $crumbs, 313 $form_box, 314 ), 315 array( 316 'title' => $title, 317 )); 318 } 319 }
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 |