From f8e4fdf2011d84d09dd10b329073d5e0869a269d Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 23 Oct 2015 12:23:37 -0700 Subject: [PATCH] change async loading order for form --- awx/ui/client/src/controllers/Teams.js | 113 +++++++++++++------------ awx/ui/client/src/controllers/Users.js | 101 ++++++++++++---------- 2 files changed, 114 insertions(+), 100 deletions(-) diff --git a/awx/ui/client/src/controllers/Teams.js b/awx/ui/client/src/controllers/Teams.js index 6fe42bc955..1cc8408bd1 100644 --- a/awx/ui/client/src/controllers/Teams.js +++ b/awx/ui/client/src/controllers/Teams.js @@ -210,8 +210,6 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP }); }); - $scope.team_id = id; - // manipulate the choices from the options request to be usable // by the search option for permission_type, you can't inject the // list until this is done! @@ -222,8 +220,11 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP }); generator.inject(form, { mode: 'edit', related: true, scope: $scope }); generator.reset(); + $scope.$emit('loadTeam'); }); + $scope.team_id = id; + $scope.PermissionAddAllowed = false; // Retrieve each related set and any lookups @@ -254,59 +255,65 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP } }); - // Retrieve detail record and prepopulate the form - Wait('start'); - Rest.setUrl(defaultUrl + ':id/'); - Rest.get({ - params: { - id: id - } - }) - .success(function (data) { - var fld, related, set; - $scope.team_name = data.name; - for (fld in form.fields) { - if (data[fld]) { - $scope[fld] = data[fld]; - master[fld] = $scope[fld]; - } + // Retrieve each related set and any lookups + if ($scope.loadTeamRemove) { + $scope.loadTeamRemove(); + } + $scope.loadTeamRemove = $scope.$on('loadTeam', function () { + // Retrieve detail record and prepopulate the form + Wait('start'); + Rest.setUrl(defaultUrl + ':id/'); + Rest.get({ + params: { + id: id } - related = data.related; - for (set in form.related) { - if (related[set]) { - relatedSets[set] = { - url: related[set], - iterator: form.related[set].iterator - }; - } - } - // Initialize related search functions. Doing it here to make sure relatedSets object is populated. - RelatedSearchInit({ - scope: $scope, - form: form, - relatedSets: relatedSets - }); - RelatedPaginateInit({ - scope: $scope, - relatedSets: relatedSets - }); - - LookUpInit({ - scope: $scope, - form: form, - current_item: data.organization, - list: OrganizationList, - field: 'organization', - input_type: 'radio' - }); - - $scope.organization_url = data.related.organization; - $scope.$emit('teamLoaded'); }) - .error(function (data, status) { - ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to retrieve team: ' + $routeParams.team_id + - '. GET status: ' + status }); - }); + .success(function (data) { + var fld, related, set; + $scope.team_name = data.name; + for (fld in form.fields) { + if (data[fld]) { + $scope[fld] = data[fld]; + master[fld] = $scope[fld]; + } + } + related = data.related; + for (set in form.related) { + if (related[set]) { + relatedSets[set] = { + url: related[set], + iterator: form.related[set].iterator + }; + } + } + // Initialize related search functions. Doing it here to make sure relatedSets object is populated. + RelatedSearchInit({ + scope: $scope, + form: form, + relatedSets: relatedSets + }); + RelatedPaginateInit({ + scope: $scope, + relatedSets: relatedSets + }); + + LookUpInit({ + scope: $scope, + form: form, + current_item: data.organization, + list: OrganizationList, + field: 'organization', + input_type: 'radio' + }); + + $scope.organization_url = data.related.organization; + $scope.$emit('teamLoaded'); + }) + .error(function (data, status) { + ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to retrieve team: ' + $routeParams.team_id + + '. GET status: ' + status }); + }); + }); $scope.getPermissionText = function () { if (this.permission.permission_type !== "admin" && this.permission.run_ad_hoc_commands) { diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index 3aa0b98662..9cd0d2d161 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -242,22 +242,23 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP }); }); + // manipulate the choices from the options request to be usable + // by the search option for permission_type, you can't inject the + // list until this is done! + permissionsChoice.then(function (choices) { + form.related.permissions.fields.permission_type.searchOptions = + permissionsSearchSelect({ + choices: choices + }); + generator.inject(form, { mode: 'edit', related: true, scope: $scope }); + generator.reset(); + $scope.$emit("loadForm"); + }); + if ($scope.removeFormReady) { $scope.removeFormReady(); } $scope.removeFormReady = $scope.$on('formReady', function () { - // manipulate the choices from the options request to be usable - // by the search option for permission_type, you can't inject the - // list until this is done! - permissionsChoice.then(function (choices) { - form.related.permissions.fields.permission_type.searchOptions = - permissionsSearchSelect({ - choices: choices - }); - generator.inject(form, { mode: 'edit', related: true, scope: $scope }); - generator.reset(); - }); - if ($scope.removePostRefresh) { $scope.removePostRefresh(); } @@ -471,51 +472,57 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP // Put form back to its original state ResetForm(); - - if ($scope.removeModifyForm) { - $scope.removeModifyForm(); + if ($scope.removeLoadForm) { + $scope.removeLoadForm(); } - $scope.removeModifyForm = $scope.$on('modifyForm', function () { - // Modify form based on LDAP settings - Rest.setUrl(GetBasePath('config')); - Rest.get() - .success(function (data) { - var i, fld; - if (data.user_ldap_fields) { - for (i = 0; i < data.user_ldap_fields.length; i++) { - fld = data.user_ldap_fields[i]; - if (form.fields[fld]) { - form.fields[fld].readonly = true; - form.fields[fld].editRequired = false; - if (form.fields[fld].awRequiredWhen) { - delete form.fields[fld].awRequiredWhen; + $scope.removeLoadForm = $scope.$on('loadForm', function () { + + + if ($scope.removeModifyForm) { + $scope.removeModifyForm(); + } + $scope.removeModifyForm = $scope.$on('modifyForm', function () { + // Modify form based on LDAP settings + Rest.setUrl(GetBasePath('config')); + Rest.get() + .success(function (data) { + var i, fld; + if (data.user_ldap_fields) { + for (i = 0; i < data.user_ldap_fields.length; i++) { + fld = data.user_ldap_fields[i]; + if (form.fields[fld]) { + form.fields[fld].readonly = true; + form.fields[fld].editRequired = false; + if (form.fields[fld].awRequiredWhen) { + delete form.fields[fld].awRequiredWhen; + } } } } + $scope.$emit('formReady'); + }) + .error(function (data, status) { + ProcessErrors($scope, data, status, null, { hdr: 'Error!', + msg: 'Failed to retrieve application config. GET status: ' + status }); + }); + }); + + Wait('start'); + Rest.setUrl(defaultUrl + id + '/'); + Rest.get() + .success(function (data) { + if (data.ldap_dn !== null && data.ldap_dn !== undefined && data.ldap_dn !== '') { + //this is an LDAP user + $scope.$emit('modifyForm'); + } else { + $scope.$emit('formReady'); } - $scope.$emit('formReady'); }) .error(function (data, status) { ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to retrieve application config. GET status: ' + status }); + msg: 'Failed to retrieve user: ' + id + '. GET status: ' + status }); }); }); - - Wait('start'); - Rest.setUrl(defaultUrl + id + '/'); - Rest.get() - .success(function (data) { - if (data.ldap_dn !== null && data.ldap_dn !== undefined && data.ldap_dn !== '') { - //this is an LDAP user - $scope.$emit('modifyForm'); - } else { - $scope.$emit('formReady'); - } - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to retrieve user: ' + id + '. GET status: ' + status }); - }); } UsersEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',