From 2c02d12fde6896f0948339552f58340311cde8b4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 31 Jul 2018 21:51:58 +0200 Subject: [PATCH] Implement selector drafts --- Admin/Routes/Web/Api.php | 19 +++ Controller.php | 81 +++++++++++ .../DepartmentTagSelectorView.php | 1 + .../department-selector-popup.tpl.php | 128 ++++++------------ .../department-selector.tpl.php | 20 +-- .../PositionTagSelectorView.php | 1 + .../position-selector-popup.tpl.php | 128 ++++++------------ .../position-selector.tpl.php | 20 +-- .../UnitTagSelector/UnitTagSelectorView.php | 1 + .../unit-selector-popup.tpl.php | 128 ++++++------------ .../UnitTagSelector/unit-selector.tpl.php | 20 +-- Theme/Backend/department-create.tpl.php | 4 +- Theme/Backend/department-profile.tpl.php | 4 +- Theme/Backend/position-create.tpl.php | 2 + Theme/Backend/position-profile.tpl.php | 2 + Theme/Backend/unit-create.tpl.php | 2 + Theme/Backend/unit-profile.tpl.php | 4 +- 17 files changed, 280 insertions(+), 285 deletions(-) diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php index 36a18e9..014fc8b 100644 --- a/Admin/Routes/Web/Api.php +++ b/Admin/Routes/Web/Api.php @@ -57,4 +57,23 @@ return [ 'verb' => RouteVerb::DELETE, ], ], + + '^.*/api/organization/find/unit.*$' => [ + [ + 'dest' => '\Modules\Organization\Controller:apiUnitFind', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/api/organization/find/department.*$' => [ + [ + 'dest' => '\Modules\Organization\Controller:apiDepartmentFind', + 'verb' => RouteVerb::GET, + ], + ], + '^.*/api/organization/find/position.*$' => [ + [ + 'dest' => '\Modules\Organization\Controller:apiPositionFind', + 'verb' => RouteVerb::GET, + ], + ], ]; diff --git a/Controller.php b/Controller.php index 514f1ec..6fb8874 100644 --- a/Controller.php +++ b/Controller.php @@ -1080,4 +1080,85 @@ final class Controller extends ModuleAbstract implements WebInterface return $department; } + + /** + * Api method to find units + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiUnitFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!$this->app->accountManager->get($request->getHeader()->getAccount())->hasPermission( + PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::UNIT) + ) { + $response->set('unit_find', null); + $response->getHeader()->setStatusCode(RequestStatusCode::R_403); + return; + } + + $response->getHeader()->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->getUri()->__toString(), array_values(UnitMapper::find((string) ($request->getData('search') ?? '')))); + } + + /** + * Api method to find departments + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiDepartmentFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!$this->app->accountManager->get($request->getHeader()->getAccount())->hasPermission( + PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::DEPARTMENT) + ) { + $response->set('department_find', null); + $response->getHeader()->setStatusCode(RequestStatusCode::R_403); + return; + } + + $response->getHeader()->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->getUri()->__toString(), array_values(DepartmentMapper::find((string) ($request->getData('search') ?? '')))); + } + + /** + * Api method to find positions + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiPositionFind(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + if (!$this->app->accountManager->get($request->getHeader()->getAccount())->hasPermission( + PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::POSITION) + ) { + $response->set('position_find', null); + $response->getHeader()->setStatusCode(RequestStatusCode::R_403); + return; + } + + $response->getHeader()->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->getUri()->__toString(), array_values(PositionMapper::find((string) ($request->getData('search') ?? '')))); + } } diff --git a/Theme/Backend/Components/DepartmentTagSelector/DepartmentTagSelectorView.php b/Theme/Backend/Components/DepartmentTagSelector/DepartmentTagSelectorView.php index c80e042..5980633 100644 --- a/Theme/Backend/Components/DepartmentTagSelector/DepartmentTagSelectorView.php +++ b/Theme/Backend/Components/DepartmentTagSelector/DepartmentTagSelectorView.php @@ -48,6 +48,7 @@ class DepartmentTagSelectorView extends View $this->id = $data[0]; $this->isRequired = $data[1] ?? false; $this->getData('department-selector-popup')->setId($this->id); + return parent::render(); } } diff --git a/Theme/Backend/Components/DepartmentTagSelector/department-selector-popup.tpl.php b/Theme/Backend/Components/DepartmentTagSelector/department-selector-popup.tpl.php index 9369a83..59eb39b 100644 --- a/Theme/Backend/Components/DepartmentTagSelector/department-selector-popup.tpl.php +++ b/Theme/Backend/Components/DepartmentTagSelector/department-selector-popup.tpl.php @@ -1,90 +1,48 @@ -