-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRW-9170 Changed ACL role form fields in Back Office to select type. …
…(#11136) FRW-9170 Changed ACL role form fields in Back Office to select type.
- Loading branch information
1 parent
c5036b8
commit 1c309a1
Showing
17 changed files
with
463 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
$(document).ready(function () { | ||
initializeDropdowns(); | ||
|
||
$('.js-select-dependable.js-select-dependable--bundle').on('change', function (event) { | ||
handleBundleChange(event); | ||
}); | ||
|
||
$('.js-select-dependable.js-select-dependable--controller').on('change', function (event) { | ||
handleControllerChange(event); | ||
}); | ||
}); | ||
|
||
function initializeDropdowns() { | ||
const dropdowns = getDropdowns(); | ||
resetDropdowns([dropdowns.controller, dropdowns.action]); | ||
disablePlaceholders(dropdowns.all); | ||
} | ||
|
||
function getDropdowns() { | ||
const bundle = $('.js-select-dependable.js-select-dependable--bundle'); | ||
const controller = $('.js-select-dependable.js-select-dependable--controller'); | ||
const action = $('.js-select-dependable.js-select-dependable--action'); | ||
return { | ||
bundle, | ||
controller, | ||
action, | ||
all: [bundle, controller, action], | ||
}; | ||
} | ||
|
||
function handleBundleChange(event) { | ||
const dropdowns = getDropdowns(); | ||
handleDropdownChange(event, `/acl/rules/controller-choices?bundle=`, dropdowns.controller); | ||
resetDropdowns([dropdowns.action]); | ||
} | ||
|
||
function handleControllerChange(event) { | ||
const dropdowns = getDropdowns(); | ||
const bundle = $('.js-select-dependable.js-select-dependable--bundle').val(); | ||
handleDropdownChange(event, `/acl/rules/action-choices?bundle=${bundle}&controller=`, dropdowns.action); | ||
} | ||
|
||
function resetDropdowns(dropdownsArray) { | ||
dropdownsArray.forEach((dropdown) => { | ||
const emptyOption = getEmptyOption(dropdown); | ||
dropdown.empty().append(emptyOption); | ||
}); | ||
} | ||
|
||
function disablePlaceholders(dropdownsArray) { | ||
dropdownsArray.forEach((dropdown) => { | ||
const emptyOption = getEmptyOption(dropdown); | ||
}); | ||
} | ||
|
||
function getEmptyOption(dropdown) { | ||
const firstDropdown = dropdown[0]; | ||
const emptyOption = firstDropdown ? firstDropdown.querySelector('option[value=""]') : null; | ||
|
||
if (emptyOption) { | ||
emptyOption.disabled = true; | ||
} | ||
const option = new Option(emptyOption ? emptyOption.text : 'Select option', '', true, true); | ||
option.disabled = true; | ||
return option; | ||
} | ||
|
||
function handleDropdownAvailability(isDisabled) { | ||
const dropdowns = getDropdowns().all; | ||
dropdowns.forEach((dropdown) => dropdown.prop('disabled', isDisabled)); | ||
} | ||
|
||
function handleDropdownChange(event, queryUrl, dropdown) { | ||
const value = event.target.value; | ||
sendRequest(queryUrl + value, dropdown); | ||
} | ||
|
||
function sendRequest(queryUrl, dropdown) { | ||
handleDropdownAvailability(true); | ||
|
||
$.ajax({ | ||
url: queryUrl, | ||
}).done(function (data) { | ||
updateDropdownData(dropdown, data); | ||
handleDropdownAvailability(false); | ||
}); | ||
} | ||
|
||
function updateDropdownData(dropdown, data) { | ||
const emptyOption = getEmptyOption(dropdown); | ||
dropdown.empty().append(emptyOption); | ||
for (const [key, value] of Object.entries(data)) { | ||
dropdown.append(new Option(key, value, false, false)); | ||
} | ||
dropdown.prop('disabled', false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Spryker/Zed/Acl/Communication/Controller/RulesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Acl\Communication\Controller; | ||
|
||
use Spryker\Zed\Kernel\Communication\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* @method \Spryker\Zed\Acl\Communication\AclCommunicationFactory getFactory() | ||
* @method \Spryker\Zed\Acl\Business\AclFacadeInterface getFacade() | ||
* @method \Spryker\Zed\Acl\Persistence\AclQueryContainerInterface getQueryContainer() | ||
* @method \Spryker\Zed\Acl\Persistence\AclRepositoryInterface getRepository() | ||
*/ | ||
class RulesController extends AbstractController | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected const BUNDLE_FIELD = 'bundle'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const CONTROLLER_FIELD = 'controller'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const ROOT_ACCESS = '*'; | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* | ||
* @return \Symfony\Component\HttpFoundation\JsonResponse | ||
*/ | ||
public function controllerChoicesAction(Request $request): JsonResponse | ||
{ | ||
$bundle = (string)$request->query->get(static::BUNDLE_FIELD); | ||
if ($bundle === static::ROOT_ACCESS) { | ||
return $this->jsonResponse([static::ROOT_ACCESS => static::ROOT_ACCESS]); | ||
} | ||
|
||
$choices = $this->getFactory()->getRouterFacade()->getRouterControllerCollection($bundle)->getControllers(); | ||
|
||
array_unshift($choices, static::ROOT_ACCESS); | ||
|
||
return $this->jsonResponse(array_combine($choices, $choices)); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* | ||
* @return \Symfony\Component\HttpFoundation\JsonResponse | ||
*/ | ||
public function actionChoicesAction(Request $request): JsonResponse | ||
{ | ||
$bundle = (string)$request->query->get(static::BUNDLE_FIELD); | ||
if ($bundle === static::ROOT_ACCESS) { | ||
return $this->jsonResponse(['error' => 'Please select a bundle first.'], 400); | ||
} | ||
|
||
$controller = (string)$request->query->get(static::CONTROLLER_FIELD); | ||
|
||
if ($controller === static::ROOT_ACCESS) { | ||
return $this->jsonResponse([static::ROOT_ACCESS => static::ROOT_ACCESS]); | ||
} | ||
|
||
$choices = $this->getFactory() | ||
->getRouterFacade() | ||
->getRouterActionCollection($bundle, $controller) | ||
->getActions(); | ||
|
||
array_unshift($choices, static::ROOT_ACCESS); | ||
|
||
return $this->jsonResponse(array_combine($choices, $choices)); | ||
} | ||
} |
Oops, something went wrong.