2011-06-13 01:06:17 +02:00
|
|
|
<?php
|
|
|
|
|
2013-05-23 15:47:54 +02:00
|
|
|
/**
|
|
|
|
* @group countdown
|
|
|
|
*/
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorCountdownEditController
|
2011-06-13 01:06:17 +02:00
|
|
|
extends PhabricatorCountdownController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2011-08-01 22:46:25 +02:00
|
|
|
if ($this->id) {
|
2013-08-26 20:53:11 +02:00
|
|
|
$page_title = pht('Edit Countdown');
|
2013-07-22 23:42:25 +02:00
|
|
|
$countdown = id(new PhabricatorCountdownQuery())
|
2013-05-23 15:47:54 +02:00
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
2013-07-23 15:16:19 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2013-05-23 15:47:54 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$countdown) {
|
2011-06-13 01:06:17 +02:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
} else {
|
2013-08-26 20:53:11 +02:00
|
|
|
$page_title = pht('Create Countdown');
|
2013-10-16 19:36:08 +02:00
|
|
|
$countdown = PhabricatorCountdown::initializeNewCountdown($user);
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
2013-10-16 19:36:08 +02:00
|
|
|
$e_text = true;
|
|
|
|
$e_epoch = null;
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2014-02-05 14:33:14 +01:00
|
|
|
$errors = array();
|
2011-06-13 01:06:17 +02:00
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$title = $request->getStr('title');
|
2013-05-04 00:49:29 +02:00
|
|
|
$epoch = $request->getStr('epoch');
|
2013-10-16 19:36:08 +02:00
|
|
|
$view_policy = $request->getStr('viewPolicy');
|
2011-06-13 01:06:17 +02:00
|
|
|
|
|
|
|
$e_text = null;
|
|
|
|
if (!strlen($title)) {
|
2013-02-25 21:48:55 +01:00
|
|
|
$e_text = pht('Required');
|
2013-06-03 21:58:11 +02:00
|
|
|
$errors[] = pht('You must give the countdown a name.');
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 21:58:11 +02:00
|
|
|
if (strlen($epoch)) {
|
|
|
|
$timestamp = PhabricatorTime::parseLocalTime($epoch, $user);
|
|
|
|
if (!$timestamp) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'You entered an incorrect date. You can enter date '.
|
|
|
|
'like \'2011-06-26 13:33:37\' to create an event at '.
|
|
|
|
'13:33:37 on the 26th of June 2011.');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$e_epoch = pht('Required');
|
|
|
|
$errors[] = pht('You must specify the end date for a countdown.');
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!count($errors)) {
|
2013-06-03 21:58:11 +02:00
|
|
|
$countdown->setTitle($title);
|
|
|
|
$countdown->setEpoch($timestamp);
|
2013-10-16 19:36:08 +02:00
|
|
|
$countdown->setViewPolicy($view_policy);
|
2013-05-23 15:47:54 +02:00
|
|
|
$countdown->save();
|
2011-06-13 01:06:17 +02:00
|
|
|
return id(new AphrontRedirectResponse())
|
2013-05-23 15:47:54 +02:00
|
|
|
->setURI('/countdown/'.$countdown->getID().'/');
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 15:47:54 +02:00
|
|
|
if ($countdown->getEpoch()) {
|
2013-06-03 21:58:11 +02:00
|
|
|
$display_epoch = phabricator_datetime($countdown->getEpoch(), $user);
|
2011-06-26 19:51:59 +02:00
|
|
|
} else {
|
2013-05-04 00:49:29 +02:00
|
|
|
$display_epoch = $request->getStr('epoch');
|
2011-06-26 19:51:59 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
|
|
|
$cancel_uri = '/countdown/';
|
|
|
|
if ($countdown->getID()) {
|
|
|
|
$cancel_uri = '/countdown/'.$countdown->getID().'/';
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb('C'.$countdown->getID(), $cancel_uri);
|
|
|
|
$crumbs->addTextCrumb(pht('Edit'));
|
2013-07-23 15:16:19 +02:00
|
|
|
$submit_label = pht('Save Changes');
|
|
|
|
} else {
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Create Countdown'));
|
2013-07-23 15:16:19 +02:00
|
|
|
$submit_label = pht('Create Countdown');
|
|
|
|
}
|
|
|
|
|
2013-10-16 19:36:08 +02:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setObject($countdown)
|
|
|
|
->execute();
|
2013-07-23 15:16:19 +02:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setAction($request->getRequestURI()->getPath())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-02-25 21:48:55 +01:00
|
|
|
->setLabel(pht('Title'))
|
2013-05-23 15:47:54 +02:00
|
|
|
->setValue($countdown->getTitle())
|
2013-10-16 19:36:08 +02:00
|
|
|
->setName('title')
|
|
|
|
->setError($e_text))
|
2011-06-13 01:06:17 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-07-23 15:16:19 +02:00
|
|
|
->setLabel(pht('End Date'))
|
2013-05-04 00:49:29 +02:00
|
|
|
->setValue($display_epoch)
|
|
|
|
->setName('epoch')
|
2013-10-16 19:36:08 +02:00
|
|
|
->setError($e_epoch)
|
2013-02-25 21:48:55 +01:00
|
|
|
->setCaption(pht('Examples: '.
|
|
|
|
'2011-12-25 or 3 hours or '.
|
|
|
|
'June 8 2011, 5 PM.')))
|
2013-10-16 19:36:08 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('viewPolicy')
|
|
|
|
->setPolicyObject($countdown)
|
|
|
|
->setPolicies($policies)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
2011-06-13 01:06:17 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-07-23 15:16:19 +02:00
|
|
|
->addCancelButton($cancel_uri)
|
|
|
|
->setValue($submit_label));
|
|
|
|
|
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);
|
2013-02-25 21:48:55 +01:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
Countdown tweaks
Summary:
A few tweaks to hsb's Countdown implementation:
- Allow the page to be rendered "chromeless", suitable for display on one of
the dozens of monitors everyone has laying around.
- Show title of countdown in deletion dialog.
- When creating a new countdown default to time(), not Dec 31, 1969.
- Add extra "/" after editing to avoid needless redirect.
- Tweak some page titles.
- Show countdown author in list view.
- Highlight tab in list view.
- Tweak menu copy.
- Link countdown title in list view, separate buttons into different columns
so they pick up padding.
Test Plan:
Created, edited and deleted a timer. Viewed a timer and toggled chrome mode.
Viewed timer list.
Reviewed By: hsb
Reviewers: hsb, aran, jungejason, tuomaspelkonen
CC: aran, hsb, epriestley
Differential Revision: 454
2011-06-14 02:35:13 +02:00
|
|
|
array(
|
2013-02-25 21:48:55 +01:00
|
|
|
$crumbs,
|
2013-08-26 20:53:11 +02:00
|
|
|
$form_box,
|
2011-06-13 01:06:17 +02:00
|
|
|
),
|
|
|
|
array(
|
2013-08-26 20:53:11 +02:00
|
|
|
'title' => $page_title,
|
2013-02-25 21:48:55 +01:00
|
|
|
'device' => true,
|
2011-06-13 01:06:17 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|