From dbac6580257094323056a8c48b9d02ee0dabb7e5 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Sat, 16 May 2015 17:21:37 -0700 Subject: [PATCH] Split up settings into "Date and Time Settings" and everything else. Summary: Ref T8176, Split up settings into "Date and Time Settings" and everything else. Test Plan: Open /settings, Account Settings should now have two tabs: "Account" and "Date and Time" Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T8176 Differential Revision: https://secure.phabricator.com/D12881 --- src/__phutil_library_map__.php | 2 + .../panel/PhabricatorAccountSettingsPanel.php | 50 +---------- .../PhabricatorDateTimeSettingsPanel.php | 89 +++++++++++++++++++ 3 files changed, 95 insertions(+), 46 deletions(-) create mode 100644 src/applications/settings/panel/PhabricatorDateTimeSettingsPanel.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3ccb046634..edadae1253 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1742,6 +1742,7 @@ phutil_register_library_map(array( 'PhabricatorDataCacheSpec' => 'applications/cache/spec/PhabricatorDataCacheSpec.php', 'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php', 'PhabricatorDatabaseSetupCheck' => 'applications/config/check/PhabricatorDatabaseSetupCheck.php', + 'PhabricatorDateTimeSettingsPanel' => 'applications/settings/panel/PhabricatorDateTimeSettingsPanel.php', 'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php', 'PhabricatorDefaultSearchEngineSelector' => 'applications/search/selector/PhabricatorDefaultSearchEngineSelector.php', 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', @@ -5134,6 +5135,7 @@ phutil_register_library_map(array( 'PhabricatorDataCacheSpec' => 'PhabricatorCacheSpec', 'PhabricatorDataNotAttachedException' => 'Exception', 'PhabricatorDatabaseSetupCheck' => 'PhabricatorSetupCheck', + 'PhabricatorDateTimeSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorDebugController' => 'PhabricatorController', 'PhabricatorDefaultSearchEngineSelector' => 'PhabricatorSearchEngineSelector', 'PhabricatorDestructionEngine' => 'Phobject', diff --git a/src/applications/settings/panel/PhabricatorAccountSettingsPanel.php b/src/applications/settings/panel/PhabricatorAccountSettingsPanel.php index 9353d9523f..7acd5e0a54 100644 --- a/src/applications/settings/panel/PhabricatorAccountSettingsPanel.php +++ b/src/applications/settings/panel/PhabricatorAccountSettingsPanel.php @@ -18,18 +18,8 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel { $user = $request->getUser(); $username = $user->getUsername(); - $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; - $preferences = $user->loadPreferences(); - $errors = array(); if ($request->isFormPost()) { - $new_timezone = $request->getStr('timezone'); - if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { - $user->setTimezoneIdentifier($new_timezone); - } else { - $errors[] = pht('The selected timezone is not a valid timezone.'); - } - $sex = $request->getStr('sex'); $sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE); if (in_array($sex, $sexes)) { @@ -41,19 +31,13 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel { // Checked in runtime. $user->setTranslation($request->getStr('translation')); - $preferences->setPreference($pref_time, $request->getStr($pref_time)); - if (!$errors) { - $preferences->save(); $user->save(); return id(new AphrontRedirectResponse()) ->setURI($this->getPanelURI('?saved=true')); } } - $timezone_ids = DateTimeZone::listIdentifiers(); - $timezone_id_map = array_fuse($timezone_ids); - $label_unknown = pht('%s updated their profile', $username); $label_her = pht('%s updated her profile', $username); $label_his = pht('%s updated his profile', $username); @@ -93,10 +77,10 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel { ->setUser($user) ->appendChild( id(new AphrontFormSelectControl()) - ->setLabel(pht('Timezone')) - ->setName('timezone') - ->setOptions($timezone_id_map) - ->setValue($user->getTimezoneIdentifier())) + ->setOptions($translations) + ->setLabel(pht('Translation')) + ->setName('translation') + ->setValue($user->getTranslation())) ->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**')) ->appendChild( id(new AphrontFormSelectControl()) @@ -104,32 +88,6 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel { ->setLabel(pht('Pronoun')) ->setName('sex') ->setValue($user->getSex())) - ->appendChild( - id(new AphrontFormSelectControl()) - ->setOptions($translations) - ->setLabel(pht('Translation')) - ->setName('translation') - ->setValue($user->getTranslation())) - ->appendRemarkupInstructions( - pht( - "**Custom Date and Time Formats**\n\n". - "You can specify custom formats which will be used when ". - "rendering dates and times of day. Examples:\n\n". - "| Format | Example | Notes |\n". - "| ------ | -------- | ----- |\n". - "| `g:i A` | 2:34 PM | Default 12-hour time. |\n". - "| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n". - "| `H:i` | 14:34 | 24-hour time. |\n". - "\n\n". - "You can find a [[%s | full reference in the PHP manual]].", - 'http://www.php.net/manual/en/function.date.php')) - ->appendChild( - id(new AphrontFormTextControl()) - ->setLabel(pht('Time-of-Day Format')) - ->setName($pref_time) - ->setCaption( - pht('Format used when rendering a time of day.')) - ->setValue($preferences->getPreference($pref_time))) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Save Account Settings'))); diff --git a/src/applications/settings/panel/PhabricatorDateTimeSettingsPanel.php b/src/applications/settings/panel/PhabricatorDateTimeSettingsPanel.php new file mode 100644 index 0000000000..661a1172b7 --- /dev/null +++ b/src/applications/settings/panel/PhabricatorDateTimeSettingsPanel.php @@ -0,0 +1,89 @@ +getUser(); + $username = $user->getUsername(); + + $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; + $preferences = $user->loadPreferences(); + + $errors = array(); + if ($request->isFormPost()) { + $new_timezone = $request->getStr('timezone'); + if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { + $user->setTimezoneIdentifier($new_timezone); + } else { + $errors[] = pht('The selected timezone is not a valid timezone.'); + } + + $preferences->setPreference($pref_time, $request->getStr($pref_time)); + + if (!$errors) { + $preferences->save(); + $user->save(); + return id(new AphrontRedirectResponse()) + ->setURI($this->getPanelURI('?saved=true')); + } + } + + $timezone_ids = DateTimeZone::listIdentifiers(); + $timezone_id_map = array_fuse($timezone_ids); + + $form = new AphrontFormView(); + $form + ->setUser($user) + ->appendChild( + id(new AphrontFormSelectControl()) + ->setLabel(pht('Timezone')) + ->setName('timezone') + ->setOptions($timezone_id_map) + ->setValue($user->getTimezoneIdentifier())) + ->appendRemarkupInstructions( + pht( + "**Custom Date and Time Formats**\n\n". + "You can specify custom formats which will be used when ". + "rendering dates and times of day. Examples:\n\n". + "| Format | Example | Notes |\n". + "| ------ | -------- | ----- |\n". + "| `g:i A` | 2:34 PM | Default 12-hour time. |\n". + "| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n". + "| `H:i` | 14:34 | 24-hour time. |\n". + "\n\n". + "You can find a [[%s | full reference in the PHP manual]].", + 'http://www.php.net/manual/en/function.date.php')) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel(pht('Time-of-Day Format')) + ->setName($pref_time) + ->setCaption( + pht('Format used when rendering a time of day.')) + ->setValue($preferences->getPreference($pref_time))) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue(pht('Save Account Settings'))); + + $form_box = id(new PHUIObjectBoxView()) + ->setHeaderText(pht('Date and Time Settings')) + ->setFormSaved($request->getStr('saved')) + ->setFormErrors($errors) + ->setForm($form); + + return array( + $form_box, + ); + } +}