diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 99dc4f6f99..a7a437ef11 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -209,9 +209,10 @@ function($injector, $stateExtender, $log, i18n) { FormDefinition: [params.form, function(definition) { return definition; }], - resourceData: ['FormDefinition', 'Rest', '$stateParams', 'GetBasePath', - function(FormDefinition, Rest, $stateParams, GetBasePath) { + resourceData: ['FormDefinition', 'Rest', '$stateParams', 'GetBasePath', '$q', 'ProcessErrors', + function(FormDefinition, Rest, $stateParams, GetBasePath, $q, ProcessErrors) { let form, path; + let deferred = $q.defer(); form = typeof(FormDefinition) === 'function' ? FormDefinition() : FormDefinition; if (GetBasePath(form.basePath) === undefined && GetBasePath(form.stateTree) === undefined ){ @@ -221,7 +222,18 @@ function($injector, $stateExtender, $log, i18n) { path = (GetBasePath(form.basePath) || GetBasePath(form.stateTree) || form.basePath) + $stateParams[`${form.name}_id`]; } Rest.setUrl(path); - return Rest.get(); + Rest.get() + .then((response) => deferred.resolve(response)) + .catch(({ data, status }) => { + ProcessErrors(null, data, status, null, + { + hdr: i18n._('Error!'), + msg: i18n._('Unable to get resource: ') + status + } + ); + deferred.reject(); + }); + return deferred.promise; } ] }, diff --git a/awx/ui/client/src/teams/edit/teams-edit.controller.js b/awx/ui/client/src/teams/edit/teams-edit.controller.js index 41a37b19cb..dc9beea14d 100644 --- a/awx/ui/client/src/teams/edit/teams-edit.controller.js +++ b/awx/ui/client/src/teams/edit/teams-edit.controller.js @@ -5,14 +5,15 @@ *************************************************/ export default ['$scope', '$rootScope', '$stateParams', 'TeamForm', 'Rest', - 'ProcessErrors', 'GetBasePath', 'Wait', '$state', 'OrgAdminLookup', 'resolvedModels', + 'ProcessErrors', 'GetBasePath', 'Wait', '$state', 'OrgAdminLookup', 'resolvedModels', 'resourceData', function($scope, $rootScope, $stateParams, TeamForm, Rest, ProcessErrors, - GetBasePath, Wait, $state, OrgAdminLookup, models) { + GetBasePath, Wait, $state, OrgAdminLookup, models, Dataset) { const { me } = models; - var form = TeamForm, - id = $stateParams.team_id, - defaultUrl = GetBasePath('teams') + id; + const { data } = Dataset; + const id = $stateParams.team_id; + const defaultUrl = GetBasePath('teams') + id; + let form = TeamForm; init(); @@ -20,26 +21,19 @@ export default ['$scope', '$rootScope', '$stateParams', 'TeamForm', 'Rest', $scope.canEdit = me.get('summary_fields.user_capabilities.edit'); $scope.isOrgAdmin = me.get('related.admin_of_organizations.count') > 0; $scope.team_id = id; - Rest.setUrl(defaultUrl); - Wait('start'); - Rest.get(defaultUrl).then(({data}) => { - setScopeFields(data); - $scope.organization_name = data.summary_fields.organization.name; + setScopeFields(data); + $scope.organization_name = data.summary_fields.organization.name; - OrgAdminLookup.checkForAdminAccess({organization: data.organization}) + OrgAdminLookup.checkForAdminAccess({organization: data.organization}) .then(function(canEditOrg){ $scope.canEditOrg = canEditOrg; }); - $scope.team_obj = data; - Wait('stop'); - }); + $scope.team_obj = data; $scope.$watch('team_obj.summary_fields.user_capabilities.edit', function(val) { $scope.canAdd = (val === false) ? false : true; }); - - } // @issue I think all this really want to do is _.forEach(form.fields, (field) =>{ $scope[field] = data[field]})