Handle backend save response in dashboard js

This commit is contained in:
Stephen Abello
2026-01-15 11:08:20 +01:00
parent 3a6e148c11
commit 7c21178e1d
2 changed files with 18 additions and 6 deletions

View File

@@ -273,11 +273,15 @@ class IboDashboard extends HTMLElement {
let sSaveUrl = GetAbsoluteUrlAppRoot() + '/pages/UI.php?route=dashboard.save&values='+encodeURIComponent(JSON.stringify(aPayload));
fetch(sSaveUrl)
.then(async data => {
// TODO 3.3 What's returned ?
const res = await data.json();
if(res.status === 'ok') {
CombodoToast.OpenToast(res.message, 'success');
this.SetEditMode(false);
this.aLastSavedState = aPayload;
} else {
CombodoToast.OpenToast(res.message, 'error');
}
})
this.SetEditMode(false);
this.aLastSavedState = aPayload;
}

View File

@@ -88,6 +88,8 @@ class DashboardController extends Controller
{
$sValues = utils::ReadParam('values', '', false, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
$aValues = !empty($sValues) ? json_decode($sValues, true, 20) : [];
$sStatus = 'error';
$sMessage = 'Unknown error';
try {
// Get the form block from the service (and the compiler)
@@ -106,15 +108,21 @@ class DashboardController extends Controller
XMLSerializer::GetInstance()->Serialize($aValues, $oDomNode, 'DashboardGrid', 'Dashboard');
$sXml = $oDomNode->ownerDocument->saveXML();
$oDashboard->PersistDashboard($sXml);
$sStatus = 'ok';
$sMessage = 'Dashboard saved';
// }
// }
} catch (Exception $e) {
IssueLog::Exception($e->getMessage(), $e);
return null;
$sStatus = 'error';
$sMessage = $e->getMessage();
}
$oPage = new JsonPage();
$oPage->SetData($aValues);
$oPage->SetData([
'status' => $sStatus,
'message' => $sMessage
]);
$oPage->SetOutputDataOnly(true);
return $oPage;
}