2013-01-24 17:23:05 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class ConpherenceNewController extends ConpherenceController {
|
|
|
|
|
|
2015-03-26 16:46:47 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2013-01-24 17:23:05 -08:00
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
2013-04-15 16:27:41 -07:00
|
|
|
$title = pht('New Message');
|
2013-01-24 17:23:05 -08:00
|
|
|
$participants = array();
|
2013-10-07 12:51:24 -07:00
|
|
|
$participant_prefill = null;
|
2013-01-24 17:23:05 -08:00
|
|
|
$message = '';
|
|
|
|
|
$e_participants = null;
|
|
|
|
|
$e_message = null;
|
2015-02-16 11:31:00 -08:00
|
|
|
$errors = array();
|
2013-01-24 17:23:05 -08:00
|
|
|
|
|
|
|
|
// this comes from ajax requests from all over. should be a single phid.
|
|
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
$participants = $request->getArr('participants');
|
|
|
|
|
$message = $request->getStr('message');
|
2015-03-26 13:35:48 -07:00
|
|
|
list($error_codes, $conpherence) = ConpherenceEditor::createThread(
|
2013-05-30 16:37:51 -07:00
|
|
|
$user,
|
|
|
|
|
$participants,
|
|
|
|
|
$conpherence_title = null,
|
|
|
|
|
$message,
|
|
|
|
|
PhabricatorContentSource::newFromRequest($request));
|
2013-01-24 17:23:05 -08:00
|
|
|
|
2013-05-30 16:37:51 -07:00
|
|
|
if ($error_codes) {
|
|
|
|
|
foreach ($error_codes as $error_code) {
|
|
|
|
|
switch ($error_code) {
|
|
|
|
|
case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
|
2015-02-16 11:31:00 -08:00
|
|
|
$e_message = pht('Required');
|
|
|
|
|
$errors[] = pht(
|
|
|
|
|
'You can not send an empty message.');
|
2013-05-30 16:37:51 -07:00
|
|
|
break;
|
|
|
|
|
case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
|
2015-02-16 11:31:00 -08:00
|
|
|
$e_participants = pht('Required');
|
|
|
|
|
$errors[] = pht(
|
|
|
|
|
'You must choose at least one recipient for your '.
|
|
|
|
|
'message.');
|
2013-05-30 16:37:51 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2013-01-25 16:03:54 -08:00
|
|
|
}
|
2013-05-30 16:37:51 -07:00
|
|
|
} else {
|
2013-05-01 14:42:58 -07:00
|
|
|
$uri = $this->getApplicationURI($conpherence->getID());
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
|
->setURI($uri);
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
2013-10-07 12:51:24 -07:00
|
|
|
} else {
|
|
|
|
|
$participant_prefill = $request->getStr('participant');
|
|
|
|
|
if ($participant_prefill) {
|
|
|
|
|
$participants[] = $participant_prefill;
|
|
|
|
|
}
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$submit_uri = $this->getApplicationURI('new/');
|
|
|
|
|
$cancel_uri = $this->getApplicationURI();
|
2013-03-31 12:44:12 -07:00
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
2015-02-16 11:31:00 -08:00
|
|
|
->setErrors($errors)
|
2013-03-31 12:44:12 -07:00
|
|
|
->setUser($user)
|
|
|
|
|
->setTitle($title)
|
|
|
|
|
->addCancelButton($cancel_uri)
|
2013-04-15 16:27:41 -07:00
|
|
|
->addSubmitButton(pht('Send Message'));
|
2013-03-31 12:44:12 -07:00
|
|
|
|
2015-03-31 14:10:55 -07:00
|
|
|
$form = id(new AphrontFormView())
|
2013-01-24 17:23:05 -08:00
|
|
|
->setUser($user)
|
2013-05-14 12:21:00 -07:00
|
|
|
->setFullWidth(true)
|
2015-03-31 14:10:55 -07:00
|
|
|
->appendControl(
|
2013-01-24 17:23:05 -08:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2015-03-31 14:10:55 -07:00
|
|
|
->setName('participants')
|
|
|
|
|
->setValue($participants)
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
|
|
|
|
->setLabel(pht('To'))
|
|
|
|
|
->setError($e_participants))
|
2013-01-24 17:23:05 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new PhabricatorRemarkupControl())
|
2014-11-24 15:25:25 -08:00
|
|
|
->setUser($user)
|
|
|
|
|
->setName('message')
|
|
|
|
|
->setValue($message)
|
|
|
|
|
->setLabel(pht('Message'))
|
|
|
|
|
->setError($e_message));
|
2013-01-24 17:23:05 -08:00
|
|
|
|
2015-03-31 14:10:55 -07:00
|
|
|
$dialog->appendForm($form);
|
2013-01-24 17:23:05 -08:00
|
|
|
|
2013-03-31 12:44:12 -07:00
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
2014-07-10 08:12:48 +10:00
|
|
|
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|