From 284c9473476c7c6c06d42cace1ac3fd862944180 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 16 Apr 2014 18:13:09 -0400 Subject: [PATCH] AC-1185 fixed page rendering issues related to html-unsafe. Fixed search helper. Finished new inventory group delete functionality. --- awx/ui/static/js/helpers/Groups.js | 91 ++++++++++++++++++------- awx/ui/static/js/helpers/Permissions.js | 15 ++-- awx/ui/static/js/helpers/search.js | 2 +- 3 files changed, 77 insertions(+), 31 deletions(-) diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index 1779eb8045..acba13de3a 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -1268,13 +1268,11 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched } ]) - .factory('GroupsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm', 'Prompt', 'ProcessErrors', 'GetBasePath', 'Wait', 'BuildTree', 'Find', 'CreateDialog', function ($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors, GetBasePath, Wait, BuildTree, Find, CreateDialog) { return function (params) { - // Delete the selected group node. Disassociates it from its parent. var scope = params.scope, tree_id = params.tree_id, @@ -1284,26 +1282,6 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched childCount = 0, buttonSet; - // action_to_take = function () { - // $('#prompt-modal').on('hidden.bs.modal', function () { - // Wait('start'); - // }); - // $('#prompt-modal').modal('hide'); - // Rest.setUrl(url); - // Rest.post({ id: node.group_id, disassociate: 1 }) - // .success(function () { - // $('#prompt-modal').modal('hide'); - // scope.$emit('GroupDeleteCompleted'); // Signal a group refresh to start - // }) - // .error(function (data, status) { - // Wait('stop'); - // ProcessErrors(scope, data, status, null, { - // hdr: 'Error!', - // msg: 'Call to ' + url + ' failed. POST returned status: ' + status - // }); - // }); - // }; - scope.deleteOption = "preserve-all"; buttonSet = [{ @@ -1409,15 +1387,82 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched $('#group-delete-dialog').dialog('close'); }; + if (scope.removeChildDeleteFinished) { + scope.removeChildDeleteFinished(); + } + scope.removeChildDeleteFinished = scope.$on('ChildDeleteFinished', function() { + var url = GetBasePath('inventory') + scope.inventory_id + '/groups/'; + Rest.setUrl(url); + Rest.post({ id: node.group_id, disassociate: 1 }) + .success(function () { + scope.$emit('GroupDeleteCompleted'); // Signal a group refresh to start + }) + .error(function (data, status) { + ProcessErrors(scope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + ' failed. POST returned: ' + status + }); + }); + }); + + if (scope.removeDeleteNextGroup) { + scope.removeDeleteNextGroup(); + } + scope.removeDeleteNextGroup = scope.$on('DeleteNextGroup', function() { + var group; + if (groups && groups.length > 0) { + group = groups.pop(); + Rest.setUrl(GetBasePath('group') + group.group_id + '/'); + Rest.destroy() + .success(function() { + scope.$emit('DeleteNextGroup'); + }) + .error( function(data, status) { + $log.error('Failed to delete group ' + group.group_id + '. Status: ' + status); + scope.$emit('DeleteNextGroup'); + }); + } + else { + scope.$emit('ChildDeleteFinished'); + } + }); + + if (scope.removeDeleteNextHost) { + scope.removeDeleteNextHost(); + } + scope.removeDeleteNextHost = scope.$on('DeleteNextHost', function() { + var host; + if (hosts && hosts.length > 0) { + host = hosts.pop(); + Rest.setUrl(GetBasePath('hosts') + host.id + '/'); + Rest.destroy() + .success(function() { + scope.$emit('DeleteNextHost'); + }) + .error( function(data, status) { + $log.error('Failed to delete host ' + host.id + '. Status: ' + status); + scope.$emit('DeleteNextHost'); + }); + } + else { + scope.$emit('DeleteNextGroup'); + } + }); + scope.performDelete = function() { $('#group-delete-dialog').dialog('close'); + Wait('start'); + if (scope.deleteOption === 'delete-all') { + scope.$emit('DeleteNextHost'); + } + else { + scope.$emit('ChildDeleteFinished'); + } }; }; } ]) - .factory('ShowUpdateStatus', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm', 'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'InventoryStatusForm', 'Wait', 'Empty', 'WatchInventoryWindowResize', function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath, diff --git a/awx/ui/static/js/helpers/Permissions.js b/awx/ui/static/js/helpers/Permissions.js index 08b6b0f22b..b98e73fd19 100644 --- a/awx/ui/static/js/helpers/Permissions.js +++ b/awx/ui/static/js/helpers/Permissions.js @@ -9,16 +9,16 @@ angular.module('PermissionsHelper', []) // Handle category change event -.factory('PermissionCategoryChange', [ - function () { +.factory('PermissionCategoryChange', ['$sce', + function ($sce) { return function (params) { var scope = params.scope, - reset = params.reset; + reset = params.reset, + html; if (scope.category === 'Inventory') { scope.projectrequired = false; - scope.permissionTypeHelp = - "
\n" + + html = "
\n" + "
Read
\n" + "
Only allow the user or team to view the inventory.
\n" + "
Write
\n" + @@ -26,10 +26,10 @@ angular.module('PermissionsHelper', []) "
Admin
\n" + "
Allow the user or team full access to the inventory. This includes reading, writing, deletion of the inventory and inventory sync operations.
\n" + "
\n"; + scope.permissionTypeHelp = $sce.trustAsHtml(html); } else { scope.projectrequired = true; - scope.permissionTypeHelp = - "
\n" + + html = "
\n" + "
Run
\n" + "
Allow the user or team to perform a live deployment of the project against the inventory. In Run mode modules will " + "be executed, and changes to the inventory will occur.
\n" + @@ -37,6 +37,7 @@ angular.module('PermissionsHelper', []) "
Only allow the user or team to deploy the project against the inventory as a dry-run operation. In Check mode, module operations " + "will only be simulated. No changes will occur.
\n" + "
\n"; + scope.permissionTypeHelp = $sce.trustAsHtml(html); } if (reset) { diff --git a/awx/ui/static/js/helpers/search.js b/awx/ui/static/js/helpers/search.js index 55c4aa43de..f0e5e29aa6 100644 --- a/awx/ui/static/js/helpers/search.js +++ b/awx/ui/static/js/helpers/search.js @@ -451,7 +451,7 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) */ scope.search = function (iterator, page, load, calcOnly) { page = page || null; - load = (load || !scope.set || scope.set.length === 0) ? true : false; + load = (load || !scope[set] || scope[set].length === 0) ? true : false; calcOnly = (calcOnly) ? true : false; if (load) { scope[set] = []; //clear the list array to make sure 'Loading' is the only thing visible on the list