mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 01:52:22 +03:00
Make the settings serialization more dynamic
This commit is contained in:
parent
054c4fe36d
commit
1ee373a544
5 changed files with 32 additions and 12 deletions
|
@ -52,7 +52,11 @@ App.Pages.ApiSettings = (function () {
|
|||
|
||||
function deserialize(apiSettings) {
|
||||
apiSettings.forEach((apiSetting) => {
|
||||
$('[data-field="' + apiSetting.name + '"]').val(apiSetting.value);
|
||||
const $field = $('[data-field="' + apiSetting.name + '"]');
|
||||
|
||||
$field.is(':checkbox')
|
||||
? $field.prop('checked', Boolean(Number(apiSetting.value)))
|
||||
: $field.val(apiSetting.value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -64,7 +68,7 @@ App.Pages.ApiSettings = (function () {
|
|||
|
||||
apiSettings.push({
|
||||
name: $field.data('field'),
|
||||
value: $field.val()
|
||||
value: $field.is(':checkbox') ? Number($field.prop('checked')) : $field.val()
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
App.Pages.BusinessSettings = (function () {
|
||||
const $saveSettings = $('#save-settings');
|
||||
const $applyGlobalWorkingPlan = $('#apply-global-working-plan');
|
||||
const $appointmentStatusOptions = $('#appointment-status-options')
|
||||
const $appointmentStatusOptions = $('#appointment-status-options');
|
||||
let workingPlanManager = null;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,11 @@ App.Pages.BusinessSettings = (function () {
|
|||
|
||||
function deserialize(businessSettings) {
|
||||
businessSettings.forEach((businessSetting) => {
|
||||
$('[data-field="' + businessSetting.name + '"]').val(businessSetting.value);
|
||||
const $field = $('[data-field="' + businessSetting.name + '"]');
|
||||
|
||||
$field.is(':checkbox')
|
||||
? $field.prop('checked', Boolean(Number(businessSetting.value)))
|
||||
: $field.val(businessSetting.value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -67,7 +71,7 @@ App.Pages.BusinessSettings = (function () {
|
|||
|
||||
businessSettings.push({
|
||||
name: $field.data('field'),
|
||||
value: $field.val()
|
||||
value: $field.is(':checkbox') ? Number($field.prop('checked')) : $field.val()
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -160,7 +164,7 @@ App.Pages.BusinessSettings = (function () {
|
|||
workingPlanManager.setup(companyWorkingPlan);
|
||||
workingPlanManager.timepickers(false);
|
||||
workingPlanManager.addEventListeners();
|
||||
|
||||
|
||||
App.Components.AppointmentStatusOptions.setOptions($appointmentStatusOptions, appointmentStatusOptions);
|
||||
|
||||
$saveSettings.on('click', onSaveSettingsClick);
|
||||
|
|
|
@ -70,7 +70,11 @@ App.Pages.GeneralSettings = (function () {
|
|||
$resetCompanyColor.prop('hidden', false);
|
||||
}
|
||||
|
||||
$('[data-field="' + generalSetting.name + '"]').val(generalSetting.value);
|
||||
const $field = $('[data-field="' + generalSetting.name + '"]');
|
||||
|
||||
$field.is(':checkbox')
|
||||
? $field.prop('checked', Boolean(Number(generalSetting.value)))
|
||||
: $field.val(generalSetting.value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -82,7 +86,7 @@ App.Pages.GeneralSettings = (function () {
|
|||
|
||||
generalSettings.push({
|
||||
name: $field.data('field'),
|
||||
value: $field.val()
|
||||
value: $field.is(':checkbox') ? Number($field.prop('checked')) : $field.val()
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -52,7 +52,11 @@ App.Pages.GoogleAnalyticsSettings = (function () {
|
|||
|
||||
function deserialize(googleAnalyticsSettings) {
|
||||
googleAnalyticsSettings.forEach((googleAnalyticsSetting) => {
|
||||
$('[data-field="' + googleAnalyticsSetting.name + '"]').val(googleAnalyticsSetting.value);
|
||||
const $field = $('[data-field="' + googleAnalyticsSetting.name + '"]');
|
||||
|
||||
$field.is(':checkbox')
|
||||
? $field.prop('checked', Boolean(Number(googleAnalyticsSetting.value)))
|
||||
: $field.val(googleAnalyticsSetting.value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -64,7 +68,7 @@ App.Pages.GoogleAnalyticsSettings = (function () {
|
|||
|
||||
googleAnalyticsSettings.push({
|
||||
name: $field.data('field'),
|
||||
value: $field.val()
|
||||
value: $field.is(':checkbox') ? Number($field.prop('checked')) : $field.val()
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -52,7 +52,11 @@ App.Pages.MatomoAnalyticsSettings = (function () {
|
|||
|
||||
function deserialize(matomoAnalyticsSettings) {
|
||||
matomoAnalyticsSettings.forEach((matomoAnalyticsSetting) => {
|
||||
$('[data-field="' + matomoAnalyticsSetting.name + '"]').val(matomoAnalyticsSetting.value);
|
||||
const $field = $('[data-field="' + matomoAnalyticsSetting.name + '"]');
|
||||
|
||||
$field.is(':checkbox')
|
||||
? $field.prop('checked', Boolean(Number(matomoAnalyticsSetting.value)))
|
||||
: $field.val(matomoAnalyticsSetting.value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -64,7 +68,7 @@ App.Pages.MatomoAnalyticsSettings = (function () {
|
|||
|
||||
matomoAnalyticsSettings.push({
|
||||
name: $field.data('field'),
|
||||
value: $field.val()
|
||||
value: $field.is(':checkbox') ? Number($field.prop('checked')) : $field.val()
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue