This commit is contained in:
the-djmaze 2022-04-16 11:01:24 +02:00
parent 7bbc53c8af
commit 0a49027840
64 changed files with 239 additions and 123 deletions

View file

@ -2,6 +2,7 @@ import ko from 'ko';
import { koComputable } from 'External/ko';
import { SettingsGet } from 'Common/Globals';
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
import { ContactUserStore } from 'Stores/User/Contact';
import Remote from 'Remote/User/Fetch';
@ -10,14 +11,24 @@ export class UserSettingsContacts /*extends AbstractViewSettings*/ {
this.contactsAutosave = ko.observable(!!SettingsGet('ContactsAutosave'));
this.allowContactsSync = ContactUserStore.allowSync;
this.enableContactsSync = ContactUserStore.enableSync;
this.contactsSyncUrl = ContactUserStore.syncUrl;
this.contactsSyncUser = ContactUserStore.syncUser;
this.contactsSyncPass = ContactUserStore.syncPass;
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') },
];
});
this.saveTrigger = koComputable(() =>
[
ContactUserStore.enableSync() ? '1' : '0',
ContactUserStore.syncMode(),
ContactUserStore.syncUrl(),
ContactUserStore.syncUser(),
ContactUserStore.syncPass()
@ -31,7 +42,7 @@ export class UserSettingsContacts /*extends AbstractViewSettings*/ {
this.saveTrigger.subscribe(() =>
Remote.request('SaveContactsSyncData', null, {
Enable: ContactUserStore.enableSync() ? 1 : 0,
Mode: ContactUserStore.syncMode(),
Url: ContactUserStore.syncUrl(),
User: ContactUserStore.syncUser(),
Password: ContactUserStore.syncPass()

View file

@ -12,7 +12,7 @@ ContactUserStore.syncing = ko.observable(false).extend({ debounce: 200 });
addObservablesTo(ContactUserStore, {
allowSync: false, // Admin setting
enableSync: false,
syncMode: 0,
syncUrl: '',
syncUser: '',
syncPass: ''
@ -23,7 +23,7 @@ addObservablesTo(ContactUserStore, {
* @returns {void}
*/
ContactUserStore.sync = fResultFunc => {
if (ContactUserStore.enableSync()
if (ContactUserStore.syncMode()
&& !ContactUserStore.importing()
&& !ContactUserStore.syncing()
) {
@ -39,7 +39,7 @@ ContactUserStore.init = () => {
let value = !!SettingsGet('ContactsSyncIsAllowed');
ContactUserStore.allowSync(value);
if (value) {
ContactUserStore.enableSync(!!SettingsGet('EnableContactsSync'));
ContactUserStore.syncMode(SettingsGet('ContactsSyncMode'));
ContactUserStore.syncUrl(SettingsGet('ContactsSyncUrl'));
ContactUserStore.syncUser(SettingsGet('ContactsSyncUser'));
ContactUserStore.syncPass(SettingsGet('ContactsSyncPassword'));

View file

@ -37,9 +37,6 @@ export class ContactsPopupView extends AbstractViewPopup {
this.bBackToCompose = false;
this.sLastComposeFocusedField = '';
this.allowContactsSync = ContactUserStore.allowSync;
this.enableContactsSync = ContactUserStore.enableSync;
this.addObservables({
search: '',
contactsCount: 0,
@ -124,6 +121,8 @@ export class ContactsPopupView extends AbstractViewPopup {
contactsCheckedOrSelectedUids: () => this.contactsCheckedOrSelected().map(contact => contact.id),
contactsSyncEnabled: () => ContactUserStore.allowSync() && ContactUserStore.syncMode(),
viewHash: () => '' + this.viewProperties.map(property => property.value && property.value()).join('')
});