1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-03 19:31:02 +01:00

Merge "Profile" and "Account" settings panels

Summary: There are only a total of three options now, merge them into a single panel.

Test Plan:
Set all the settings.

{F49406}

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D6400
This commit is contained in:
epriestley 2013-07-10 05:09:50 -07:00
parent 63b4183d9a
commit c20b7540c9
3 changed files with 48 additions and 121 deletions

View file

@ -1496,7 +1496,6 @@ phutil_register_library_map(array(
'PhabricatorSettingsPanelExternalAccounts' => 'applications/settings/panel/PhabricatorSettingsPanelExternalAccounts.php',
'PhabricatorSettingsPanelHomePreferences' => 'applications/settings/panel/PhabricatorSettingsPanelHomePreferences.php',
'PhabricatorSettingsPanelPassword' => 'applications/settings/panel/PhabricatorSettingsPanelPassword.php',
'PhabricatorSettingsPanelProfile' => 'applications/settings/panel/PhabricatorSettingsPanelProfile.php',
'PhabricatorSettingsPanelSSHKeys' => 'applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php',
'PhabricatorSettingsPanelSearchPreferences' => 'applications/settings/panel/PhabricatorSettingsPanelSearchPreferences.php',
'PhabricatorSetupCheck' => 'applications/config/check/PhabricatorSetupCheck.php',
@ -3448,7 +3447,6 @@ phutil_register_library_map(array(
'PhabricatorSettingsPanelExternalAccounts' => 'PhabricatorSettingsPanel',
'PhabricatorSettingsPanelHomePreferences' => 'PhabricatorSettingsPanel',
'PhabricatorSettingsPanelPassword' => 'PhabricatorSettingsPanel',
'PhabricatorSettingsPanelProfile' => 'PhabricatorSettingsPanel',
'PhabricatorSettingsPanelSSHKeys' => 'PhabricatorSettingsPanel',
'PhabricatorSettingsPanelSearchPreferences' => 'PhabricatorSettingsPanel',
'PhabricatorSetupCheckAPC' => 'PhabricatorSetupCheck',

View file

@ -26,6 +26,17 @@ final class PhabricatorSettingsPanelAccount
$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)) {
$user->setSex($sex);
} else {
$user->setSex(null);
}
// Checked in runtime.
$user->setTranslation($request->getStr('translation'));
if (!$errors) {
$user->save();
return id(new AphrontRedirectResponse())
@ -45,30 +56,60 @@ final class PhabricatorSettingsPanelAccount
}
} else {
$notice = new AphrontErrorView();
$notice->setTitle(pht('Form Errors'));
$notice->setErrors($errors);
$notice = $notice->render();
}
$timezone_ids = DateTimeZone::listIdentifiers();
$timezone_id_map = array_fuse($timezone_ids);
$sexes = array(
PhutilPerson::SEX_UNKNOWN => pht('Unspecified'),
PhutilPerson::SEX_MALE => pht('Male'),
PhutilPerson::SEX_FEMALE => pht('Female'),
);
$translations = array();
$symbols = id(new PhutilSymbolLoader())
->setType('class')
->setAncestorClass('PhabricatorTranslation')
->setConcreteOnly(true)
->selectAndLoadSymbols();
foreach ($symbols as $symbol) {
$class = $symbol['name'];
$translations[$class] = newv($class, array())->getName();
}
asort($translations);
$default = PhabricatorEnv::newObjectFromConfig('translation.provider');
$translations = array(
'' => pht('Server Default (%s)', $default->getName()),
) + $translations;
$form = new AphrontFormView();
$form
->setUser($user)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Username'))
->setValue($user->getUsername()))
->setFlexible(true)
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Timezone'))
->setName('timezone')
->setOptions($timezone_id_map)
->setValue($user->getTimezoneIdentifier()))
->appendChild(
id(new AphrontFormSelectControl())
->setOptions($sexes)
->setLabel(pht('Sex'))
->setName('sex')
->setValue($user->getSex()))
->appendChild(
id(new AphrontFormSelectControl())
->setOptions($translations)
->setLabel(pht('Translation'))
->setName('translation')
->setValue($user->getTranslation()))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save')));
->setValue(pht('Save Account Settings')));
$header = new PhabricatorHeaderView();
$header->setHeader(pht('Account Settings'));

View file

@ -1,112 +0,0 @@
<?php
final class PhabricatorSettingsPanelProfile
extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'profile';
}
public function getPanelName() {
return pht('Profile');
}
public function getPanelGroup() {
return pht('Account Information');
}
public function processRequest(AphrontRequest $request) {
$user = $request->getUser();
$errors = array();
if ($request->isFormPost()) {
$sex = $request->getStr('sex');
$sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE);
if (in_array($sex, $sexes)) {
$user->setSex($sex);
} else {
$user->setSex(null);
}
// Checked in runtime.
$user->setTranslation($request->getStr('translation'));
if (!$errors) {
$user->save();
$response = id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?saved=true'));
return $response;
}
}
$error_view = null;
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle(pht('Form Errors'));
$error_view->setErrors($errors);
} else {
if ($request->getStr('saved')) {
$error_view = new AphrontErrorView();
$error_view->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
$error_view->setTitle(pht('Changes Saved'));
$error_view->appendChild(
phutil_tag('p', array(), pht('Your changes have been saved.')));
$error_view = $error_view->render();
}
}
$profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/');
$sexes = array(
PhutilPerson::SEX_UNKNOWN => pht('Unknown'),
PhutilPerson::SEX_MALE => pht('Male'),
PhutilPerson::SEX_FEMALE => pht('Female'),
);
$translations = array();
$symbols = id(new PhutilSymbolLoader())
->setType('class')
->setAncestorClass('PhabricatorTranslation')
->setConcreteOnly(true)
->selectAndLoadSymbols();
foreach ($symbols as $symbol) {
$class = $symbol['name'];
$translations[$class] = newv($class, array())->getName();
}
asort($translations);
$default = PhabricatorEnv::newObjectFromConfig('translation.provider');
$translations = array(
'' => pht('Server Default (%s)', $default->getName()),
) + $translations;
$form = new AphrontFormView();
$form
->setUser($request->getUser())
->appendChild(
id(new AphrontFormSelectControl())
->setOptions($sexes)
->setLabel(pht('Sex'))
->setName('sex')
->setValue($user->getSex()))
->appendChild(
id(new AphrontFormSelectControl())
->setOptions($translations)
->setLabel(pht('Translation'))
->setName('translation')
->setValue($user->getTranslation()));
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save')));
$header = new PhabricatorHeaderView();
$header->setHeader(pht('Edit Profile Details'));
return array(
$error_view,
$header,
$form,
);
}
}