2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +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
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
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({ throttle: Magics.Time500ms });
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onBuild() {
|
|
|
|
this.contactsAutosave.subscribe((value) => {
|
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'ContactsAutosave': boolToAjax(value)
|
|
|
|
});
|
2014-10-30 21:59:25 +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()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { ContactsUserSettings, ContactsUserSettings as default };
|