diff --git a/js/layouts/dashboard/dashboard-grid-slot.js b/js/layouts/dashboard/dashboard-grid-slot.js index 76f1ef067..704981930 100644 --- a/js/layouts/dashboard/dashboard-grid-slot.js +++ b/js/layouts/dashboard/dashboard-grid-slot.js @@ -43,10 +43,10 @@ class IboGridSlot extends HTMLElement { const oDashlet = this.oDashlet; const aSlotData = { - x: this.iPosX, - y: this.iPostY, - w: this.iWidth, - h: this.iHeight + position_x: this.iPosX, + position_y: this.iPostY, + width: this.iWidth, + height: this.iHeight }; const aDashletData = oDashlet ? oDashlet.Serialize() : {}; diff --git a/js/layouts/dashboard/dashboard.js b/js/layouts/dashboard/dashboard.js index 5d070fa8d..70b48f560 100644 --- a/js/layouts/dashboard/dashboard.js +++ b/js/layouts/dashboard/dashboard.js @@ -216,8 +216,9 @@ class IboDashboard extends HTMLElement { schema_version: this.schemaVersion, id: this.sId, title: sDashboardTitle, - refresh_rate: sDashboardRefreshRate, - dashlets: aSerializedGrid + refresh: sDashboardRefreshRate, + dashlets_list: aSerializedGrid, + _token: ":)" }; } @@ -226,6 +227,12 @@ class IboDashboard extends HTMLElement { // TODO 3.3: Implement saving dashboard state to server when backend is ready // May try to save as serialized PHP if XML format is not yet decided console.log(aPayload); + // Fetch dashlet form from server + 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 ? + }) this.SetEditMode(false); this.aLastSavedState = aPayload; diff --git a/js/layouts/dashboard/dashlet.js b/js/layouts/dashboard/dashlet.js index 5686959a8..7fe19ff39 100644 --- a/js/layouts/dashboard/dashlet.js +++ b/js/layouts/dashboard/dashlet.js @@ -50,10 +50,11 @@ class IboDashlet extends HTMLElement { } Serialize() { + // TODO 3.3 Should we use getters ? const aDashletData = { id: this.sDashletId, - type: this.sType, - formData: this.formData, + class: this.sType, + dashlet: JSON.parse(this.formData), }; return aDashletData; diff --git a/sources/Controller/Base/Layout/DashboardController.php b/sources/Controller/Base/Layout/DashboardController.php index aade09b1e..3cb3797cc 100644 --- a/sources/Controller/Base/Layout/DashboardController.php +++ b/sources/Controller/Base/Layout/DashboardController.php @@ -8,6 +8,8 @@ use Combodo\iTop\Application\UI\Base\Component\Dashlet\DashletWrapper; use Combodo\iTop\Application\UI\Base\Component\TurboForm\TurboFormUIBlockFactory; use Combodo\iTop\Application\UI\Base\iUIBlock; use Combodo\iTop\Application\WebPage\AjaxPage; +use Combodo\iTop\Application\WebPage\JsonPage; +use Combodo\iTop\Controller\AbstractController; use Combodo\iTop\Service\DependencyInjection\ServiceLocator; use ModelReflectionRuntime; use utils; @@ -70,4 +72,17 @@ class DashboardController extends Controller return $oPage; } + + public function OperationSave() + { + $sValues = utils::ReadParam('values', '', false, utils::ENUM_SANITIZATION_FILTER_RAW_DATA); + $aValues = !empty($sValues) ? json_decode($sValues, true, 20) : []; + + // TODO 3.3 Consume the values and persist them + + $oPage = new JsonPage(); + $oPage->SetData($aValues); + $oPage->SetOutputDataOnly(true); + return $oPage; + } }