snappymail/dev/Settings/User/Contacts.js

47 lines
1.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 AppStore from 'Stores/User/App';
import ContactStore from 'Stores/User/Contact';
import Remote from 'Remote/User/Fetch';
2016-06-30 08:02:45 +08:00
2021-01-22 23:32:08 +08:00
export class ContactsUserSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.contactsAutosave = AppStore.contactsAutosave;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.allowContactsSync = ContactStore.allowContactsSync;
this.enableContactsSync = ContactStore.enableContactsSync;
this.contactsSyncUrl = ContactStore.contactsSyncUrl;
this.contactsSyncUser = ContactStore.contactsSyncUser;
this.contactsSyncPass = ContactStore.contactsSyncPass;
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
this.saveTrigger = ko
.computed(() =>
[
this.enableContactsSync() ? '1' : '0',
this.contactsSyncUrl(),
this.contactsSyncUser(),
this.contactsSyncPass()
].join('|')
)
.extend({ debounce: 500 });
2016-07-16 05:29:42 +08:00
}
onBuild() {
this.contactsAutosave.subscribe((value) => {
Remote.saveSettings(null, {
'ContactsAutosave': value ? '1' : '0'
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.saveTrigger.subscribe(() => {
2019-07-05 03:19:24 +08:00
Remote.saveContactsSyncData(
null,
2016-07-16 05:29:42 +08:00
this.enableContactsSync(),
this.contactsSyncUrl(),
this.contactsSyncUser(),
this.contactsSyncPass()
);
});
}
}