snappymail/dev/Settings/Admin/General.js

127 lines
4.1 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
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';
2022-03-06 05:25:32 +08:00
import { 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
2022-02-28 17:38:47 +08:00
import { AbstractViewSettings } from 'Knoin/AbstractViews';
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';
2022-02-24 21:01:41 +08:00
import { LanguagesPopupView } from 'View/Popup/Languages';
2015-03-28 06:06:56 +08:00
export class AdminSettingsGeneral extends AbstractViewSettings {
2016-07-16 05:29:42 +08:00
constructor() {
2022-02-28 17:38:47 +08:00
super();
2016-07-16 05:29:42 +08:00
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;
2022-03-01 17:18:12 +08:00
this.addSettings(['AllowLanguagesOnSettings','NewMoveToFolder']);
addObservablesTo(this, {
2020-10-27 18:09:24 +08:00
attachmentLimitTrigger: SaveSettingsStep.Idle,
2021-03-16 17:46:22 +08:00
themeTrigger: SaveSettingsStep.Idle,
2022-03-06 05:25:32 +08:00
capaThemes: SettingsCapa('Themes'),
capaUserBackground: SettingsCapa('UserBackground'),
capaAdditionalAccounts: SettingsCapa('AdditionalAccounts'),
capaIdentities: SettingsCapa('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
2022-02-28 17:38:47 +08:00
this.attachmentLimit = ko
.observable(SettingsGet('AttachmentLimit') / (1024 * 1024))
.extend({ debounce: 500 });
2016-07-16 05:29:42 +08:00
2022-02-28 17:38:47 +08:00
this.addSetting('Language');
this.addSetting('AttachmentLimit');
this.addSetting('Theme', value => changeTheme(value, this.themeTrigger));
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);
},
2022-02-28 17:38:47 +08:00
fSaveHelper = key => value => Remote.saveSetting(key, value);
2021-03-16 17:46:22 +08:00
addSubscribablesTo(this, {
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))
2022-03-01 17:18:12 +08:00
.then(() => Remote.saveSetting('LanguageAdmin', value));
2021-03-16 17:46:22 +08:00
},
2022-02-28 17:38:47 +08:00
capaAdditionalAccounts: fSaveHelper('CapaAdditionalAccounts'),
2014-08-21 23:08:34 +08:00
2022-02-28 17:38:47 +08:00
capaIdentities: fSaveHelper('CapaIdentities'),
2022-02-28 17:38:47 +08:00
capaAttachmentThumbnails: fSaveHelper('CapaAttachmentThumbnails'),
2014-08-21 23:08:34 +08:00
2022-02-28 17:38:47 +08:00
capaThemes: fSaveHelper('CapaThemes'),
2016-06-30 08:02:45 +08:00
2022-03-01 17:18:12 +08:00
capaUserBackground: fSaveHelper('CapaUserBackground')
2021-03-16 17:46:22 +08:00
});
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
]);
}
}