snappymail/dev/Settings/Admin/General.js

180 lines
5.3 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 {
2019-07-05 03:19:24 +08:00
pInt,
settingsSaveHelperSimpleFunction,
changeTheme,
convertThemeName,
convertLangName
2016-07-16 05:29:42 +08:00
} from 'Common/Utils';
2016-06-30 08:02:45 +08:00
2020-08-14 04:58:41 +08:00
import { SaveSettingsStep } from 'Common/Enums';
2019-07-05 03:19:24 +08:00
import { reload as translatorReload } 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/Ajax';
2016-07-16 05:29:42 +08:00
import ThemeStore from 'Stores/Theme';
import LanguageStore from 'Stores/Language';
import AppAdminStore from 'Stores/Admin/App';
import CapaAdminStore from 'Stores/Admin/Capa';
2015-03-28 06:06:56 +08:00
const settingsGet = rl.settings.get;
2019-07-05 03:19:24 +08:00
class GeneralAdminSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.language = LanguageStore.language;
this.languages = LanguageStore.languages;
this.languageAdmin = LanguageStore.languageAdmin;
this.languagesAdmin = LanguageStore.languagesAdmin;
this.theme = ThemeStore.theme;
this.themes = ThemeStore.themes;
this.capaThemes = CapaAdminStore.themes;
this.capaUserBackground = CapaAdminStore.userBackground;
this.capaAdditionalAccounts = CapaAdminStore.additionalAccounts;
this.capaIdentities = CapaAdminStore.identities;
this.capaAttachmentThumbnails = CapaAdminStore.attachmentThumbnails;
this.capaTemplates = CapaAdminStore.templates;
this.allowLanguagesOnSettings = AppAdminStore.allowLanguagesOnSettings;
this.weakPassword = AppAdminStore.weakPassword;
2017-02-09 01:48:53 +08:00
this.newMoveToFolder = AppAdminStore.newMoveToFolder;
2016-07-16 05:29:42 +08:00
2017-10-02 01:54:50 +08:00
this.dataFolderAccess = AppAdminStore.dataFolderAccess;
2019-07-05 03:19:24 +08:00
this.mainAttachmentLimit = ko
2020-08-14 04:58:41 +08:00
.observable(pInt(settingsGet('AttachmentLimit')) / (1024 * 1024))
2019-07-05 03:19:24 +08:00
.extend({ posInterer: 25 });
2016-07-16 05:29:42 +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.attachmentLimitTrigger = ko.observable(SaveSettingsStep.Idle);
this.languageTrigger = ko.observable(SaveSettingsStep.Idle);
2020-08-14 04:58:41 +08:00
this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ throttle: 100 });
2016-07-16 05:29:42 +08:00
this.themeTrigger = ko.observable(SaveSettingsStep.Idle);
}
onBuild() {
setTimeout(() => {
2019-07-05 03:19:24 +08:00
const f1 = settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this),
2016-07-16 05:29:42 +08:00
f2 = settingsSaveHelperSimpleFunction(this.languageTrigger, this),
f3 = settingsSaveHelperSimpleFunction(this.themeTrigger, this),
fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageAdminTrigger(saveSettingsStep);
2020-08-14 04:58:41 +08:00
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
2016-07-16 05:29:42 +08:00
};
2015-03-28 06:06:56 +08:00
2016-07-16 05:29:42 +08:00
this.mainAttachmentLimit.subscribe((value) => {
Remote.saveAdminConfig(f1, {
'AttachmentLimit': pInt(value)
2015-03-28 06:06:56 +08:00
});
});
2016-07-16 05:29:42 +08:00
this.language.subscribe((value) => {
Remote.saveAdminConfig(f2, {
'Language': value.trim()
2016-07-16 05:29:42 +08:00
});
2014-08-21 23:08:34 +08:00
});
2016-07-16 05:29:42 +08:00
this.languageAdmin.subscribe((value) => {
this.languageAdminTrigger(SaveSettingsStep.Animate);
2019-07-05 03:19:24 +08:00
translatorReload(true, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => {
Remote.saveAdminConfig(null, {
'LanguageAdmin': value.trim()
2019-07-05 03:19:24 +08:00
});
2016-07-16 05:29:42 +08:00
});
});
2016-07-16 05:29:42 +08:00
this.theme.subscribe((value) => {
changeTheme(value, this.themeTrigger);
Remote.saveAdminConfig(f3, {
'Theme': value.trim()
2016-07-16 05:29:42 +08:00
});
});
2016-07-16 05:29:42 +08:00
this.capaAdditionalAccounts.subscribe((value) => {
Remote.saveAdminConfig(null, {
'CapaAdditionalAccounts': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
2014-08-21 23:08:34 +08:00
});
2016-07-16 05:29:42 +08:00
this.capaIdentities.subscribe((value) => {
Remote.saveAdminConfig(null, {
'CapaIdentities': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
});
2016-07-16 05:29:42 +08:00
this.capaTemplates.subscribe((value) => {
Remote.saveAdminConfig(null, {
'CapaTemplates': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
2014-08-21 23:08:34 +08:00
});
2016-07-16 05:29:42 +08:00
this.capaAttachmentThumbnails.subscribe((value) => {
Remote.saveAdminConfig(null, {
'CapaAttachmentThumbnails': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
2014-08-21 23:08:34 +08:00
});
2016-07-16 05:29:42 +08:00
this.capaThemes.subscribe((value) => {
Remote.saveAdminConfig(null, {
'CapaThemes': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
2016-06-30 08:02:45 +08:00
});
2016-07-16 05:29:42 +08:00
this.capaUserBackground.subscribe((value) => {
Remote.saveAdminConfig(null, {
'CapaUserBackground': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
});
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.allowLanguagesOnSettings.subscribe((value) => {
Remote.saveAdminConfig(null, {
'AllowLanguagesOnSettings': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
});
2017-02-09 01:48:53 +08:00
this.newMoveToFolder.subscribe((value) => {
Remote.saveAdminConfig(null, {
'NewMoveToFolder': value ? '1' : '0'
2017-02-09 01:48:53 +08:00
});
});
2020-08-14 04:58:41 +08:00
}, 50);
2016-07-16 05:29:42 +08:00
}
selectLanguage() {
2019-07-05 03:19:24 +08:00
showScreenPopup(require('View/Popup/Languages'), [this.language, this.languages(), LanguageStore.userLanguage()]);
2016-07-16 05:29:42 +08:00
}
selectLanguageAdmin() {
showScreenPopup(require('View/Popup/Languages'), [
2019-07-05 03:19:24 +08:00
this.languageAdmin,
this.languagesAdmin(),
LanguageStore.userLanguageAdmin()
2016-07-16 05:29:42 +08:00
]);
}
}
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
export { GeneralAdminSettings, GeneralAdminSettings as default };