snappymail/dev/Settings/User/Contacts.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
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 {Magics} from 'Common/Enums';
import {boolToAjax} from 'Common/Utils';
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/Ajax';
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
class ContactsUserSettings
2016-06-30 08:02:45 +08:00
{
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
2016-07-16 05:29:42 +08:00
this.saveTrigger = ko.computed(() => [
2016-06-30 08:02:45 +08:00
this.enableContactsSync() ? '1' : '0',
this.contactsSyncUrl(),
this.contactsSyncUser(),
this.contactsSyncPass()
2016-07-16 05:29:42 +08:00
].join('|')).extend({throttle: Magics.Time500ms});
}
onBuild() {
this.contactsAutosave.subscribe((value) => {
Remote.saveSettings(null, {
'ContactsAutosave': boolToAjax(value)
});
});
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.saveTrigger.subscribe(() => {
Remote.saveContactsSyncData(null,
this.enableContactsSync(),
this.contactsSyncUrl(),
this.contactsSyncUser(),
this.contactsSyncPass()
);
});
}
}
2016-06-30 08:02:45 +08:00
2016-07-16 03:54:37 +08:00
export {ContactsUserSettings, ContactsUserSettings as default};