1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-22 19:49:02 +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', 'PhabricatorFlaggableInterface' => 'applications/flag/interface/PhabricatorFlaggableInterface.php',
'PhabricatorFlagsApplication' => 'applications/flag/application/PhabricatorFlagsApplication.php', 'PhabricatorFlagsApplication' => 'applications/flag/application/PhabricatorFlagsApplication.php',
'PhabricatorFlagsUIEventListener' => 'applications/flag/events/PhabricatorFlagsUIEventListener.php', 'PhabricatorFlagsUIEventListener' => 'applications/flag/events/PhabricatorFlagsUIEventListener.php',
'PhabricatorFormUIExample' => 'applications/uiexample/examples/PhabricatorFormUIExample.php',
'PhabricatorFundApplication' => 'applications/fund/application/PhabricatorFundApplication.php', 'PhabricatorFundApplication' => 'applications/fund/application/PhabricatorFundApplication.php',
'PhabricatorGDSetupCheck' => 'applications/config/check/PhabricatorGDSetupCheck.php', 'PhabricatorGDSetupCheck' => 'applications/config/check/PhabricatorGDSetupCheck.php',
'PhabricatorGarbageCollector' => 'infrastructure/daemon/garbagecollector/PhabricatorGarbageCollector.php', 'PhabricatorGarbageCollector' => 'infrastructure/daemon/garbagecollector/PhabricatorGarbageCollector.php',
@ -5311,7 +5310,6 @@ phutil_register_library_map(array(
'PhabricatorFlaggableInterface' => 'PhabricatorPHIDInterface', 'PhabricatorFlaggableInterface' => 'PhabricatorPHIDInterface',
'PhabricatorFlagsApplication' => 'PhabricatorApplication', 'PhabricatorFlagsApplication' => 'PhabricatorApplication',
'PhabricatorFlagsUIEventListener' => 'PhabricatorEventListener', 'PhabricatorFlagsUIEventListener' => 'PhabricatorEventListener',
'PhabricatorFormUIExample' => 'PhabricatorUIExample',
'PhabricatorFundApplication' => 'PhabricatorApplication', 'PhabricatorFundApplication' => 'PhabricatorApplication',
'PhabricatorGDSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorGDSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorGarbageCollector' => 'Phobject', 'PhabricatorGarbageCollector' => 'Phobject',

View file

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

View file

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