bitbake: toastergui: libtoaster: typeahead resiliency for slow server

When we have a slow request we don't want to see the typeahead results
changing in the middle of typing the item. To do this we make sure that
requests to the typeahead can only happen sequentially and that if
results have been retrieved but the input is now empty we don't bother
showing the results.

(Bitbake rev: 0b508e8b4a9e25c223c6c11ecd6d0e1aab727e8c)

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Michael Wood 2015-08-04 22:46:39 +03:00 committed by Richard Purdie
parent 0494a2769b
commit aad380028f
1 changed files with 17 additions and 1 deletions

View File

@ -18,15 +18,24 @@ var libtoaster = (function (){
if (!xhrUrl || xhrUrl.length === 0)
throw("No url to typeahead supplied");
var xhrReq;
jQElement.typeahead({
source: function(query, process){
xhrParams.search = query;
$.getJSON(xhrUrl, this.options.xhrParams, function(data){
/* If we have a request in progress don't fire off another one*/
if (xhrReq)
xhrReq.abort();
xhrReq = $.getJSON(xhrUrl, this.options.xhrParams, function(data){
if (data.error !== "ok") {
console.log("Error getting data from server "+data.error);
return;
}
xhrReq = null;
return process(data.results);
});
},
@ -41,6 +50,9 @@ var libtoaster = (function (){
return 0;
}
if (this.$element.val().length === 0)
return 0;
return 1;
},
highlighter: function (item) {
@ -52,6 +64,7 @@ var libtoaster = (function (){
sorter: function (items) { return items; },
xhrUrl: xhrUrl,
xhrParams: xhrParams,
xhrReq: xhrReq,
});
@ -528,6 +541,9 @@ $(document).ready(function() {
});
$(document).ajaxError(function(event, jqxhr, settings, errMsg){
if (errMsg === 'abort')
return;
console.warn("Problem with xhr call");
console.warn(errMsg);
console.warn(jqxhr.responseText);