mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Handle backend save response in dashboard js
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user