2011-06-13 01:06:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PhabricatorCountdownEditController
|
|
|
|
extends PhabricatorCountdownController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
$action_label = 'Create Timer';
|
|
|
|
|
2011-08-01 22:46:25 +02:00
|
|
|
if ($this->id) {
|
2011-06-13 01:06:17 +02:00
|
|
|
$timer = id(new PhabricatorTimer())->load($this->id);
|
|
|
|
// If no timer is found
|
|
|
|
if (!$timer) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($timer->getAuthorPHID() != $user->getPHID())
|
|
|
|
&& $user->getIsAdmin() == false) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$action_label = 'Update Timer';
|
|
|
|
} else {
|
|
|
|
$timer = new PhabricatorTimer();
|
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
|
|
|
$timer->setDatePoint(time());
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
$e_text = null;
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$errors = array();
|
|
|
|
$title = $request->getStr('title');
|
|
|
|
$datepoint = $request->getStr('datepoint');
|
|
|
|
|
|
|
|
$e_text = null;
|
|
|
|
if (!strlen($title)) {
|
|
|
|
$e_text = 'Required';
|
2011-06-26 19:51:59 +02:00
|
|
|
$errors[] = 'You must give it a name.';
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
2011-06-26 19:51:59 +02:00
|
|
|
// If the user types something like "5 PM", convert it to a timestamp
|
|
|
|
// using their local time, not the server time.
|
|
|
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
|
|
|
|
|
|
|
try {
|
|
|
|
$date = new DateTime($datepoint, $timezone);
|
|
|
|
$timestamp = $date->format('U');
|
|
|
|
} catch (Exception $e) {
|
2011-06-13 01:06:17 +02:00
|
|
|
$errors[] = 'You entered an incorrect date. You can enter date like'.
|
|
|
|
' \'2011-06-26 13:33:37\' to create an event at'.
|
2011-06-26 19:51:59 +02:00
|
|
|
' 13:33:37 on the 26th of June 2011.';
|
|
|
|
$timestamp = null;
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$timer->setTitle($title);
|
|
|
|
$timer->setDatePoint($timestamp);
|
|
|
|
|
|
|
|
if (!count($errors)) {
|
|
|
|
$timer->setAuthorPHID($user->getPHID());
|
|
|
|
$timer->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
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
|
|
|
->setURI('/countdown/'.$timer->getID().'/');
|
2011-06-26 19:51:59 +02:00
|
|
|
} else {
|
2011-06-13 01:06:17 +02:00
|
|
|
$error_view = id(new AphrontErrorView())
|
|
|
|
->setErrors($errors)
|
|
|
|
->setTitle('It\'s not The Final Countdown (du nu nuuu nun)' .
|
|
|
|
' until you fix these problem');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 19:51:59 +02:00
|
|
|
if ($timer->getDatePoint()) {
|
|
|
|
$display_datepoint = phabricator_datetime(
|
|
|
|
$timer->getDatePoint(),
|
|
|
|
$user);
|
|
|
|
} else {
|
|
|
|
$display_datepoint = $request->getStr('datepoint');
|
|
|
|
}
|
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setAction($request->getRequestURI()->getPath())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Title')
|
|
|
|
->setValue($timer->getTitle())
|
|
|
|
->setName('title'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('End date')
|
2011-06-26 19:51:59 +02:00
|
|
|
->setValue($display_datepoint)
|
2011-06-13 01:06:17 +02:00
|
|
|
->setName('datepoint')
|
2011-06-26 19:51:59 +02:00
|
|
|
->setCaption(
|
|
|
|
'Examples: '.
|
|
|
|
'<tt>2011-12-25</tt> or '.
|
|
|
|
'<tt>3 hours</tt> or '.
|
|
|
|
'<tt>June 8 2011, 5 PM</tt>.'))
|
2011-06-13 01:06:17 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton('/countdown/')
|
|
|
|
->setValue($action_label));
|
|
|
|
|
|
|
|
$panel = id(new AphrontPanelView())
|
|
|
|
->setWidth(AphrontPanelView::WIDTH_FORM)
|
|
|
|
->setHeader($action_label)
|
|
|
|
->appendChild($form);
|
|
|
|
|
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
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
2011-06-13 01:06:17 +02:00
|
|
|
$error_view,
|
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
|
|
|
$panel,
|
2011-06-13 01:06:17 +02:00
|
|
|
),
|
|
|
|
array(
|
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
|
|
|
'title' => 'Edit Countdown',
|
2011-06-13 01:06:17 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|