2012-10-24 22:22:24 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 19:10:07 +01:00
|
|
|
final class PhabricatorCalendarEventEditController
|
2012-10-24 22:22:24 +02:00
|
|
|
extends PhabricatorCalendarController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isCreate() {
|
|
|
|
return !$this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$start_time = id(new AphrontFormDateControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('start')
|
|
|
|
->setLabel(pht('Start'))
|
|
|
|
->setInitialTime(AphrontFormDateControl::TIME_START_OF_DAY);
|
|
|
|
|
|
|
|
$end_time = id(new AphrontFormDateControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('end')
|
|
|
|
->setLabel(pht('End'))
|
|
|
|
->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY);
|
|
|
|
|
|
|
|
if ($this->isCreate()) {
|
2014-02-06 19:07:29 +01:00
|
|
|
$status = new PhabricatorCalendarEvent();
|
2012-10-24 22:22:24 +02:00
|
|
|
$end_value = $end_time->readValueFromRequest($request);
|
|
|
|
$start_value = $start_time->readValueFromRequest($request);
|
|
|
|
$submit_label = pht('Create');
|
|
|
|
$filter = 'status/create/';
|
2014-02-06 19:10:07 +01:00
|
|
|
$page_title = pht('Create Event');
|
2012-10-24 22:22:24 +02:00
|
|
|
$redirect = 'created';
|
|
|
|
} else {
|
2014-02-06 19:07:42 +01:00
|
|
|
$status = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2014-03-22 03:11:48 +01:00
|
|
|
if (!$status) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-02-06 19:07:42 +01:00
|
|
|
|
2012-10-24 22:22:24 +02:00
|
|
|
$end_time->setValue($status->getDateTo());
|
|
|
|
$start_time->setValue($status->getDateFrom());
|
|
|
|
$submit_label = pht('Update');
|
2014-02-06 19:10:07 +01:00
|
|
|
$filter = 'event/edit/'.$status->getID().'/';
|
|
|
|
$page_title = pht('Update Event');
|
2012-10-24 22:22:24 +02:00
|
|
|
$redirect = 'updated';
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$type = $request->getInt('status');
|
|
|
|
$start_value = $start_time->readValueFromRequest($request);
|
|
|
|
$end_value = $end_time->readValueFromRequest($request);
|
|
|
|
$description = $request->getStr('description');
|
|
|
|
|
|
|
|
try {
|
|
|
|
$status
|
|
|
|
->setUserPHID($user->getPHID())
|
|
|
|
->setStatus($type)
|
|
|
|
->setDateFrom($start_value)
|
|
|
|
->setDateTo($end_value)
|
|
|
|
->setDescription($description)
|
|
|
|
->save();
|
2014-02-06 19:07:29 +01:00
|
|
|
} catch (PhabricatorCalendarEventInvalidEpochException $e) {
|
2013-02-23 16:12:36 +01:00
|
|
|
$errors[] = pht('Start must be before end.');
|
2012-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$uri = new PhutilURI($this->getApplicationURI());
|
|
|
|
$uri->setQueryParams(
|
|
|
|
array(
|
|
|
|
'month' => phabricator_format_local_time($status->getDateFrom(),
|
|
|
|
$user,
|
|
|
|
'm'),
|
|
|
|
'year' => phabricator_format_local_time($status->getDateFrom(),
|
|
|
|
$user,
|
|
|
|
'Y'),
|
|
|
|
$redirect => true,
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2013-05-29 23:35:34 +02:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
$response = id(new AphrontAjaxResponse())
|
|
|
|
->setContent(array('redirect_uri' => $uri));
|
|
|
|
} else {
|
|
|
|
$response = id(new AphrontRedirectResponse())
|
|
|
|
->setURI($uri);
|
|
|
|
}
|
|
|
|
return $response;
|
2012-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
if ($errors) {
|
2015-03-01 23:45:56 +01:00
|
|
|
$error_view = id(new PHUIInfoView())
|
2013-02-23 16:12:36 +01:00
|
|
|
->setTitle(pht('Status can not be set!'))
|
2012-10-24 22:22:24 +02:00
|
|
|
->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
$status_select = id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setName('status')
|
2012-11-12 22:28:45 +01:00
|
|
|
->setValue($status->getStatus())
|
2012-10-24 22:22:24 +02:00
|
|
|
->setOptions($status->getStatusOptions());
|
|
|
|
|
|
|
|
$description = id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setName('description')
|
|
|
|
->setValue($status->getDescription());
|
|
|
|
|
2013-05-29 23:35:34 +02:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle($page_title)
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM);
|
|
|
|
if ($this->isCreate()) {
|
2014-02-06 19:10:07 +01:00
|
|
|
$dialog->setSubmitURI($this->getApplicationURI('event/create/'));
|
2013-05-29 23:35:34 +02:00
|
|
|
} else {
|
|
|
|
$dialog->setSubmitURI(
|
2014-02-06 19:10:07 +01:00
|
|
|
$this->getApplicationURI('event/edit/'.$status->getID().'/'));
|
2013-05-29 23:35:34 +02:00
|
|
|
}
|
2013-08-26 20:53:11 +02:00
|
|
|
$form = new PHUIFormLayoutView();
|
2013-05-29 23:35:34 +02:00
|
|
|
if ($error_view) {
|
|
|
|
$form->appendChild($error_view);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$form = id(new AphrontFormView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setUser($user);
|
2013-05-29 23:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
2012-10-24 22:22:24 +02:00
|
|
|
->appendChild($status_select)
|
|
|
|
->appendChild($start_time)
|
|
|
|
->appendChild($end_time)
|
|
|
|
->appendChild($description);
|
|
|
|
|
2013-05-29 23:35:34 +02:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
$dialog->addSubmitButton($submit_label);
|
|
|
|
$submit = $dialog;
|
|
|
|
} else {
|
|
|
|
$submit = id(new AphrontFormSubmitControl())
|
|
|
|
->setValue($submit_label);
|
|
|
|
}
|
2012-10-24 22:22:24 +02:00
|
|
|
if ($this->isCreate()) {
|
|
|
|
$submit->addCancelButton($this->getApplicationURI());
|
|
|
|
} else {
|
|
|
|
$submit->addCancelButton(
|
2014-02-06 19:10:27 +01:00
|
|
|
$this->getApplicationURI('event/view/'.$status->getID().'/'));
|
2012-10-24 22:22:24 +02:00
|
|
|
}
|
2013-05-29 23:35:34 +02:00
|
|
|
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
$dialog->appendChild($form);
|
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog($dialog);
|
|
|
|
}
|
2012-10-24 22:22:24 +02:00
|
|
|
$form->appendChild($submit);
|
|
|
|
|
2014-02-18 01:08:50 +01:00
|
|
|
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText($page_title)
|
2014-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors)
|
2013-08-26 20:53:11 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
2012-10-24 22:22:24 +02:00
|
|
|
$nav = $this->buildSideNavView($status);
|
|
|
|
$nav->selectFilter($filter);
|
|
|
|
|
2014-02-18 01:08:50 +01:00
|
|
|
$crumbs = $this
|
|
|
|
->buildApplicationCrumbs()
|
|
|
|
->addTextCrumb($page_title);
|
|
|
|
|
2012-10-24 22:22:24 +02:00
|
|
|
$nav->appendChild(
|
|
|
|
array(
|
2014-02-18 01:08:50 +01:00
|
|
|
$crumbs,
|
2013-08-26 20:53:11 +02:00
|
|
|
$form_box,
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2012-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
|
|
|
array(
|
|
|
|
'title' => $page_title,
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2012-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|