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