From 2dd2fb95ac642252201f7ace02814aac606b1da6 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Mon, 2 Dec 2013 21:34:53 +0000 Subject: [PATCH] AC-697 Dynamic help on Permissions page based on Permission Type. Uses a help collapse. Added ngBind support to help collapse, allowing the controller to set a scope variable to an html string. Added a Permissions.js helper to share setting help text and other defaults whenever permission type changes. --- awx/ui/static/js/app.js | 1 + awx/ui/static/js/controllers/Permissions.js | 53 ++++++++----------- awx/ui/static/js/forms/Permissions.js | 16 ++---- awx/ui/static/js/helpers/Permissions.js | 48 +++++++++++++++++ awx/ui/static/lib/ansible/form-generator.js | 9 +++- .../static/lib/ansible/generator-helpers.js | 7 ++- awx/ui/templates/ui/index.html | 1 + 7 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 awx/ui/static/js/helpers/Permissions.js diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 0df2aa7337..e905f7b6c2 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -53,6 +53,7 @@ angular.module('ansible', [ 'ProjectsHelper', 'PermissionFormDefinition', 'PermissionListDefinition', + 'PermissionsHelper', 'JobsListDefinition', 'JobFormDefinition', 'JobEventsListDefinition', diff --git a/awx/ui/static/js/controllers/Permissions.js b/awx/ui/static/js/controllers/Permissions.js index 2e4ed0e3b1..d326f2f449 100644 --- a/awx/ui/static/js/controllers/Permissions.js +++ b/awx/ui/static/js/controllers/Permissions.js @@ -77,7 +77,7 @@ PermissionsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$route function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, PermissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath, ReturnToCaller, InventoryList, ProjectList, LookUpInit, CheckAccess, - Wait) + Wait, PermissionCategoryChange) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -100,8 +100,8 @@ function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routePa scope.category = 'Inventory'; master.category = 'Inventory'; master.inventoryrequired = true; - master.projectrequired = false - + master.projectrequired = false; + LookUpInit({ scope: scope, form: form, @@ -152,29 +152,27 @@ function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routePa for (var fld in master) { scope[fld] = master[fld]; } + scope.selectCategory(); }; + + scope.selectCategory = function() { PermissionCategoryChange({ scope: scope, reset: true }); }; + + + scope.selectCategory(); - scope.selectCategory = function() { - if (scope.category == 'Inventory') { - scope.projectrequired = false; - } - else { - scope.projectrequired = true; - } - scope.permission_type = null; - } } PermissionsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'PermissionsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', - 'ReturnToCaller', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', 'Wait' + 'ReturnToCaller', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', 'Wait', + 'PermissionCategoryChange' ]; function PermissionsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, PermissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, Prompt, GetBasePath, InventoryList, ProjectList, LookUpInit, CheckAccess, - Wait) + Wait, PermissionCategoryChange) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -191,7 +189,11 @@ function PermissionsEdit ($scope, $rootScope, $compile, $location, $log, $routeP var master = {}; var relatedSets = {}; - CheckAccess({ scope: scope }) + CheckAccess({ scope: scope }); + + scope.selectCategory = function(resetIn) { + var reset = (resetIn == false) ? false : true; + PermissionCategoryChange({ scope: scope, reset: reset }); } // Retrieve detail record and prepopulate the form Rest.setUrl(defaultUrl); @@ -216,13 +218,10 @@ function PermissionsEdit ($scope, $rootScope, $compile, $location, $log, $routeP scope.category = 'Deploy'; if (data['permission_type'] != 'run' && data['permission_type'] != 'check' ) { scope.category = 'Inventory'; - scope.projectrequired = false; - } - else { - scope.projectrequired = true; } master['category'] = scope.category; - + scope.selectCategory(false); //call without resetting scope.category value + LookUpInit({ scope: scope, form: form, @@ -287,24 +286,14 @@ function PermissionsEdit ($scope, $rootScope, $compile, $location, $log, $routeP for (var fld in master) { scope[fld] = master[fld]; } + scope.selectCategory(false); }; - - scope.selectCategory = function() { - if (scope.category == 'Inventory') { - scope.projectrequired = false; - } - else { - scope.projectrequired = true; - } - scope.permission_type = null; - } - } PermissionsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'PermissionsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'Prompt', 'GetBasePath', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', - 'Wait' + 'Wait', 'PermissionCategoryChange' ]; diff --git a/awx/ui/static/js/forms/Permissions.js b/awx/ui/static/js/forms/Permissions.js index 0e98a6543d..e044d73724 100644 --- a/awx/ui/static/js/forms/Permissions.js +++ b/awx/ui/static/js/forms/Permissions.js @@ -14,7 +14,8 @@ angular.module('PermissionFormDefinition', []) addTitle: 'Add Permission', //Title in add mode editTitle: '{{ name }}', //Title in edit mode name: 'permission', //entity or model name in singular form - well: true, //Wrap the form with TB well/ + well: true, //Wrap the form with TB well + forceListeners: true, stream: { 'class': "btn-primary btn-xs activity-btn", @@ -83,18 +84,9 @@ angular.module('PermissionFormDefinition', []) {label: 'Check', value: 'check', ngShow: "category == 'Deploy'" } ], addRequired: true, - editRequired: true + editRequired: true, + helpCollapse: [{ hdr: 'Permission', ngBind: 'permissionTypeHelp' }] } - /* , - deployment_permission_type: { - label: 'Permission', - type: 'radio', - ngShow: "category == 'Deploy'", - options: [ - {label: 'Deploy', value: 'PERM_INVENTORY_DEPLOY'}, - {label: 'Check', value: 'PERM_INVENTORY_CHECK'} - ] - }*/ }, buttons: { //for now always generates