Updated the typeahead directive to cache queries.
This commit is contained in:
parent
572a630520
commit
fa95e79e0f
@ -1,6 +1,6 @@
|
||||
CACHE MANIFEST
|
||||
|
||||
# version 2013-05-18.1
|
||||
# version 2013-05-18.2
|
||||
|
||||
CACHE:
|
||||
/partial/404.html
|
||||
|
@ -5,24 +5,32 @@ overlord_directive.directive('ngAutocomplete', ['$q', '$parse', 'DeepLabel', fun
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function (scope, element, attrs, ngModel) {
|
||||
var labels = [],
|
||||
var labelsCache = {},
|
||||
mappedCache = {},
|
||||
labels = [],
|
||||
mapped = {},
|
||||
deepLabel = DeepLabel;
|
||||
|
||||
|
||||
element.typeahead({
|
||||
source: function (query, process) {
|
||||
var Entity = angular.injector(['overlord.service']).get(attrs.resource);
|
||||
Entity.autocomplete({term: query, count: 20}, function (result) {
|
||||
labels = [];
|
||||
mapped = {};
|
||||
$.each(result, function (i, item) {
|
||||
var label = deepLabel(item, attrs.label);
|
||||
mapped[label] = item
|
||||
labels.push(label)
|
||||
})
|
||||
process(labels)
|
||||
});
|
||||
if (query in labelsCache) {
|
||||
labels = labelsCache[query];
|
||||
mapped = mappedCache[query];
|
||||
process(labels);
|
||||
} else {
|
||||
var Entity = angular.injector(['overlord.service']).get(attrs.resource);
|
||||
Entity.autocomplete({term: query, count: 20}, function (result) {
|
||||
labels = [];
|
||||
mapped = {};
|
||||
$.each(result, function (i, item) {
|
||||
var label = deepLabel(item, attrs.label);
|
||||
mapped[label] = item
|
||||
labels.push(label)
|
||||
})
|
||||
labelsCache[query] = labels;
|
||||
mappedCache[query] = mapped;
|
||||
process(labels)
|
||||
});
|
||||
}
|
||||
},
|
||||
minLength: 1,
|
||||
items: 20,
|
||||
|
Loading…
Reference in New Issue
Block a user