diff --git a/awx/ui/static/js/controllers/Permissions.js b/awx/ui/static/js/controllers/Permissions.js index edfd176a2c..ed6dbaed46 100644 --- a/awx/ui/static/js/controllers/Permissions.js +++ b/awx/ui/static/js/controllers/Permissions.js @@ -136,6 +136,7 @@ export function PermissionsAdd($scope, $rootScope, $compile, $location, $log, $r master.category = 'Inventory'; master.inventoryrequired = true; master.projectrequired = false; + $scope.run_ad_hoc_commands = false; LookUpInit({ scope: $scope, @@ -155,6 +156,22 @@ export function PermissionsAdd($scope, $rootScope, $compile, $location, $log, $r input_type: 'radio' }); + $scope.changeAdhocCommandCheckbox = function () { + if ($scope.category === 'Deploy') { + $scope.run_ad_hoc_command = false; + } else { + if ($scope.permission_type === 'admin') { + $scope.run_ad_hoc_commands = true; + $("#permission_run_ad_hoc_commands_chbox").attr("disabled", true); + } else { + if (!$scope.run_ad_hoc_commands) { + $scope.run_ad_hoc_commands = false; + } + $("#permission_run_ad_hoc_commands_chbox").attr("disabled", false); + } + } + } + // Save $scope.formSave = function () { var fld, url, data = {}; @@ -226,12 +243,25 @@ export function PermissionsEdit($scope, $rootScope, $compile, $location, $log, $ defaultUrl = GetBasePath('base') + 'permissions/' + id + '/', master = {}; + $scope.changeAdhocCommandCheckbox = function () { + if ($scope.category === 'Deploy') { + $scope.run_ad_hoc_command = false; + } else { + if ($scope.permission_type === 'admin') { + $scope.run_ad_hoc_commands = true; + $("#permission_run_ad_hoc_commands_chbox").attr("disabled", true); + } else { + if (!$scope.run_ad_hoc_commands) { + $scope.run_ad_hoc_commands = false; + } + $("#permission_run_ad_hoc_commands_chbox").attr("disabled", false); + } + } + } + generator.inject(form, { mode: 'edit', related: true, scope: $scope }); generator.reset(); - - - $scope.selectCategory = function (resetIn) { var reset = (resetIn === false) ? false : true; PermissionCategoryChange({ scope: $scope, reset: reset }); @@ -285,6 +315,8 @@ export function PermissionsEdit($scope, $rootScope, $compile, $location, $log, $ input_type: 'radio' }); + $scope.changeAdhocCommandCheckbox(); + if (!$scope.PermissionAddAllowed) { // If not a privileged user, disable access $('form[name="permission_form"]').find('select, input, button').each(function () { diff --git a/awx/ui/static/js/forms/Permissions.js b/awx/ui/static/js/forms/Permissions.js index 2974b05353..274ab2285a 100644 --- a/awx/ui/static/js/forms/Permissions.js +++ b/awx/ui/static/js/forms/Permissions.js @@ -97,6 +97,7 @@ export default labelClass: 'prepend-asterisk', type: 'radio_group', class: 'squeeze', + ngChange: 'changeAdhocCommandCheckbox()', options: [{ label: 'Read', value: 'read', diff --git a/awx/ui/static/js/shared/form-generator.js b/awx/ui/static/js/shared/form-generator.js index 9956f610f4..c203c2224a 100644 --- a/awx/ui/static/js/shared/form-generator.js +++ b/awx/ui/static/js/shared/form-generator.js @@ -671,10 +671,6 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat html += Attr(field, 'type'); html += "ng-model=\"" + fld + '" '; html += "name=\"" + fld + '" '; - if (form.name === "permission") { - html += "ng-disabled='permission_type === \"admin\"'"; - html += "ng-checked='permission_type === \"admin\"'"; - } html += (field.ngChange) ? Attr(field, 'ngChange') : ""; html += "id=\"" + form.name + "_" + fld + "_chbox\" "; html += (idx !== undefined) ? "_" + idx : "";