1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 05:20:56 +01:00

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
This commit is contained in:
lkassianik 2015-05-16 17:21:37 -07:00
parent 72a896f772
commit dbac658025
3 changed files with 95 additions and 46 deletions

View file

@ -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',

View file

@ -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')));

View file

@ -0,0 +1,89 @@
<?php
final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'datetime';
}
public function getPanelName() {
return pht('Date and Time');
}
public function getPanelGroup() {
return pht('Account Information');
}
public function processRequest(AphrontRequest $request) {
$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.');
}
$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,
);
}
}