From dd8f245f93c5eca5bb51d59918d9855f1961e281 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Wed, 10 May 2017 10:21:14 -0400 Subject: [PATCH] Fixed adhoc limit pattern when navigating from nested group to adhoc form --- .../nested-groups-list.controller.js | 92 ++++--------------- 1 file changed, 17 insertions(+), 75 deletions(-) diff --git a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js index 1bcf0824c6..f9681033be 100644 --- a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js +++ b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-list.controller.js @@ -43,6 +43,22 @@ $scope.inventory_id = $stateParams.inventory_id; _.forEach($scope[list.name], buildStatusIndicators); + $scope.$on('selectedOrDeselected', function(e, value) { + let item = value.value; + + if (value.isSelected) { + if(!$scope.groupsSelected) { + $scope.groupsSelected = []; + } + $scope.groupsSelected.push(item); + } else { + _.remove($scope.groupsSelected, { id: item.id }); + if($scope.groupsSelected.length === 0) { + $scope.groupsSelected = null; + } + } + }); + } function buildStatusIndicators(group){ @@ -66,84 +82,10 @@ $scope.createGroup = function(){ $state.go('inventories.edit.groups.edit.nested_groups.add'); }; + $scope.editGroup = function(id){ $state.go('inventories.edit.groups.edit', {group_id: id}); }; - // $scope.editGroup = function(id){ - // $state.go('inventories.edit.groups.edit.nested_groups.edit', {nested_group_id: id}); - // }; - $scope.deleteGroup = function(group){ - $scope.toDelete = {}; - angular.extend($scope.toDelete, group); - if($scope.toDelete.total_groups === 0 && $scope.toDelete.total_hosts === 0) { - // This group doesn't have any child groups or hosts - the user is just trying to delete - // the group - $scope.deleteOption = "delete"; - } - $('#group-delete-modal').modal('show'); - }; - $scope.confirmDelete = function(){ - - // Bind an even listener for the modal closing. Trying to $state.go() before the modal closes - // will mean that these two things are running async and the modal may not finish closing before - // the state finishes transitioning. - $('#group-delete-modal').off('hidden.bs.modal').on('hidden.bs.modal', function () { - // Remove the event handler so that we don't end up with multiple bindings - $('#group-delete-modal').off('hidden.bs.modal'); - // Reload the inventory manage page and show that the group has been removed - $state.go('.', null, {reload: true}); - }); - - switch($scope.deleteOption){ - case 'promote': - GroupManageService.promote($scope.toDelete.id, $stateParams.inventory_id) - .then(() => { - if (parseInt($state.params.group_id) === $scope.toDelete.id) { - $state.go("^", null, {reload: true}); - } else { - $state.go($state.current, null, {reload: true}); - } - $('#group-delete-modal').modal('hide'); - $('body').removeClass('modal-open'); - $('.modal-backdrop').remove(); - }); - break; - default: - GroupManageService.delete($scope.toDelete.id).then(() => { - if (parseInt($state.params.group_id) === $scope.toDelete.id) { - $state.go("^", null, {reload: true}); - } else { - $state.go($state.current, null, {reload: true}); - } - $('#group-delete-modal').modal('hide'); - $('body').removeClass('modal-open'); - $('.modal-backdrop').remove(); - }); - } - }; - $scope.updateGroup = function(group) { - GroupManageService.getInventorySource({group: group.id}).then(res =>InventoryUpdate({ - scope: $scope, - group_id: group.id, - url: res.data.results[0].related.update, - group_name: group.name, - group_source: res.data.results[0].source - })); - }; - - $scope.cancelUpdate = function (id) { - CancelSourceUpdate({ scope: $scope, id: id }); - }; - - // $scope.$parent governed by InventoryManageController, for unified multiSelect options - $scope.$on('multiSelectList.selectionChanged', (event, selection) => { - $scope.$parent.groupsSelected = selection.length > 0 ? true : false; - $scope.$parent.groupsSelectedItems = selection.selectedItems; - }); - - $scope.copyMoveGroup = function(){ - // TODO: implement - }; var cleanUpStateChangeListener = $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams) { if (toState.name === "inventories.edit.groups.edit.nested_groups.edit") {