Updated subscribables

This commit is contained in:
djmaze 2021-03-16 11:38:40 +01:00
parent 4b6f6b1bfc
commit 004eba6be2
7 changed files with 200 additions and 219 deletions

View file

@ -2,7 +2,12 @@ import ko from 'ko';
import { SaveSettingsStep } from 'Common/Enums';
import { SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction, defaultOptionsAfterRender, addObservablesTo } from 'Common/Utils';
import {
settingsSaveHelperSimpleFunction,
defaultOptionsAfterRender,
addObservablesTo,
addSubscribablesTo
} from 'Common/Utils';
import Remote from 'Remote/Admin/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
@ -50,7 +55,7 @@ export class ContactsAdminSettings {
this.mainContactsType = ko
.computed({
read: this.contactsType,
write: (value) => {
write: value => {
if (value !== this.contactsType()) {
if (supportedTypes.includes(value)) {
this.contactsType(value);
@ -64,11 +69,41 @@ export class ContactsAdminSettings {
})
.extend({ notify: 'always' });
this.contactsType.subscribe(() => {
this.testContactsSuccess(false);
this.testContactsError(false);
this.testContactsErrorMessage('');
});
addSubscribablesTo(this, {
enableContacts: value =>
Remote.saveAdminConfig(null, {
'ContactsEnable': value ? 1 : 0
}),
contactsSync: value =>
Remote.saveAdminConfig(null, {
'ContactsSync': value ? 1 : 0
}),
contactsType: value => {
this.testContactsSuccess(false);
this.testContactsError(false);
this.testContactsErrorMessage('');
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this), {
'ContactsPdoType': value.trim()
})
},
pdoDsn: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this), {
'ContactsPdoDsn': value.trim()
}),
pdoUser: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this), {
'ContactsPdoUser': value.trim()
}),
pdoPassword: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this), {
'ContactsPdoPassword': value.trim()
})
})
this.contactsType(SettingsGet('ContactsPdoType'));
@ -117,51 +152,4 @@ export class ContactsAdminSettings {
this.testContactsError(false);
this.testContactsErrorMessage('');
}
onBuild() {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this),
f3 = settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this),
f4 = settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this),
f5 = settingsSaveHelperSimpleFunction(this.contactsTypeTrigger, this);
this.enableContacts.subscribe((value) => {
Remote.saveAdminConfig(null, {
'ContactsEnable': value ? '1' : '0'
});
});
this.contactsSync.subscribe((value) => {
Remote.saveAdminConfig(null, {
'ContactsSync': value ? '1' : '0'
});
});
this.contactsType.subscribe((value) => {
Remote.saveAdminConfig(f5, {
'ContactsPdoType': value.trim()
});
});
this.pdoDsn.subscribe((value) => {
Remote.saveAdminConfig(f1, {
'ContactsPdoDsn': value.trim()
});
});
this.pdoUser.subscribe((value) => {
Remote.saveAdminConfig(f3, {
'ContactsPdoUser': value.trim()
});
});
this.pdoPassword.subscribe((value) => {
Remote.saveAdminConfig(f4, {
'ContactsPdoPassword': value.trim()
});
});
this.contactsType(SettingsGet('ContactsPdoType'));
}, 50);
}
}

View file

@ -1,7 +1,7 @@
import ko from 'ko';
import { Settings, SettingsGet } from 'Common/Globals';
import { settingsSaveHelperSimpleFunction, addObservablesTo } from 'Common/Utils';
import { settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils';
import Remote from 'Remote/Admin/Fetch';
@ -15,41 +15,32 @@ export class LoginAdminSettings {
});
this.defaultDomain = ko.observable(SettingsGet('LoginDefaultDomain')).idleTrigger();
}
onBuild() {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this);
this.determineUserLanguage.subscribe(value =>
addSubscribablesTo(this, {
determineUserLanguage: value =>
Remote.saveAdminConfig(null, {
'DetermineUserLanguage': value ? '1' : '0'
})
);
'DetermineUserLanguage': value ? 1 : 0
}),
this.determineUserDomain.subscribe(value =>
determineUserDomain: value =>
Remote.saveAdminConfig(null, {
'DetermineUserDomain': value ? '1' : '0'
})
);
'DetermineUserDomain': value ? 1 : 0
}),
this.allowLanguagesOnLogin.subscribe(value =>
allowLanguagesOnLogin: value =>
Remote.saveAdminConfig(null, {
'AllowLanguagesOnLogin': value ? '1' : '0'
})
);
'AllowLanguagesOnLogin': value ? 1 : 0
}),
this.hideSubmitButton.subscribe(value =>
hideSubmitButton: value =>
Remote.saveAdminConfig(null, {
'hideSubmitButton': value ? '1' : '0'
})
);
'hideSubmitButton': value ? 1 : 0
}),
this.defaultDomain.subscribe(value =>
Remote.saveAdminConfig(f1, {
defaultDomain: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this), {
'LoginDefaultDomain': value.trim()
})
);
}, 50);
});
}
}

View file

@ -21,6 +21,12 @@ export class PluginsAdminSettings {
this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this);
this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this);
this.enabledPlugins.subscribe(value =>
Remote.saveAdminConfig(null, {
'EnabledPlugins': value ? 1 : 0
})
);
}
disablePlugin(plugin) {
@ -40,12 +46,6 @@ export class PluginsAdminSettings {
el = event.target.closestWithin('.e-item .disabled-plugin', oDom);
el && ko.dataFor(el) && this.disablePlugin(ko.dataFor(el));
});
this.enabledPlugins.subscribe((value) => {
Remote.saveAdminConfig(null, {
'EnabledPlugins': value ? '1' : '0'
});
});
}
onShow() {