snappymail/dev/Screen/User/Settings.js

127 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { Capa, KeyState } from 'Common/Enums';
import { keyScope, leftPanelType, leftPanelDisabled } from 'Common/Globals';
import { runSettingsViewModelHooks } from 'Common/Plugins';
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
2016-07-07 07:11:13 +08:00
import AppStore from 'Stores/User/App';
import AccountStore from 'Stores/User/Account';
2019-07-05 03:19:24 +08:00
import { addSettingsViewModel } from 'Knoin/Knoin';
import { AbstractSettingsScreen } from 'Screen/AbstractSettings';
import { GeneralUserSettings } from 'Settings/User/General';
import { ContactsUserSettings } from 'Settings/User/Contacts';
import { AccountsUserSettings } from 'Settings/User/Accounts';
import { FiltersUserSettings } from 'Settings/User/Filters';
import { SecurityUserSettings } from 'Settings/User/Security';
import { TemplatesUserSettings } from 'Settings/User/Templates';
import { FoldersUserSettings } from 'Settings/User/Folders';
import { ThemesUserSettings } from 'Settings/User/Themes';
import { OpenPgpUserSettings } from 'Settings/User/OpenPgp';
import { SystemDropDownSettingsUserView } from 'View/User/Settings/SystemDropDown';
import { MenuSettingsUserView } from 'View/User/Settings/Menu';
import { PaneSettingsUserView } from 'View/User/Settings/Pane';
const Settings = rl.settings;
2019-07-05 03:19:24 +08:00
class SettingsUserScreen extends AbstractSettingsScreen {
2016-07-16 05:29:42 +08:00
constructor() {
2019-07-05 03:19:24 +08:00
super([SystemDropDownSettingsUserView, MenuSettingsUserView, PaneSettingsUserView]);
initOnStartOrLangChange(
() => {
this.sSettingsTitle = i18n('TITLES/SETTINGS');
},
() => {
this.setSettingsTitle();
}
);
2016-07-07 07:11:13 +08:00
}
/**
* @param {Function=} fCallback
*/
setupSettings(fCallback = null) {
2019-07-05 03:19:24 +08:00
if (!Settings.capa(Capa.Settings)) {
if (fCallback) {
2016-07-07 07:11:13 +08:00
fCallback();
}
return false;
}
2019-07-05 03:19:24 +08:00
addSettingsViewModel(GeneralUserSettings, 'SettingsGeneral', 'SETTINGS_LABELS/LABEL_GENERAL_NAME', 'general', true);
2016-07-07 07:11:13 +08:00
2019-07-05 03:19:24 +08:00
if (AppStore.contactsIsAllowed()) {
addSettingsViewModel(ContactsUserSettings, 'SettingsContacts', 'SETTINGS_LABELS/LABEL_CONTACTS_NAME', 'contacts');
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.AdditionalAccounts) || Settings.capa(Capa.Identities)) {
addSettingsViewModel(
AccountsUserSettings,
'SettingsAccounts',
Settings.capa(Capa.AdditionalAccounts)
? 'SETTINGS_LABELS/LABEL_ACCOUNTS_NAME'
: 'SETTINGS_LABELS/LABEL_IDENTITIES_NAME',
'accounts'
);
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Sieve)) {
addSettingsViewModel(FiltersUserSettings, 'SettingsFilters', 'SETTINGS_LABELS/LABEL_FILTERS_NAME', 'filters');
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.AutoLogout) || Settings.capa(Capa.TwoFactor)) {
addSettingsViewModel(SecurityUserSettings, 'SettingsSecurity', 'SETTINGS_LABELS/LABEL_SECURITY_NAME', 'security');
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Templates)) {
addSettingsViewModel(
TemplatesUserSettings,
'SettingsTemplates',
'SETTINGS_LABELS/LABEL_TEMPLATES_NAME',
'templates'
);
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Folders)) {
addSettingsViewModel(FoldersUserSettings, 'SettingsFolders', 'SETTINGS_LABELS/LABEL_FOLDERS_NAME', 'folders');
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Themes)) {
addSettingsViewModel(ThemesUserSettings, 'SettingsThemes', 'SETTINGS_LABELS/LABEL_THEMES_NAME', 'themes');
2016-07-07 07:11:13 +08:00
}
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.OpenPGP)) {
addSettingsViewModel(OpenPgpUserSettings, 'SettingsOpenPGP', 'SETTINGS_LABELS/LABEL_OPEN_PGP_NAME', 'openpgp');
2016-07-07 07:11:13 +08:00
}
runSettingsViewModelHooks(false);
2019-07-05 03:19:24 +08:00
if (fCallback) {
2016-07-07 07:11:13 +08:00
fCallback();
}
return true;
}
onShow() {
this.setSettingsTitle();
keyScope(KeyState.Settings);
leftPanelType('');
if (Settings.app('mobile')) {
2016-07-07 07:11:13 +08:00
leftPanelDisabled(true);
}
}
setSettingsTitle() {
const sEmail = AccountStore.email();
rl.setWindowTitle((sEmail ? sEmail + ' - ' : '') + this.sSettingsTitle);
2016-07-07 07:11:13 +08:00
}
}
2019-07-05 03:19:24 +08:00
export { SettingsUserScreen, SettingsUserScreen as default };