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.

This commit is contained in:
Chris Houseknecht
2013-11-21 21:13:31 +00:00
parent a0fd9c5f18
commit 8dafc10541
2 changed files with 38 additions and 34 deletions

View File

@@ -95,7 +95,7 @@ JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$rout
function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, 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 ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope. //scope.
@@ -187,7 +187,7 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
// Detect and alert user to potential SCM status issues // Detect and alert user to potential SCM status issues
var checkSCMStatus = function(oldValue, newValue) { var checkSCMStatus = function(oldValue, newValue) {
if (oldValue !== newValue) { if (oldValue !== newValue && !Empty(scope.project)) {
Rest.setUrl(GetBasePath('projects') + scope.project + '/'); Rest.setUrl(GetBasePath('projects') + scope.project + '/');
Rest.get() Rest.get()
.success( function(data, status, headers, config) { .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', JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope',
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit',
'md5Setup', 'ParseTypeChange', 'Wait']; 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty' ];
function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList,
ProjectList, LookUpInit, PromptPasswords, GetBasePath, md5Setup, ParseTypeChange, 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 ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope. //scope.
@@ -366,6 +366,7 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
// Detect and alert user to potential SCM status issues // Detect and alert user to potential SCM status issues
var checkSCMStatus = function() { var checkSCMStatus = function() {
if (!Empty(scope.project)) {
Rest.setUrl(GetBasePath('projects') + scope.project + '/'); Rest.setUrl(GetBasePath('projects') + scope.project + '/');
Rest.get() Rest.get()
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
@@ -395,6 +396,7 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
{ hdr: 'Error!', msg: 'Failed to get project ' + scope.project +'. GET returned status: ' + status }); { hdr: 'Error!', msg: 'Failed to get project ' + scope.project +'. GET returned status: ' + status });
}); });
} }
}
// Register a watcher on project_name. Refresh the playbook list on change. // Register a watcher on project_name. Refresh the playbook list on change.
@@ -683,5 +685,5 @@ JobTemplatesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList',
'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup', 'ParseTypeChange',
'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream' 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty'
]; ];

View File

@@ -38,8 +38,10 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
var name = list.iterator.charAt(0).toUpperCase() + list.iterator.substring(1); var name = list.iterator.charAt(0).toUpperCase() + list.iterator.substring(1);
var hdr = (params.hdr) ? params.hdr : 'Select ' + name; var hdr = (params.hdr) ? params.hdr : 'Select ' + name;
$('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-url',defaultUrl + var watchUrl = (/\/$/.test(defaultUrl)) ? defaultUrl + '?' : defaultUrl + '&';
'?' + form.fields[field].sourceField + '__' + 'iexact=:value'); 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); $('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-source',field);
scope['lookUp' + name] = function() { scope['lookUp' + name] = function() {