From a4bb09253f67b1ba87a743e9168ecb03caa8ed9c Mon Sep 17 00:00:00 2001 From: mokaddem Date: Wed, 13 Jan 2021 14:15:53 +0100 Subject: [PATCH] chg: [sharinggroup] Improved support of CRUDComponent --- src/Controller/Component/CRUDComponent.php | 2 +- src/Controller/SharingGroupsController.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index d96dd11..988c7d7 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -223,7 +223,7 @@ class CRUDComponent extends Component $data = $this->Table->patchEntity($data, $input, $patchEntityParams); $savedData = $this->Table->save($data); if ($savedData !== false) { - $message = __('{0} updated.', $this->ObjectAlias); + $message = __('{0} `{1}` updated.', $this->ObjectAlias, $savedData->{$this->Table->getDisplayField()}); if (!empty($input['metaFields'])) { $this->MetaFields->deleteAll(['scope' => $this->Table->metaFields, 'parent_id' => $data->id]); $this->saveMetaFields($data->id, $input); diff --git a/src/Controller/SharingGroupsController.php b/src/Controller/SharingGroupsController.php index a37701c..5f246f7 100644 --- a/src/Controller/SharingGroupsController.php +++ b/src/Controller/SharingGroupsController.php @@ -31,8 +31,9 @@ class SharingGroupsController extends AppController $dropdownData = [ 'organisation' => $this->getAvailableOrgForSg($this->ACL->getUser()) ]; - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set(compact('dropdownData')); $this->set('metaGroup', 'Trust Circles'); @@ -52,8 +53,9 @@ class SharingGroupsController extends AppController public function edit($id = false) { $this->CRUD->edit($id); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $dropdownData = [ 'organisation' => $this->getAvailableOrgForSg($this->ACL->getUser()) @@ -66,8 +68,9 @@ class SharingGroupsController extends AppController public function delete($id) { $this->CRUD->delete($id); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', 'Trust Circles'); } @@ -110,7 +113,7 @@ class SharingGroupsController extends AppController } else { $message = __('Organisation(s) could not be added to the sharing group.'); } - if ($this->ParamHandler->isRest()) { + if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) { if ($result) { $this->RestResponse->saveSuccessResponse('SharingGroups', 'addOrg', $id, 'json', $message); } else {