2011-06-10 00:28:29 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorProjectCreateController
|
2011-06-10 00:28:29 +02:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-10-10 13:29:07 +02:00
|
|
|
$this->requireApplicationCapability(
|
2014-07-25 00:20:39 +02:00
|
|
|
ProjectCreateProjectsCapability::CAPABILITY);
|
2013-10-10 13:29:07 +02:00
|
|
|
|
2014-02-10 23:30:17 +01:00
|
|
|
$project = PhabricatorProject::initializeNewProject($user);
|
2011-06-10 00:28:29 +02:00
|
|
|
|
|
|
|
$e_name = true;
|
2014-05-22 20:19:03 +02:00
|
|
|
$type_name = PhabricatorProjectTransaction::TYPE_NAME;
|
|
|
|
$v_name = $project->getName();
|
|
|
|
$validation_exception = null;
|
2011-06-10 00:28:29 +02:00
|
|
|
if ($request->isFormPost()) {
|
2014-02-10 23:30:17 +01:00
|
|
|
$xactions = array();
|
2014-05-22 20:19:03 +02:00
|
|
|
$v_name = $request->getStr('name');
|
2011-06-10 00:28:29 +02:00
|
|
|
|
2014-02-10 23:30:17 +01:00
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
2014-05-22 20:19:03 +02:00
|
|
|
->setTransactionType($type_name)
|
|
|
|
->setNewValue($v_name);
|
2014-02-10 23:30:17 +01:00
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
|
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'+' => array($user->getPHID() => $user->getPHID()),
|
|
|
|
));
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
|
|
|
->setActor($user)
|
|
|
|
->setContinueOnNoEffect(true)
|
2014-05-22 20:19:03 +02:00
|
|
|
->setContentSourceFromRequest($request);
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($project, $xactions);
|
2011-06-26 17:37:47 +02:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(array(
|
|
|
|
'phid' => $project->getPHID(),
|
|
|
|
'name' => $project->getName(),
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/project/view/'.$project->getID().'/');
|
|
|
|
}
|
2014-05-22 20:19:03 +02:00
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
$e_name = $ex->getShortMessage($type_name);
|
2011-06-10 00:28:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
if ($request->isAjax()) {
|
2013-08-26 20:53:11 +02:00
|
|
|
$form = new PHUIFormLayoutView();
|
2011-06-26 17:37:47 +02:00
|
|
|
} else {
|
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form->setUser($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
2011-06-10 00:28:29 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-02-13 18:22:14 +01:00
|
|
|
->setLabel(pht('Name'))
|
2011-06-10 00:28:29 +02:00
|
|
|
->setName('name')
|
2014-05-22 20:19:03 +02:00
|
|
|
->setValue($v_name)
|
2014-02-10 23:31:57 +01:00
|
|
|
->setError($e_name));
|
2011-06-10 00:28:29 +02:00
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
if ($request->isAjax()) {
|
2014-05-22 20:19:03 +02:00
|
|
|
$errors = array();
|
|
|
|
if ($validation_exception) {
|
|
|
|
$errors = mpull($ex->getErrors(), 'getMessage');
|
|
|
|
}
|
2011-06-26 17:37:47 +02:00
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
2013-02-13 18:22:14 +01:00
|
|
|
->setTitle(pht('Create a New Project'))
|
2014-05-22 20:19:03 +02:00
|
|
|
->setErrors($errors)
|
2011-06-26 17:37:47 +02:00
|
|
|
->appendChild($form)
|
2013-02-13 18:22:14 +01:00
|
|
|
->addSubmitButton(pht('Create Project'))
|
2011-06-26 17:37:47 +02:00
|
|
|
->addCancelButton('/project/');
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
} else {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-02-13 18:22:14 +01:00
|
|
|
->setValue(pht('Create'))
|
2011-06-26 17:37:47 +02:00
|
|
|
->addCancelButton('/project/'));
|
|
|
|
|
2013-02-13 18:22:14 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
pht('Create Project'),
|
|
|
|
$this->getApplicationURI().'create/');
|
2013-02-13 18:22:14 +01:00
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText(pht('Create New Project'))
|
2014-05-22 20:19:03 +02:00
|
|
|
->setValidationException($validation_exception)
|
2013-08-26 20:53:11 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
2013-02-13 18:22:14 +01:00
|
|
|
return $this->buildApplicationPage(
|
2011-06-26 17:37:47 +02:00
|
|
|
array(
|
2013-02-13 18:22:14 +01:00
|
|
|
$crumbs,
|
2013-08-26 20:53:11 +02:00
|
|
|
$form_box,
|
2011-06-26 17:37:47 +02:00
|
|
|
),
|
|
|
|
array(
|
2013-02-13 18:22:14 +01:00
|
|
|
'title' => pht('Create New Project'),
|
2011-06-26 17:37:47 +02:00
|
|
|
));
|
|
|
|
}
|
2011-06-10 00:28:29 +02:00
|
|
|
}
|
2014-07-25 00:20:39 +02:00
|
|
|
|
2011-06-10 00:28:29 +02:00
|
|
|
}
|