2021-11-10 09:06:39 +01:00
|
|
|
function mergeAndSaveSettings(table_setting_id, newTableSettings, automaticFeedback=true) {
|
2021-10-20 11:28:39 +02:00
|
|
|
const settingName = 'ui.table_setting'
|
2022-01-26 12:11:44 +01:00
|
|
|
const urlGet = `/user-settings/getMySettingByName/${settingName}`
|
2021-11-10 09:06:39 +01:00
|
|
|
return AJAXApi.quickFetchJSON(urlGet).then(tableSettings => {
|
2021-10-20 11:28:39 +02:00
|
|
|
tableSettings = JSON.parse(tableSettings.value)
|
|
|
|
newTableSettings = mergeNewTableSettingsIntoOld(table_setting_id, tableSettings, newTableSettings)
|
2021-11-10 09:06:39 +01:00
|
|
|
return saveTableSetting(settingName, newTableSettings, automaticFeedback)
|
2021-10-20 11:28:39 +02:00
|
|
|
}).catch((e) => { // setting probably doesn't exist
|
2021-11-10 09:06:39 +01:00
|
|
|
return saveTableSetting(settingName, newTableSettings, automaticFeedback)
|
2021-10-20 11:28:39 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function mergeNewTableSettingsIntoOld(table_setting_id, oldTableSettings, newTableSettings) {
|
|
|
|
// Merge recursively
|
|
|
|
tableSettings = Object.assign({}, oldTableSettings, newTableSettings)
|
|
|
|
tableSettings[table_setting_id] = Object.assign({}, oldTableSettings[table_setting_id], newTableSettings[table_setting_id])
|
|
|
|
return tableSettings
|
|
|
|
}
|
|
|
|
|
2022-02-24 14:50:57 +01:00
|
|
|
function saveTableSetting(settingName, newTableSettings, automaticFeedback=true) {
|
2022-01-26 12:11:44 +01:00
|
|
|
const urlSet = `/user-settings/setMySetting/${settingName}`
|
2021-11-10 09:06:39 +01:00
|
|
|
return AJAXApi.quickFetchAndPostForm(urlSet, {
|
2021-10-20 11:28:39 +02:00
|
|
|
value: JSON.stringify(newTableSettings)
|
|
|
|
}, {
|
|
|
|
provideFeedback: false
|
2021-11-10 09:06:39 +01:00
|
|
|
}).then((postResult) => {
|
|
|
|
if (automaticFeedback) {
|
|
|
|
UI.toast({
|
|
|
|
variant: 'success',
|
|
|
|
title: 'Table setting saved',
|
|
|
|
delay: 3000
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return postResult
|
2021-10-20 11:28:39 +02:00
|
|
|
})
|
|
|
|
}
|