snappymail/dev/Settings/User/Contacts.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2022-01-01 00:02:32 +08:00
import { koComputable } from 'External/ko';
2016-06-30 08:02:45 +08:00
import { SettingsGet } from 'Common/Globals';
2022-04-16 17:01:24 +08:00
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
import { ContactUserStore } from 'Stores/User/Contact';
import Remote from 'Remote/User/Fetch';
2016-06-30 08:02:45 +08:00
export class UserSettingsContacts /*extends AbstractViewSettings*/ {
2016-07-16 05:29:42 +08:00
constructor() {
this.contactsAutosave = ko.observable(!!SettingsGet('ContactsAutosave'));
2016-06-30 08:02:45 +08:00
this.allowContactsSync = ContactUserStore.allowSync;
2022-04-16 17:01:24 +08:00
this.syncMode = ContactUserStore.syncMode;
this.syncUrl = ContactUserStore.syncUrl;
this.syncUser = ContactUserStore.syncUser;
this.syncPass = ContactUserStore.syncPass;
const i18nSyncMode = key => i18n('SETTINGS_CONTACTS/SYNC_' + key);
this.syncModeOptions = koComputable(() => {
translatorTrigger();
return [
{ id: 0, name: i18nSyncMode('NO') },
{ id: 1, name: i18nSyncMode('YES') },
{ id: 2, name: i18nSyncMode('READ') },
];
});
2016-06-30 08:02:45 +08:00
2022-01-01 00:02:32 +08:00
this.saveTrigger = koComputable(() =>
2019-07-05 03:19:24 +08:00
[
2022-04-16 17:01:24 +08:00
ContactUserStore.syncMode(),
ContactUserStore.syncUrl(),
ContactUserStore.syncUser(),
ContactUserStore.syncPass()
2019-07-05 03:19:24 +08:00
].join('|')
)
.extend({ debounce: 500 });
2016-07-16 05:29:42 +08:00
2021-03-16 18:38:40 +08:00
this.contactsAutosave.subscribe(value =>
2022-03-01 17:18:12 +08:00
Remote.saveSettings(null, { ContactsAutosave: value })
2021-03-16 18:38:40 +08:00
);
2016-06-30 08:02:45 +08:00
2021-03-16 18:38:40 +08:00
this.saveTrigger.subscribe(() =>
Remote.request('SaveContactsSyncData', null, {
2022-04-16 17:01:24 +08:00
Mode: ContactUserStore.syncMode(),
Url: ContactUserStore.syncUrl(),
User: ContactUserStore.syncUser(),
Password: ContactUserStore.syncPass()
})
2021-03-16 18:38:40 +08:00
);
2016-07-16 05:29:42 +08:00
}
}