snappymail/dev/Settings/User/Contacts.js

44 lines
1.2 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
import { SettingsGet } from 'Common/Globals';
import { ContactUserStore } from 'Stores/User/Contact';
import Remote from 'Remote/User/Fetch';
2016-06-30 08:02:45 +08:00
export class ContactsUserSettings /*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;
this.enableContactsSync = ContactUserStore.enableSync;
this.contactsSyncUrl = ContactUserStore.syncUrl;
this.contactsSyncUser = ContactUserStore.syncUser;
this.contactsSyncPass = ContactUserStore.syncPass;
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
this.saveTrigger = ko
.computed(() =>
[
ContactUserStore.enableSync() ? '1' : '0',
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 =>
2016-07-16 05:29:42 +08:00
Remote.saveSettings(null, {
ContactsAutosave: value ? 1 : 0
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, {
Enable: ContactUserStore.enableSync() ? 1 : 0,
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
}
}