mirror of
https://github.com/ansible/awx.git
synced 2026-05-22 16:27:42 -02:30
Merge pull request #3094 from mabashian/2935-backspace-inv-cred-jt
awlookup timeout instead of GET with every keystroke
This commit is contained in:
@@ -390,15 +390,22 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'JobsHelper'])
|
||||
|
||||
// lookup Validate lookup value against API
|
||||
//
|
||||
.directive('awlookup', ['Rest', function(Rest) {
|
||||
.directive('awlookup', ['Rest', '$timeout', function(Rest, $timeout) {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, elm, attrs, ctrl) {
|
||||
|
||||
var restTimeout;
|
||||
|
||||
ctrl.$parsers.unshift( function(viewValue) {
|
||||
if (viewValue !== '' && viewValue !== null) {
|
||||
var url = elm.attr('data-url');
|
||||
url = url.replace(/\:value/, encodeURI(viewValue));
|
||||
scope[elm.attr('data-source')] = null;
|
||||
if(restTimeout) {
|
||||
$timeout.cancel(restTimeout);
|
||||
}
|
||||
restTimeout = $timeout( function(){
|
||||
Rest.setUrl(url);
|
||||
Rest.get().then( function(data) {
|
||||
var results = data.data.results;
|
||||
@@ -428,8 +435,12 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'JobsHelper'])
|
||||
ctrl.$setValidity('awlookup', false);
|
||||
return undefined;
|
||||
});
|
||||
}, 750);
|
||||
}
|
||||
else {
|
||||
if(restTimeout) {
|
||||
$timeout.cancel(restTimeout);
|
||||
}
|
||||
ctrl.$setValidity('awlookup', true);
|
||||
scope[elm.attr('data-source')] = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user