diff --git a/dev/Settings/Admin/Contacts.js b/dev/Settings/Admin/Contacts.js index 3702fef09..2fe0eb088 100644 --- a/dev/Settings/Admin/Contacts.js +++ b/dev/Settings/Admin/Contacts.js @@ -2,7 +2,12 @@ import ko from 'ko'; import { SaveSettingsStep } from 'Common/Enums'; import { SettingsGet } from 'Common/Globals'; -import { settingsSaveHelperSimpleFunction, defaultOptionsAfterRender, addObservablesTo } from 'Common/Utils'; +import { + settingsSaveHelperSimpleFunction, + defaultOptionsAfterRender, + addObservablesTo, + addSubscribablesTo +} from 'Common/Utils'; import Remote from 'Remote/Admin/Fetch'; import { decorateKoCommands } from 'Knoin/Knoin'; @@ -50,7 +55,7 @@ export class ContactsAdminSettings { this.mainContactsType = ko .computed({ read: this.contactsType, - write: (value) => { + write: value => { if (value !== this.contactsType()) { if (supportedTypes.includes(value)) { this.contactsType(value); @@ -64,11 +69,41 @@ export class ContactsAdminSettings { }) .extend({ notify: 'always' }); - this.contactsType.subscribe(() => { - this.testContactsSuccess(false); - this.testContactsError(false); - this.testContactsErrorMessage(''); - }); + addSubscribablesTo(this, { + enableContacts: value => + Remote.saveAdminConfig(null, { + 'ContactsEnable': value ? 1 : 0 + }), + + contactsSync: value => + Remote.saveAdminConfig(null, { + 'ContactsSync': value ? 1 : 0 + }), + + contactsType: value => { + this.testContactsSuccess(false); + this.testContactsError(false); + this.testContactsErrorMessage(''); + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this), { + 'ContactsPdoType': value.trim() + }) + }, + + pdoDsn: value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this), { + 'ContactsPdoDsn': value.trim() + }), + + pdoUser: value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this), { + 'ContactsPdoUser': value.trim() + }), + + pdoPassword: value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this), { + 'ContactsPdoPassword': value.trim() + }) + }) this.contactsType(SettingsGet('ContactsPdoType')); @@ -117,51 +152,4 @@ export class ContactsAdminSettings { this.testContactsError(false); this.testContactsErrorMessage(''); } - - onBuild() { - setTimeout(() => { - const f1 = settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this), - f3 = settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this), - f4 = settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this), - f5 = settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this); - - this.enableContacts.subscribe((value) => { - Remote.saveAdminConfig(null, { - 'ContactsEnable': value ? '1' : '0' - }); - }); - - this.contactsSync.subscribe((value) => { - Remote.saveAdminConfig(null, { - 'ContactsSync': value ? '1' : '0' - }); - }); - - this.contactsType.subscribe((value) => { - Remote.saveAdminConfig(f5, { - 'ContactsPdoType': value.trim() - }); - }); - - this.pdoDsn.subscribe((value) => { - Remote.saveAdminConfig(f1, { - 'ContactsPdoDsn': value.trim() - }); - }); - - this.pdoUser.subscribe((value) => { - Remote.saveAdminConfig(f3, { - 'ContactsPdoUser': value.trim() - }); - }); - - this.pdoPassword.subscribe((value) => { - Remote.saveAdminConfig(f4, { - 'ContactsPdoPassword': value.trim() - }); - }); - - this.contactsType(SettingsGet('ContactsPdoType')); - }, 50); - } } diff --git a/dev/Settings/Admin/Login.js b/dev/Settings/Admin/Login.js index a4da1c855..3cfab448f 100644 --- a/dev/Settings/Admin/Login.js +++ b/dev/Settings/Admin/Login.js @@ -1,7 +1,7 @@ import ko from 'ko'; import { Settings, SettingsGet } from 'Common/Globals'; -import { settingsSaveHelperSimpleFunction, addObservablesTo } from 'Common/Utils'; +import { settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; import Remote from 'Remote/Admin/Fetch'; @@ -15,41 +15,32 @@ export class LoginAdminSettings { }); this.defaultDomain = ko.observable(SettingsGet('LoginDefaultDomain')).idleTrigger(); - } - onBuild() { - setTimeout(() => { - const f1 = settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this); - - this.determineUserLanguage.subscribe(value => + addSubscribablesTo(this, { + determineUserLanguage: value => Remote.saveAdminConfig(null, { - 'DetermineUserLanguage': value ? '1' : '0' - }) - ); + 'DetermineUserLanguage': value ? 1 : 0 + }), - this.determineUserDomain.subscribe(value => + determineUserDomain: value => Remote.saveAdminConfig(null, { - 'DetermineUserDomain': value ? '1' : '0' - }) - ); + 'DetermineUserDomain': value ? 1 : 0 + }), - this.allowLanguagesOnLogin.subscribe(value => + allowLanguagesOnLogin: value => Remote.saveAdminConfig(null, { - 'AllowLanguagesOnLogin': value ? '1' : '0' - }) - ); + 'AllowLanguagesOnLogin': value ? 1 : 0 + }), - this.hideSubmitButton.subscribe(value => + hideSubmitButton: value => Remote.saveAdminConfig(null, { - 'hideSubmitButton': value ? '1' : '0' - }) - ); + 'hideSubmitButton': value ? 1 : 0 + }), - this.defaultDomain.subscribe(value => - Remote.saveAdminConfig(f1, { + defaultDomain: value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this), { 'LoginDefaultDomain': value.trim() }) - ); - }, 50); + }); } } diff --git a/dev/Settings/Admin/Plugins.js b/dev/Settings/Admin/Plugins.js index 2213b18a7..e5d4aef44 100644 --- a/dev/Settings/Admin/Plugins.js +++ b/dev/Settings/Admin/Plugins.js @@ -21,6 +21,12 @@ export class PluginsAdminSettings { this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this); this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this); + + this.enabledPlugins.subscribe(value => + Remote.saveAdminConfig(null, { + 'EnabledPlugins': value ? 1 : 0 + }) + ); } disablePlugin(plugin) { @@ -40,12 +46,6 @@ export class PluginsAdminSettings { el = event.target.closestWithin('.e-item .disabled-plugin', oDom); el && ko.dataFor(el) && this.disablePlugin(ko.dataFor(el)); }); - - this.enabledPlugins.subscribe((value) => { - Remote.saveAdminConfig(null, { - 'EnabledPlugins': value ? '1' : '0' - }); - }); } onShow() { diff --git a/dev/Settings/User/Contacts.js b/dev/Settings/User/Contacts.js index 7e39e4729..0d3a8360b 100644 --- a/dev/Settings/User/Contacts.js +++ b/dev/Settings/User/Contacts.js @@ -24,23 +24,21 @@ export class ContactsUserSettings { ].join('|') ) .extend({ debounce: 500 }); - } - onBuild() { - this.contactsAutosave.subscribe((value) => { + this.contactsAutosave.subscribe(value => Remote.saveSettings(null, { - 'ContactsAutosave': value ? '1' : '0' - }); - }); + 'ContactsAutosave': value ? 1 : 0 + }) + ); - this.saveTrigger.subscribe(() => { + this.saveTrigger.subscribe(() => Remote.saveContactsSyncData( null, ContactUserStore.enableSync(), ContactUserStore.syncUrl(), ContactUserStore.syncUser(), ContactUserStore.syncPass() - ); - }); + ) + ); } } diff --git a/dev/Settings/User/General.js b/dev/Settings/User/General.js index 5b88faaab..17d7536fb 100644 --- a/dev/Settings/User/General.js +++ b/dev/Settings/User/General.js @@ -4,7 +4,7 @@ import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts'; import { SaveSettingsStep } from 'Common/Enums'; import { EditorDefaultType, Layout } from 'Common/EnumsUser'; import { SettingsGet } from 'Common/Globals'; -import { settingsSaveHelperSimpleFunction, addObservablesTo } from 'Common/Utils'; +import { settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; import { i18n, trigger as translatorTrigger, reload as translatorReload, convertLangName } from 'Common/Translator'; import { showScreenPopup } from 'Knoin/Knoin'; @@ -83,6 +83,68 @@ export class GeneralUserSettings { { 'id': Layout.BottomPreview, 'name': i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT') } ]; }); + + + const fReloadLanguageHelper = (saveSettingsStep) => () => { + this.languageTrigger(saveSettingsStep); + setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000); + }; + addSubscribablesTo(this, { + language: value => { + this.languageTrigger(SaveSettingsStep.Animate); + translatorReload(false, value) + .then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult)) + .then(() => { + Remote.saveSettings(null, { + 'Language': value + }); + }); + }, + + editorDefaultType: + Remote.saveSettingsHelper('EditorDefaultType', null, + settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this)), + + messagesPerPage: Remote.saveSettingsHelper('MPP', null, settingsSaveHelperSimpleFunction(this.mppTrigger, this)), + + showImages: Remote.saveSettingsHelper('ShowImages', v=>v?'1':'0'), + + removeColors: Remote.saveSettingsHelper('RemoveColors', v=>v?'1':'0'), + + useCheckboxesInList: Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0'), + + enableDesktopNotification: (value => + Remote.saveSettings(null, { + 'DesktopNotifications': value ? 1 : 0 + }) + ).debounce(3000), + + enableSoundNotification: (value => + Remote.saveSettings(null, { + 'SoundNotification': value ? 1 : 0 + }) + ).debounce(3000), + + replySameFolder: (value => + Remote.saveSettings(null, { + 'ReplySameFolder': value ? 1 : 0 + }) + ).debounce(3000), + + useThreads: value => { + MessageUserStore.list([]); + Remote.saveSettings(null, { + 'UseThreads': value ? 1 : 0 + }); + }, + + layout: value => { + MessageUserStore.list([]); + Remote.saveSettings(settingsSaveHelperSimpleFunction(this.layoutTrigger, this), { + 'Layout': value + }); + } + }); } editMainIdentity() { @@ -100,68 +162,6 @@ export class GeneralUserSettings { NotificationUserStore.displayDesktopNotification('SnappyMail', 'Test notification', { }); } - onBuild() { - setTimeout(() => { - const f0 = settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this), - f1 = settingsSaveHelperSimpleFunction(this.mppTrigger, this), - f2 = settingsSaveHelperSimpleFunction(this.layoutTrigger, this), - fReloadLanguageHelper = (saveSettingsStep) => () => { - this.languageTrigger(saveSettingsStep); - setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000); - }; - - this.language.subscribe((value) => { - this.languageTrigger(SaveSettingsStep.Animate); - translatorReload(false, value) - .then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult)) - .then(() => { - Remote.saveSettings(null, { - 'Language': value - }); - }); - }); - - 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')); - this.removeColors.subscribe(Remote.saveSettingsHelper('RemoveColors', v=>v?'1':'0')); - - this.useCheckboxesInList.subscribe(Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0')); - - this.enableDesktopNotification.subscribe((value => - Remote.saveSettings(null, { - 'DesktopNotifications': value ? 1 : 0 - }) - ).debounce(3000)); - - this.enableSoundNotification.subscribe((value => - Remote.saveSettings(null, { - 'SoundNotification': value ? 1 : 0 - }) - ).debounce(3000)); - - this.replySameFolder.subscribe((value => - Remote.saveSettings(null, { - 'ReplySameFolder': value ? 1 : 0 - }) - ).debounce(3000)); - - this.useThreads.subscribe((value) => { - MessageUserStore.list([]); - Remote.saveSettings(null, { - 'UseThreads': value ? 1 : 0 - }); - }); - - this.layout.subscribe((value) => { - MessageUserStore.list([]); - Remote.saveSettings(f2, { - 'Layout': value - }); - }); - }, 50); - } - selectLanguage() { showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]); } diff --git a/dev/Stores/User/Folder.js b/dev/Stores/User/Folder.js index 36260df1b..164b30ea4 100644 --- a/dev/Stores/User/Folder.js +++ b/dev/Stores/User/Folder.js @@ -2,7 +2,7 @@ import ko from 'ko'; import { FolderType } from 'Common/EnumsUser'; import { UNUSED_OPTION_VALUE } from 'Common/Consts'; -import { addObservablesTo } from 'Common/Utils'; +import { addObservablesTo, addSubscribablesTo } from 'Common/Utils'; import { folderListOptionsBuilder } from 'Common/UtilsUser'; import { getFolderInboxName, getFolderFromCacheList } from 'Common/Cache'; import { SettingsGet } from 'Common/Globals'; @@ -125,18 +125,19 @@ export const FolderUserStore = new class { ) ); - const fRemoveSystemFolderType = (observable) => () => { - const folder = getFolderFromCacheList(observable()); - if (folder) { - folder.type(FolderType.User); - } - }; - const fSetSystemFolderType = (type) => (value) => { - const folder = getFolderFromCacheList(value); - if (folder) { - folder.type(type); - } - }; + const + fRemoveSystemFolderType = (observable) => () => { + const folder = getFolderFromCacheList(observable()); + if (folder) { + folder.type(FolderType.User); + } + }, + fSetSystemFolderType = type => value => { + const folder = getFolderFromCacheList(value); + if (folder) { + folder.type(type); + } + }; this.sentFolder.subscribe(fRemoveSystemFolderType(this.sentFolder), this, 'beforeChange'); this.draftFolder.subscribe(fRemoveSystemFolderType(this.draftFolder), this, 'beforeChange'); @@ -144,11 +145,13 @@ export const FolderUserStore = new class { this.trashFolder.subscribe(fRemoveSystemFolderType(this.trashFolder), this, 'beforeChange'); this.archiveFolder.subscribe(fRemoveSystemFolderType(this.archiveFolder), this, 'beforeChange'); - this.sentFolder.subscribe(fSetSystemFolderType(FolderType.SentItems), this); - this.draftFolder.subscribe(fSetSystemFolderType(FolderType.Draft), this); - this.spamFolder.subscribe(fSetSystemFolderType(FolderType.Spam), this); - this.trashFolder.subscribe(fSetSystemFolderType(FolderType.Trash), this); - this.archiveFolder.subscribe(fSetSystemFolderType(FolderType.Archive), this); + addSubscribablesTo(this, { + sentFolder: fSetSystemFolderType(FolderType.SentItems), + draftFolder: fSetSystemFolderType(FolderType.Draft), + spamFolder: fSetSystemFolderType(FolderType.Spam), + trashFolder: fSetSystemFolderType(FolderType.Trash), + archiveFolder: fSetSystemFolderType(FolderType.Archive) + }); } /** diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index 67b2bd644..a4583da02 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -3,7 +3,7 @@ import ko from 'ko'; import { Notification } from 'Common/Enums'; import { Focused, MessageSetAction } from 'Common/EnumsUser'; import { doc, elementById } from 'Common/Globals'; -import { pInt, pString, addObservablesTo } from 'Common/Utils'; +import { pInt, pString, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; import { plainToHtml } from 'Common/UtilsUser'; import { @@ -170,52 +170,53 @@ export const MessageUserStore = new class { // Subscribers let timer = 0, fn = this.listLoadingAnimation; - this.listCompleteLoading.subscribe(value => { - if (value) { - fn(value); - } else if (fn()) { - clearTimeout(timer); - timer = setTimeout(() => { + + addSubscribablesTo(this, { + listCompleteLoading: value => { + if (value) { + fn(value); + } else if (fn()) { + clearTimeout(timer); + timer = setTimeout(() => { + fn(value); + timer = 0; + }, 700); + } else { fn(value); - timer = 0; - }, 700); - } else { - fn(value); - } - }); - - this.listLoading.subscribe(value => - this.listCompleteLoading(value || this.listIsNotCompleted()) - ); - this.listIsNotCompleted.subscribe(value => - this.listCompleteLoading(value || this.listLoading()) - ); - - this.list.subscribe( - (list => { - list.forEach(item => - item && item.newForAnimation() && item.newForAnimation(false) - ) - }).debounce(500) - ); - - this.message.subscribe(message => { - if (message) { - if (!SettingsUserStore.usePreviewPane()) { - AppUserStore.focusedState(Focused.MessageView); } - } else { - AppUserStore.focusedState(Focused.MessageList); + }, - this.messageFullScreenMode(false); - this.hideMessageBodies(); - } - }); + listLoading: value => + this.listCompleteLoading(value || this.listIsNotCompleted()), - this.listEndFolder.subscribe(folder => { - const message = this.message(); - if (message && folder && folder !== message.folder) { - this.message(null); + listIsNotCompleted: value => + this.listCompleteLoading(value || this.listLoading()), + + list: + (list => { + list.forEach(item => + item && item.newForAnimation() && item.newForAnimation(false) + ) + }).debounce(500), + + message: message => { + if (message) { + if (!SettingsUserStore.usePreviewPane()) { + AppUserStore.focusedState(Focused.MessageView); + } + } else { + AppUserStore.focusedState(Focused.MessageList); + + this.messageFullScreenMode(false); + this.hideMessageBodies(); + } + }, + + listEndFolder: folder => { + const message = this.message(); + if (message && folder && folder !== message.folder) { + this.message(null); + } } });