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
|
|
|
|
2021-03-16 23:06:16 +08:00
|
|
|
import { SettingsGet } from 'Common/Globals';
|
2022-04-16 17:01:24 +08:00
|
|
|
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
|
2021-03-11 05:41:35 +08:00
|
|
|
import { ContactUserStore } from 'Stores/User/Contact';
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-03-08 07:51:32 +08:00
|
|
|
export class UserSettingsContacts /*extends AbstractViewSettings*/ {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2021-03-16 23:06:16 +08:00
|
|
|
this.contactsAutosave = ko.observable(!!SettingsGet('ContactsAutosave'));
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-11 05:41:35 +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(),
|
2021-03-11 05:41:35 +08:00
|
|
|
ContactUserStore.syncUrl(),
|
|
|
|
ContactUserStore.syncUser(),
|
|
|
|
ContactUserStore.syncPass()
|
2019-07-05 03:19:24 +08:00
|
|
|
].join('|')
|
|
|
|
)
|
2021-02-10 19:12:36 +08:00
|
|
|
.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(() =>
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('SaveContactsSyncData', null, {
|
2022-04-16 17:01:24 +08:00
|
|
|
Mode: ContactUserStore.syncMode(),
|
2021-12-03 06:15:24 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|