2011-01-26 10:40:38 -08:00
|
|
|
<?php
|
|
|
|
|
|
2012-08-12 19:19:46 -07:00
|
|
|
final class PhabricatorMailingListsEditController
|
2013-01-23 16:36:21 -08:00
|
|
|
extends PhabricatorMailingListsController {
|
2011-01-26 10:40:38 -08:00
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
|
|
if ($this->id) {
|
|
|
|
|
$list = id(new PhabricatorMetaMTAMailingList())->load($this->id);
|
|
|
|
|
if (!$list) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$list = new PhabricatorMetaMTAMailingList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$e_email = true;
|
2012-01-11 13:36:28 -08:00
|
|
|
$e_uri = null;
|
|
|
|
|
$e_name = true;
|
2011-01-26 10:40:38 -08:00
|
|
|
$errors = array();
|
|
|
|
|
|
2013-01-23 16:36:21 -08:00
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
|
|
|
|
|
2011-01-26 10:40:38 -08:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
$list->setName($request->getStr('name'));
|
|
|
|
|
$list->setEmail($request->getStr('email'));
|
|
|
|
|
$list->setURI($request->getStr('uri'));
|
|
|
|
|
|
2012-03-07 13:18:00 -08:00
|
|
|
$e_email = null;
|
|
|
|
|
$e_name = null;
|
|
|
|
|
|
2011-01-26 10:40:38 -08:00
|
|
|
if (!strlen($list->getEmail())) {
|
2013-01-23 16:36:21 -08:00
|
|
|
$e_email = pht('Required');
|
|
|
|
|
$errors[] = pht('Email is required.');
|
2011-01-26 10:40:38 -08:00
|
|
|
}
|
|
|
|
|
|
2012-01-11 13:36:28 -08:00
|
|
|
if (!strlen($list->getName())) {
|
2013-01-23 16:36:21 -08:00
|
|
|
$e_name = pht('Required');
|
|
|
|
|
$errors[] = pht('Name is required.');
|
2012-03-07 13:18:00 -08:00
|
|
|
} else if (preg_match('/[ ,]/', $list->getName())) {
|
2013-01-23 16:36:21 -08:00
|
|
|
$e_name = pht('Invalid');
|
|
|
|
|
$errors[] = pht('Name must not contain spaces or commas.');
|
2012-01-11 13:36:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($list->getURI()) {
|
2012-01-11 16:07:36 -08:00
|
|
|
if (!PhabricatorEnv::isValidWebResource($list->getURI())) {
|
2013-01-23 16:36:21 -08:00
|
|
|
$e_uri = pht('Invalid');
|
|
|
|
|
$errors[] = pht('Mailing list URI must point to a valid web page.');
|
2012-01-11 13:36:28 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-26 10:40:38 -08:00
|
|
|
if (!$errors) {
|
2012-03-07 13:18:00 -08:00
|
|
|
try {
|
|
|
|
|
$list->save();
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
2012-08-12 19:19:46 -07:00
|
|
|
->setURI($this->getApplicationURI());
|
2012-03-07 13:18:00 -08:00
|
|
|
} catch (AphrontQueryDuplicateKeyException $ex) {
|
2013-01-23 16:36:21 -08:00
|
|
|
$e_email = pht('Duplicate');
|
|
|
|
|
$errors[] = pht('Another mailing list already uses that address.');
|
2012-03-07 13:18:00 -08:00
|
|
|
}
|
2011-01-26 10:40:38 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
|
if ($errors) {
|
|
|
|
|
$error_view = id(new AphrontErrorView())
|
2013-01-23 16:36:21 -08:00
|
|
|
->setTitle(pht('Form Errors'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setErrors($errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
2011-01-30 18:52:29 -08:00
|
|
|
$form->setUser($request->getUser());
|
2011-01-26 10:40:38 -08:00
|
|
|
if ($list->getID()) {
|
2012-08-12 19:19:46 -07:00
|
|
|
$form->setAction($this->getApplicationURI('/edit/'.$list->getID().'/'));
|
2011-01-26 10:40:38 -08:00
|
|
|
} else {
|
2012-08-12 19:19:46 -07:00
|
|
|
$form->setAction($this->getApplicationURI('/edit/'));
|
2011-01-26 10:40:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
2013-01-23 16:36:21 -08:00
|
|
|
->setLabel(pht('Email'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setName('email')
|
|
|
|
|
->setValue($list->getEmail())
|
2013-01-23 16:36:21 -08:00
|
|
|
->setCaption(pht('Email will be delivered to this address.'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setError($e_email))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
2013-01-23 16:36:21 -08:00
|
|
|
->setLabel(pht('Name'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setName('name')
|
2012-01-11 13:36:28 -08:00
|
|
|
->setError($e_name)
|
2013-01-23 16:36:21 -08:00
|
|
|
->setCaption(pht('Human-readable display and autocomplete name.'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setValue($list->getName()))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
2013-01-23 16:36:21 -08:00
|
|
|
->setLabel(pht('URI'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setName('uri')
|
2012-01-11 13:36:28 -08:00
|
|
|
->setError($e_uri)
|
2013-01-23 16:36:21 -08:00
|
|
|
->setCaption(pht('Optional link to mailing list archives or info.'))
|
2011-01-26 10:40:38 -08:00
|
|
|
->setValue($list->getURI()))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormStaticControl())
|
|
|
|
|
->setLabel('PHID')
|
|
|
|
|
->setValue(nonempty($list->getPHID(), '-')))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-01-23 16:36:21 -08:00
|
|
|
->setValue(pht('Save'))
|
2012-08-12 19:19:46 -07:00
|
|
|
->addCancelButton($this->getApplicationURI()));
|
2011-01-26 10:40:38 -08:00
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
|
if ($list->getID()) {
|
2013-01-23 16:36:21 -08:00
|
|
|
$panel->setHeader(pht('Edit Mailing List'));
|
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
|
->setName(pht('Edit Mailing List'))
|
2013-02-19 13:33:10 -08:00
|
|
|
->setHref($this->getApplicationURI('/edit/'.$list->getID().'/')));
|
2011-01-26 10:40:38 -08:00
|
|
|
} else {
|
2013-01-23 16:36:21 -08:00
|
|
|
$panel->setHeader(pht('Create Mailing List'));
|
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
|
->setName(pht('Create Mailing List'))
|
2013-02-19 13:33:10 -08:00
|
|
|
->setHref($this->getApplicationURI('/edit/')));
|
2011-01-26 10:40:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$panel->appendChild($form);
|
|
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
2013-01-23 16:36:21 -08:00
|
|
|
$panel->setNoBackground();
|
2011-01-26 10:40:38 -08:00
|
|
|
|
2012-08-12 19:19:46 -07:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
array(
|
2013-01-23 16:36:21 -08:00
|
|
|
$crumbs,
|
2012-08-12 19:19:46 -07:00
|
|
|
$error_view,
|
|
|
|
|
$panel,
|
|
|
|
|
),
|
2011-01-26 10:40:38 -08:00
|
|
|
array(
|
2013-01-23 16:36:21 -08:00
|
|
|
'title' => pht('Edit Mailing List'),
|
|
|
|
|
'device' => true,
|
2011-01-26 10:40:38 -08:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|