snappymail/dev/Settings/User/General.js

170 lines
5.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
2019-07-05 03:19:24 +08:00
import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts';
2016-06-30 08:02:45 +08:00
2020-08-14 04:58:41 +08:00
import { SaveSettingsStep, EditorDefaultType, Layout } from 'Common/Enums';
2016-07-16 05:29:42 +08:00
import { settingsSaveHelperSimpleFunction, convertLangName } from 'Common/Utils';
2016-07-16 05:29:42 +08:00
2019-07-05 03:19:24 +08:00
import { i18n, trigger as translatorTrigger, reload as translatorReload } from 'Common/Translator';
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
2016-07-16 05:29:42 +08:00
import AppStore from 'Stores/User/App';
import LanguageStore from 'Stores/Language';
import SettingsStore from 'Stores/User/Settings';
import IdentityStore from 'Stores/User/Identity';
import NotificationStore from 'Stores/User/Notification';
import MessageStore from 'Stores/User/Message';
import Remote from 'Remote/User/Fetch';
2016-07-16 05:29:42 +08:00
2019-07-05 03:19:24 +08:00
class GeneralUserSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.language = LanguageStore.language;
this.languages = LanguageStore.languages;
this.messagesPerPage = SettingsStore.messagesPerPage;
this.messagesPerPageArray = MESSAGES_PER_PAGE_VALUES;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.editorDefaultType = SettingsStore.editorDefaultType;
this.layout = SettingsStore.layout;
this.usePreviewPane = SettingsStore.usePreviewPane;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.soundNotificationIsSupported = NotificationStore.soundNotificationIsSupported;
this.enableSoundNotification = NotificationStore.enableSoundNotification;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.enableDesktopNotification = NotificationStore.enableDesktopNotification;
this.isDesktopNotificationSupported = NotificationStore.isDesktopNotificationSupported;
this.isDesktopNotificationDenied = NotificationStore.isDesktopNotificationDenied;
2016-06-17 07:23:49 +08:00
2016-07-16 05:29:42 +08:00
this.showImages = SettingsStore.showImages;
this.useCheckboxesInList = SettingsStore.useCheckboxesInList;
this.threadsAllowed = AppStore.threadsAllowed;
this.useThreads = SettingsStore.useThreads;
this.replySameFolder = SettingsStore.replySameFolder;
this.allowLanguagesOnSettings = !!rl.settings.get('AllowLanguagesOnSettings');
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.languageFullName = ko.computed(() => convertLangName(this.language()));
2020-08-14 04:58:41 +08:00
this.languageTrigger = ko.observable(SaveSettingsStep.Idle).extend({ throttle: 100 });
2014-08-21 23:08:34 +08:00
2020-10-27 18:09:24 +08:00
ko.addObservablesTo(this, {
mppTrigger: SaveSettingsStep.Idle,
editorDefaultTypeTrigger: SaveSettingsStep.Idle,
layoutTrigger: SaveSettingsStep.Idle
});
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
this.identities = IdentityStore.identities;
this.identityMain = ko.computed(() => {
const list = this.identities();
return Array.isArray(list) ? list.find(item => item && !item.id()) : null;
2016-06-30 08:02:45 +08:00
});
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
this.identityMainDesc = ko.computed(() => {
const identity = this.identityMain();
return identity ? identity.formattedName() : '---';
2016-06-30 08:02:45 +08:00
});
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
this.editorDefaultTypes = ko.computed(() => {
translatorTrigger();
return [
2019-07-05 03:19:24 +08:00
{ 'id': EditorDefaultType.Html, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML') },
{ 'id': EditorDefaultType.Plain, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN') },
{ 'id': EditorDefaultType.HtmlForced, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED') },
{ 'id': EditorDefaultType.PlainForced, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED') }
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.layoutTypes = ko.computed(() => {
translatorTrigger();
return [
2019-07-05 03:19:24 +08:00
{ 'id': Layout.NoPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT') },
{ 'id': Layout.SidePreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT') },
{ 'id': Layout.BottomPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT') }
2016-07-16 05:29:42 +08:00
];
2016-06-30 08:02:45 +08:00
});
2016-07-16 05:29:42 +08:00
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
editMainIdentity() {
const identity = this.identityMain();
2019-07-05 03:19:24 +08:00
if (identity) {
2016-07-16 05:29:42 +08:00
showScreenPopup(require('View/Popup/Identity'), [identity]);
}
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
testSoundNotification() {
NotificationStore.playSoundNotification(true);
}
onBuild() {
setTimeout(() => {
2019-07-05 03:19:24 +08:00
const f0 = settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this),
2016-07-16 05:29:42 +08:00
f1 = settingsSaveHelperSimpleFunction(this.mppTrigger, this),
f2 = settingsSaveHelperSimpleFunction(this.layoutTrigger, this),
fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
2020-08-14 04:58:41 +08:00
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000);
2016-07-16 05:29:42 +08:00
};
this.language.subscribe((value) => {
this.languageTrigger(SaveSettingsStep.Animate);
2019-07-05 03:19:24 +08:00
translatorReload(false, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => {
Remote.saveSettings(null, {
'Language': value
});
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.editorDefaultType.subscribe(Remote.saveSettingsHelper('EditorDefaultType', null, f0));
this.messagesPerPage.subscribe(Remote.saveSettingsHelper('MPP', null, f1));
this.showImages.subscribe(Remote.saveSettingsHelper('ShowImages', v=>v?'1':'0'));
2014-08-21 23:08:34 +08:00
this.useCheckboxesInList.subscribe(Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0'));
2014-08-21 23:08:34 +08:00
this.enableDesktopNotification.subscribe((value =>
Remote.saveSettings(null, {
'DesktopNotifications': value ? 1 : 0
})
).debounce(3000));
2014-08-21 23:08:34 +08:00
this.enableSoundNotification.subscribe((value =>
Remote.saveSettings(null, {
'SoundNotification': value ? 1 : 0
})
).debounce(3000));
2016-07-16 05:29:42 +08:00
this.replySameFolder.subscribe((value =>
Remote.saveSettings(null, {
'ReplySameFolder': value ? 1 : 0
})
).debounce(3000));
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
this.useThreads.subscribe((value) => {
MessageStore.messageList([]);
Remote.saveSettings(null, {
'UseThreads': value ? 1 : 0
2016-07-16 05:29:42 +08:00
});
});
2014-08-21 23:08:34 +08:00
this.layout.subscribe((value) => {
2016-07-16 05:29:42 +08:00
MessageStore.messageList([]);
Remote.saveSettings(f2, {
'Layout': value
});
});
2020-08-14 04:58:41 +08:00
}, 50);
2016-07-16 05:29:42 +08:00
}
2014-08-25 15:10:51 +08:00
2016-07-16 05:29:42 +08:00
onShow() {
this.enableDesktopNotification.valueHasMutated();
}
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
}
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
export { GeneralUserSettings, GeneralUserSettings as default };