snappymail/dev/Settings/Admin/General.js

150 lines
4.8 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,
convertThemeName,
addObservablesTo,
addSubscribablesTo
2016-07-16 05:29:42 +08:00
} from 'Common/Utils';
2016-06-30 08:02:45 +08:00
2021-03-16 17:46:22 +08:00
import { Capa, SaveSettingsStep } from 'Common/Enums';
2021-03-10 18:44:48 +08:00
import { Settings, SettingsGet } from 'Common/Globals';
import { reload as 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
2021-01-22 23:32:08 +08:00
export class GeneralAdminSettings {
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,
capaThemes: Settings.capa(Capa.Themes),
capaUserBackground: Settings.capa(Capa.UserBackground),
capaAdditionalAccounts: Settings.capa(Capa.AdditionalAccounts),
capaIdentities: Settings.capa(Capa.Identities),
capaAttachmentThumbnails: Settings.capa(Capa.AttachmentThumbnails),
2021-03-16 21:15:05 +08:00
capaTemplates: Settings.capa(Capa.Templates),
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-16 21:15:05 +08:00
// 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('')
: '';
this.themesOptions = ko.computed(() =>
this.themes.map(theme => ({ optValue: theme, optText: convertThemeName(theme) }))
2019-07-05 03:19:24 +08:00
);
2016-07-16 05:29:42 +08:00
this.languageFullName = ko.computed(() => convertLangName(this.language()));
this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin()));
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, fn) =>
value => {
const data = {};
data[key] = value ? 1 : 0;
Remote.saveAdminConfig(fn, data);
};
addSubscribablesTo(this, {
2021-03-16 17:46:22 +08:00
mainAttachmentLimit: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this), {
AttachmentLimit: pInt(value)
2021-03-16 17:46:22 +08:00
}),
2015-03-28 06:06:56 +08:00
2021-03-16 17:46:22 +08:00
language: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.languageTrigger, this), {
Language: value.trim()
2021-03-16 17:46:22 +08:00
}),
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))
2021-03-16 17:46:22 +08:00
.then(() => Remote.saveAdminConfig(null, {
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);
2021-03-16 17:46:22 +08:00
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.themeTrigger, this), {
Theme: value.trim()
2016-07-16 05:29:42 +08:00
});
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
capaTemplates: fSaveBoolHelper('CapaTemplates'),
2014-08-21 23:08:34 +08:00
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
]);
}
}