1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Refactor most uses of AphrontFormDateControl to user AphrontFormDateControlValue

Summary: Ref T8024, Refactor most uses of `AphrontFormDateControl` to user `AphrontFormDateControlValue`

Test Plan: Countdown and Phrequent should now save form data in error state.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8024

Differential Revision: https://secure.phabricator.com/D12731
This commit is contained in:
lkassianik 2015-05-05 19:19:20 -07:00
parent 179948e232
commit 4cbdd0c6e9
4 changed files with 52 additions and 101 deletions

View file

@ -1906,7 +1906,6 @@ phutil_register_library_map(array(
'PhabricatorFlaggableInterface' => 'applications/flag/interface/PhabricatorFlaggableInterface.php',
'PhabricatorFlagsApplication' => 'applications/flag/application/PhabricatorFlagsApplication.php',
'PhabricatorFlagsUIEventListener' => 'applications/flag/events/PhabricatorFlagsUIEventListener.php',
'PhabricatorFormUIExample' => 'applications/uiexample/examples/PhabricatorFormUIExample.php',
'PhabricatorFundApplication' => 'applications/fund/application/PhabricatorFundApplication.php',
'PhabricatorGDSetupCheck' => 'applications/config/check/PhabricatorGDSetupCheck.php',
'PhabricatorGarbageCollector' => 'infrastructure/daemon/garbagecollector/PhabricatorGarbageCollector.php',
@ -5311,7 +5310,6 @@ phutil_register_library_map(array(
'PhabricatorFlaggableInterface' => 'PhabricatorPHIDInterface',
'PhabricatorFlagsApplication' => 'PhabricatorApplication',
'PhabricatorFlagsUIEventListener' => 'PhabricatorEventListener',
'PhabricatorFormUIExample' => 'PhabricatorUIExample',
'PhabricatorFundApplication' => 'PhabricatorApplication',
'PhabricatorGDSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorGarbageCollector' => 'Phobject',

View file

@ -12,11 +12,6 @@ final class PhabricatorCountdownEditController
$request = $this->getRequest();
$user = $request->getUser();
$epoch_control = id(new AphrontFormDateControl())
->setUser($user)
->setName('epoch')
->setLabel(pht('End Date'))
->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY);
if ($this->id) {
$page_title = pht('Edit Countdown');
@ -32,31 +27,41 @@ final class PhabricatorCountdownEditController
if (!$countdown) {
return new Aphront404Response();
}
$date_value = AphrontFormDateControlValue::newFromEpoch(
$user,
$countdown->getEpoch());
} else {
$page_title = pht('Create Countdown');
$countdown = PhabricatorCountdown::initializeNewCountdown($user);
$date_value = AphrontFormDateControlValue::newFromEpoch($user, time());
}
$epoch_control->setValue($countdown->getEpoch());
$e_text = true;
$errors = array();
$e_text = true;
$e_epoch = null;
$v_text = $countdown->getTitle();
if ($request->isFormPost()) {
$title = $request->getStr('title');
$epoch = $epoch_control->readValueFromRequest($request);
$v_text = $request->getStr('title');
$date_value = AphrontFormDateControlValue::newFromRequest(
$request,
'epoch');
$view_policy = $request->getStr('viewPolicy');
$e_text = null;
if (!strlen($title)) {
if (!strlen($v_text)) {
$e_text = pht('Required');
$errors[] = pht('You must give the countdown a name.');
}
if (!$epoch) {
if (!$date_value->isValid()) {
$e_epoch = pht('Invalid');
$errors[] = pht('You must give the countdown a valid end date.');
}
if (!count($errors)) {
$countdown->setTitle($title);
$countdown->setEpoch($epoch);
$countdown->setTitle($v_text);
$countdown->setEpoch($date_value->getEpoch());
$countdown->setViewPolicy($view_policy);
$countdown->save();
return id(new AphrontRedirectResponse())
@ -64,12 +69,6 @@ final class PhabricatorCountdownEditController
}
}
if ($countdown->getEpoch()) {
$display_epoch = phabricator_datetime($countdown->getEpoch(), $user);
} else {
$display_epoch = $request->getStr('epoch');
}
$crumbs = $this->buildApplicationCrumbs();
$cancel_uri = '/countdown/';
@ -94,10 +93,16 @@ final class PhabricatorCountdownEditController
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Title'))
->setValue($countdown->getTitle())
->setValue($v_text)
->setName('title')
->setError($e_text))
->appendChild($epoch_control)
->appendChild(
id(new AphrontFormDateControl())
->setUser($user)
->setName('epoch')
->setLabel(pht('End Date'))
->setError($e_epoch)
->setValue($date_value))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)

View file

@ -62,22 +62,22 @@ final class PhrequentTrackController
$v_note = null;
$e_date = null;
$epoch_control = id(new AphrontFormDateControl())
->setUser($viewer)
->setName('epoch')
->setLabel($action_text)
->setValue(time());
$timestamp = AphrontFormDateControlValue::newFromEpoch(
$viewer,
time());
if ($request->isDialogFormPost()) {
$v_note = $request->getStr('note');
$timestamp = $epoch_control->readValueFromRequest($request);
$timestamp = AphrontFormDateControlValue::newFromRequest(
$request,
'epoch');
if (!$epoch_control->isValid()) {
$errors[] = pht('Please choose an valid date.');
if (!$timestamp->isValid()) {
$errors[] = pht('Please choose a valid date.');
$e_date = pht('Invalid');
} else {
$max_time = PhabricatorTime::getNow();
if ($timestamp > $max_time) {
if ($timestamp->getEpoch() > $max_time) {
if ($this->isStoppingTracking()) {
$errors[] = pht(
'You can not stop tracking time at a future time. Enter the '.
@ -92,7 +92,7 @@ final class PhrequentTrackController
if ($this->isStoppingTracking()) {
$min_time = $current_timer->getDateStarted();
if ($min_time > $timestamp) {
if ($min_time > $timestamp->getEpoch()) {
$errors[] = pht(
'Stop time must be after start time.');
$e_date = pht('Invalid');
@ -103,9 +103,16 @@ final class PhrequentTrackController
if (!$errors) {
$editor = new PhrequentTrackingEditor();
if ($this->isStartingTracking()) {
$editor->startTracking($viewer, $this->phid, $timestamp);
$editor->startTracking(
$viewer,
$this->phid,
$timestamp->getEpoch());
} else if ($this->isStoppingTracking()) {
$editor->stopTracking($viewer, $this->phid, $timestamp, $v_note);
$editor->stopTracking(
$viewer,
$this->phid,
$timestamp->getEpoch(),
$v_note);
}
return id(new AphrontRedirectResponse())->setURI($done_uri);
@ -113,8 +120,6 @@ final class PhrequentTrackController
}
$epoch_control->setError($e_date);
$dialog = $this->newDialog()
->setTitle($title_text)
->setWidth(AphrontDialogView::WIDTH_FORM)
@ -136,7 +141,13 @@ final class PhrequentTrackController
->setValue($start_string));
}
$form->appendChild($epoch_control);
$form->appendChild(
id(new AphrontFormDateControl())
->setUser($viewer)
->setName('epoch')
->setLabel($action_text)
->setError($e_date)
->setValue($timestamp));
if ($this->isStoppingTracking()) {
$form->appendChild(

View file

@ -1,63 +0,0 @@
<?php
final class PhabricatorFormUIExample extends PhabricatorUIExample {
public function getName() {
return 'Form';
}
public function getDescription() {
return hsprintf('Use <tt>AphrontFormView</tt> to render forms.');
}
public function renderExample() {
$request = $this->getRequest();
$user = $request->getUser();
$start_time = id(new AphrontFormDateControl())
->setUser($user)
->setName('start')
->setLabel('Start')
->setInitialTime(AphrontFormDateControl::TIME_START_OF_BUSINESS);
$end_time = id(new AphrontFormDateControl())
->setUser($user)
->setName('end')
->setLabel('End')
->setInitialTime(AphrontFormDateControl::TIME_END_OF_BUSINESS);
$null_time = id(new AphrontFormDateControl())
->setUser($user)
->setName('nulltime')
->setLabel('Nullable')
->setAllowNull(true);
if ($request->isFormPost()) {
$start_value = $start_time->readValueFromRequest($request);
$end_value = $end_time->readValueFromRequest($request);
$null_value = $null_time->readValueFromRequest($request);
}
$divider_control = new AphrontFormDividerControl();
$credentials = array();
$password_control = id(new PassphraseCredentialControl())
->setName('credentialPHID')
->setLabel(pht('Password'))
->setCredentialType('password')
->setOptions($credentials);
$form = id(new AphrontFormView())
->setUser($user)
->appendChild($start_time)
->appendChild($end_time)
->appendChild($null_time)
->appendChild($divider_control)
->appendChild($password_control)
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Submit'));
return $form;
}
}