From 8ffc6870c3a69b914d47e0b03382c5a53c32bc8e Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Tue, 23 Jul 2013 11:41:44 -0400 Subject: [PATCH] AC-221 No longer refreshing the tree after a group edit. Just refreshing the modified node's title. Also, changed Inventory save (on edit) to stay on page, update tree inventory node title and flash a 'success' message. Makes much more sense. --- awx/ui/static/js/controllers/Inventories.js | 25 +++++++++++++++++---- awx/ui/static/js/helpers/Groups.js | 8 +++---- awx/ui/static/js/helpers/inventory.js | 7 ++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index fdcf220b79..cfb208ac23 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -184,7 +184,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt, OrganizationList, TreeInit, GetBasePath, GroupsList, GroupsAdd, GroupsEdit, LoadInventory, - GroupsDelete, HostsList, HostsAdd, HostsEdit, HostsDelete, RefreshTree, ParseTypeChange) + GroupsDelete, HostsList, HostsAdd, HostsEdit, HostsDelete, RefreshGroupName, ParseTypeChange) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -247,6 +247,23 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP RefreshTree({ scope: scope }); } + function PostSave() { + // Make sure the inventory name in the tree is correct + RefreshGroupName($('#inventory-node'), scope['inventory_name'], scope['inventory_description']); + + // Reset the form to disable the form action buttons + scope[form.name + '_form'].$setPristine(); + + // Show the flash message for 5 seconds, letting the user know the save worked + scope['flashMessage'] = 'Your changes were successfully saved!'; + setTimeout(function() { + scope['flashMessage'] = null; + if (!scope.$$phase) { + scope.$digest(); + } + }, 5000); + } + // Save scope.formSave = function() { try { @@ -282,7 +299,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP Rest.setUrl(data.related.variable_data); Rest.put(json_data) .success( function(data, status, headers, config) { - $location.path('/inventories'); + PostSave(); }) .error( function(data, status, headers, config) { ProcessErrors(scope, data, status, form, @@ -290,7 +307,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP }); } else { - $location.path('/inventories'); + PostSave(); } }) .error( function(data, status, headers, config) { @@ -471,7 +488,7 @@ InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$l 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt', 'OrganizationList', 'TreeInit', 'GetBasePath', 'GroupsList', 'GroupsAdd', 'GroupsEdit', 'LoadInventory', - 'GroupsDelete', 'HostsList', 'HostsAdd', 'HostsEdit', 'HostsDelete', 'RefreshTree', + 'GroupsDelete', 'HostsList', 'HostsAdd', 'HostsEdit', 'HostsDelete', 'RefreshGroupName', 'ParseTypeChange' ]; diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index 157f04fd6a..bc9320a1b6 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -180,9 +180,9 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' .factory('GroupsEdit', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm', - 'Prompt', 'ProcessErrors', 'GetBasePath', 'RefreshTree', 'ParseTypeChange', + 'Prompt', 'ProcessErrors', 'GetBasePath', 'RefreshGroupName', 'ParseTypeChange', function($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors, - GetBasePath, RefreshTree, ParseTypeChange) { + GetBasePath, RefreshGroupName, ParseTypeChange) { return function(params) { var group_id = params.group_id; @@ -293,7 +293,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' Rest.put(json_data) .success( function(data, status, headers, config) { $('#form-modal').modal('hide'); - RefreshTree({ scope: scope }); + RefreshGroupName($('li[group_id="' + group_id + '"]'), scope['name']) }) .error( function(data, status, headers, config) { ProcessErrors(scope, data, status, form, @@ -302,7 +302,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' } else { $('#form-modal').modal('hide'); - RefreshTree({ scope: scope }); + RefreshGroupName($('li[group_id="' + group_id + '"]'), scope['name']); } }) .error( function(data, status, headers, config) { diff --git a/awx/ui/static/js/helpers/inventory.js b/awx/ui/static/js/helpers/inventory.js index b234edda3d..1d61498d0f 100644 --- a/awx/ui/static/js/helpers/inventory.js +++ b/awx/ui/static/js/helpers/inventory.js @@ -243,6 +243,13 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi } }]) + .factory('RefreshGroupName', [ function() { + return function(node, name, description) { + // Call after GroupsEdit controller saves changes + $('#tree-view').jstree('rename_node', node, name); + node.attr('description', description); + } + }]) .factory('RefreshTree', ['Alert', 'Rest', 'Authorization', '$http', 'TreeInit', 'LoadInventory', function(Alert, Rest, Authorization, $http, TreeInit, LoadInventory) {