From 8dafc105414234877e99df78e60f513b0e8d9050 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Thu, 21 Nov 2013 21:13:31 +0000 Subject: [PATCH] AC-715 Fixed issues with bad API requests when user types in value and lookup is built with predetermined search parameters. Fixed project lookup failure while user is typing. --- awx/ui/static/js/controllers/JobTemplates.js | 66 ++++++++++---------- awx/ui/static/js/helpers/Lookup.js | 6 +- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index e279c69a3a..0df423fd4f 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -95,7 +95,7 @@ JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$rout function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, - md5Setup, ParseTypeChange, Wait) + md5Setup, ParseTypeChange, Wait, Empty) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -187,7 +187,7 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP // Detect and alert user to potential SCM status issues var checkSCMStatus = function(oldValue, newValue) { - if (oldValue !== newValue) { + if (oldValue !== newValue && !Empty(scope.project)) { Rest.setUrl(GetBasePath('projects') + scope.project + '/'); Rest.get() .success( function(data, status, headers, config) { @@ -304,14 +304,14 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', - 'md5Setup', 'ParseTypeChange', 'Wait']; + 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty' ]; function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList, ProjectList, LookUpInit, PromptPasswords, GetBasePath, md5Setup, ParseTypeChange, - JobStatusToolTip, FormatDate, Wait, Stream) + JobStatusToolTip, FormatDate, Wait, Stream, Empty) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -366,34 +366,36 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route // Detect and alert user to potential SCM status issues var checkSCMStatus = function() { - Rest.setUrl(GetBasePath('projects') + scope.project + '/'); - Rest.get() - .success( function(data, status, headers, config) { - var msg; - switch(data.status) { - case 'failed': - msg = "The selected project has a failed status. Review the project's SCM settings" + - " and run an update before adding it to a template."; - break; - case 'never updated': - msg = 'The selected project has a never updated status. You will need to run a successful' + - ' update in order to selected a playbook. Without a valid playbook you will not be able ' + - ' to save this template.'; - break; - case 'missing': - msg = 'The selected project has a status of missing. Please check the server and make sure ' + - ' the directory exists and file permissions are set correctly.'; - break; - } + if (!Empty(scope.project)) { + Rest.setUrl(GetBasePath('projects') + scope.project + '/'); + Rest.get() + .success( function(data, status, headers, config) { + var msg; + switch(data.status) { + case 'failed': + msg = "The selected project has a failed status. Review the project's SCM settings" + + " and run an update before adding it to a template."; + break; + case 'never updated': + msg = 'The selected project has a never updated status. You will need to run a successful' + + ' update in order to selected a playbook. Without a valid playbook you will not be able ' + + ' to save this template.'; + break; + case 'missing': + msg = 'The selected project has a status of missing. Please check the server and make sure ' + + ' the directory exists and file permissions are set correctly.'; + break; + } - if (msg) { - Alert('Waning', msg, 'alert-info'); - } - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, form, - { hdr: 'Error!', msg: 'Failed to get project ' + scope.project +'. GET returned status: ' + status }); - }); + if (msg) { + Alert('Waning', msg, 'alert-info'); + } + }) + .error( function(data, status, headers, config) { + ProcessErrors(scope, data, status, form, + { hdr: 'Error!', msg: 'Failed to get project ' + scope.project +'. GET returned status: ' + status }); + }); + } } @@ -683,5 +685,5 @@ JobTemplatesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$ 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup', 'ParseTypeChange', - 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream' + 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty' ]; diff --git a/awx/ui/static/js/helpers/Lookup.js b/awx/ui/static/js/helpers/Lookup.js index d32c2f88cf..1444ec40e2 100644 --- a/awx/ui/static/js/helpers/Lookup.js +++ b/awx/ui/static/js/helpers/Lookup.js @@ -38,8 +38,10 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P var name = list.iterator.charAt(0).toUpperCase() + list.iterator.substring(1); var hdr = (params.hdr) ? params.hdr : 'Select ' + name; - $('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-url',defaultUrl + - '?' + form.fields[field].sourceField + '__' + 'iexact=:value'); + var watchUrl = (/\/$/.test(defaultUrl)) ? defaultUrl + '?' : defaultUrl + '&'; + watchUrl += form.fields[field].sourceField + '__' + 'iexact=:value'; + + $('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-url', watchUrl); $('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-source',field); scope['lookUp' + name] = function() {