fix: [instance:settings] Revert setting back to its original in case of failure

pull/121/head
Sami Mokaddem 2022-11-15 11:03:11 +01:00
parent 62c228c44e
commit a9e85a34d3
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 14 additions and 7 deletions

View File

@ -67,14 +67,21 @@ function saveAndUpdateSetting(statusNode, $input, settingName, settingValue) {
settingValue = JSON.stringify(settingValue) settingValue = JSON.stringify(settingValue)
} }
saveSetting(statusNode, settingName, settingValue).then((result) => { saveSetting(statusNode, settingName, settingValue).then((result) => {
window.settingsFlattened[settingName] = result.data updateSettingValue($input, settingName, result.data)
if ($input.attr('type') == 'checkbox') { }).catch((e) => {
$input.prop('checked', result.data.value == true) updateSettingValue($input, settingName, window.settingsFlattened[settingName])
} else { }).finally(() => {
$input.val(result.data.value)
}
handleSettingValueChange($input) handleSettingValueChange($input)
}).catch((e) => { }) })
}
function updateSettingValue($input, settingName, settingValue) {
window.settingsFlattened[settingName] = settingValue
if ($input.attr('type') == 'checkbox') {
$input.prop('checked', settingValue.value == true)
} else {
$input.val(settingValue.value)
}
} }
function handleSettingValueChange($input) { function handleSettingValueChange($input) {