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)
}
saveSetting(statusNode, settingName, settingValue).then((result) => {
window.settingsFlattened[settingName] = result.data
if ($input.attr('type') == 'checkbox') {
$input.prop('checked', result.data.value == true)
} else {
$input.val(result.data.value)
}
updateSettingValue($input, settingName, result.data)
}).catch((e) => {
updateSettingValue($input, settingName, window.settingsFlattened[settingName])
}).finally(() => {
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) {