snappymail/dev/Settings/Admin/General.js

147 lines
4.7 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
import {
isArray,
2019-07-05 03:19:24 +08:00
pInt,
settingsSaveHelperSimpleFunction,
changeTheme,
2022-02-17 16:36:29 +08:00
convertThemeName
2016-07-16 05:29:42 +08:00
} from 'Common/Utils';
2016-06-30 08:02:45 +08:00
2022-02-17 16:36:29 +08:00
import { addObservablesTo, addSubscribablesTo, addComputablesTo } from 'External/ko';
2021-03-16 17:46:22 +08:00
import { Capa, SaveSettingsStep } from 'Common/Enums';
2022-02-08 21:13:06 +08:00
import { Settings, SettingsGet, SettingsCapa } from 'Common/Globals';
import { translatorReload, convertLangName } from 'Common/Translator';
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
2014-08-21 23:08:34 +08:00
import Remote from 'Remote/Admin/Fetch';
import { ThemeStore } from 'Stores/Theme';
import { LanguageStore } from 'Stores/Language';
import LanguagesPopupView from 'View/Popup/Languages';
2015-03-28 06:06:56 +08:00
export class GeneralAdminSettings /*extends AbstractViewSettings*/ {
2016-07-16 05:29:42 +08:00
constructor() {
this.language = LanguageStore.language;
this.languages = LanguageStore.languages;
2021-03-10 18:44:48 +08:00
const aLanguagesAdmin = Settings.app('languagesAdmin');
this.languagesAdmin = ko.observableArray(isArray(aLanguagesAdmin) ? aLanguagesAdmin : []);
this.languageAdmin = ko
2021-03-10 18:44:48 +08:00
.observable(SettingsGet('LanguageAdmin'))
.extend({ limitedList: this.languagesAdmin });
2016-07-16 05:29:42 +08:00
this.theme = ThemeStore.theme;
this.themes = ThemeStore.themes;
addObservablesTo(this, {
2021-03-10 18:44:48 +08:00
allowLanguagesOnSettings: !!SettingsGet('AllowLanguagesOnSettings'),
newMoveToFolder: !!SettingsGet('NewMoveToFolder'),
2020-10-27 18:09:24 +08:00
attachmentLimitTrigger: SaveSettingsStep.Idle,
languageTrigger: SaveSettingsStep.Idle,
2021-03-16 17:46:22 +08:00
themeTrigger: SaveSettingsStep.Idle,
2022-02-08 21:13:06 +08:00
capaThemes: SettingsCapa(Capa.Themes),
capaUserBackground: SettingsCapa(Capa.UserBackground),
capaAdditionalAccounts: SettingsCapa(Capa.AdditionalAccounts),
capaIdentities: SettingsCapa(Capa.Identities),
2022-02-24 19:22:27 +08:00
capaAttachmentThumbnails: SettingsCapa('AttachmentThumbnails'),
2021-03-16 21:15:05 +08:00
dataFolderAccess: false
2020-10-27 18:09:24 +08:00
});
2021-03-16 21:15:05 +08:00
this.weakPassword = rl.app.weakPassword;
2016-07-16 05:29:42 +08:00
2021-03-30 04:31:51 +08:00
/** https://github.com/RainLoop/rainloop-webmail/issues/1924
if (this.weakPassword) {
fetch('./data/VERSION?' + Math.random()).then(response => this.dataFolderAccess(response.ok));
}
*/
2017-10-02 01:54:50 +08:00
2019-07-05 03:19:24 +08:00
this.mainAttachmentLimit = ko
2021-03-10 18:44:48 +08:00
.observable(pInt(SettingsGet('AttachmentLimit')) / (1024 * 1024))
.extend({ debounce: 500 });
2016-07-16 05:29:42 +08:00
2021-03-10 18:44:48 +08:00
this.uploadData = SettingsGet('PhpUploadSizes');
2019-07-05 03:19:24 +08:00
this.uploadDataDesc =
this.uploadData && (this.uploadData.upload_max_filesize || this.uploadData.post_max_size)
? [
this.uploadData.upload_max_filesize
? 'upload_max_filesize = ' + this.uploadData.upload_max_filesize + '; '
: '',
this.uploadData.post_max_size ? 'post_max_size = ' + this.uploadData.post_max_size : ''
].join('')
: '';
addComputablesTo(this, {
themesOptions: () => this.themes.map(theme => ({ optValue: theme, optText: convertThemeName(theme) })),
2016-07-16 05:29:42 +08:00
languageFullName: () => convertLangName(this.language()),
languageAdminFullName: () => convertLangName(this.languageAdmin())
});
2016-07-16 05:29:42 +08:00
this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
2016-07-16 05:29:42 +08:00
2021-03-16 17:46:22 +08:00
const fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageAdminTrigger(saveSettingsStep);
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
},
fSaveBoolHelper = key =>
value => Remote.saveConfig({[key]: value ? 1 : 0});
2021-03-16 17:46:22 +08:00
addSubscribablesTo(this, {
2021-03-16 17:46:22 +08:00
mainAttachmentLimit: value =>
Remote.saveConfig({
AttachmentLimit: pInt(value)
}, settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this)),
2015-03-28 06:06:56 +08:00
2021-03-16 17:46:22 +08:00
language: value =>
Remote.saveConfig({
Language: value.trim()
}, settingsSaveHelperSimpleFunction(this.languageTrigger, this)),
2014-08-21 23:08:34 +08:00
2021-03-16 17:46:22 +08:00
languageAdmin: value => {
2016-07-16 05:29:42 +08:00
this.languageAdminTrigger(SaveSettingsStep.Animate);
2019-07-05 03:19:24 +08:00
translatorReload(true, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => Remote.saveConfig({
LanguageAdmin: value.trim()
2021-03-16 17:46:22 +08:00
}));
},
theme: value => {
2016-07-16 05:29:42 +08:00
changeTheme(value, this.themeTrigger);
Remote.saveConfig({
Theme: value.trim()
}, settingsSaveHelperSimpleFunction(this.themeTrigger, this));
2021-03-16 17:46:22 +08:00
},
2021-03-16 17:46:22 +08:00
capaAdditionalAccounts: fSaveBoolHelper('CapaAdditionalAccounts'),
2014-08-21 23:08:34 +08:00
2021-03-16 17:46:22 +08:00
capaIdentities: fSaveBoolHelper('CapaIdentities'),
2021-03-16 17:46:22 +08:00
capaAttachmentThumbnails: fSaveBoolHelper('CapaAttachmentThumbnails'),
2014-08-21 23:08:34 +08:00
2021-03-16 17:46:22 +08:00
capaThemes: fSaveBoolHelper('CapaThemes'),
2016-06-30 08:02:45 +08:00
2021-03-16 17:46:22 +08:00
capaUserBackground: fSaveBoolHelper('CapaUserBackground'),
2016-06-30 08:02:45 +08:00
2021-03-16 17:46:22 +08:00
allowLanguagesOnSettings: fSaveBoolHelper('AllowLanguagesOnSettings'),
2017-02-09 01:48:53 +08:00
2021-03-16 17:46:22 +08:00
newMoveToFolder: fSaveBoolHelper('NewMoveToFolder')
});
2016-07-16 05:29:42 +08:00
}
selectLanguage() {
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
2016-07-16 05:29:42 +08:00
}
selectLanguageAdmin() {
showScreenPopup(LanguagesPopupView, [
2019-07-05 03:19:24 +08:00
this.languageAdmin,
this.languagesAdmin(),
2021-03-10 18:44:48 +08:00
SettingsGet('UserLanguageAdmin')
2016-07-16 05:29:42 +08:00
]);
}
}