diff options
| -rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/libtoaster.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 587f51fff9..34a3fbb1fb 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js | |||
| @@ -18,15 +18,24 @@ var libtoaster = (function (){ | |||
| 18 | if (!xhrUrl || xhrUrl.length === 0) | 18 | if (!xhrUrl || xhrUrl.length === 0) |
| 19 | throw("No url to typeahead supplied"); | 19 | throw("No url to typeahead supplied"); |
| 20 | 20 | ||
| 21 | var xhrReq; | ||
| 22 | |||
| 21 | jQElement.typeahead({ | 23 | jQElement.typeahead({ |
| 22 | source: function(query, process){ | 24 | source: function(query, process){ |
| 23 | xhrParams.search = query; | 25 | xhrParams.search = query; |
| 24 | $.getJSON(xhrUrl, this.options.xhrParams, function(data){ | 26 | |
| 27 | /* If we have a request in progress don't fire off another one*/ | ||
| 28 | if (xhrReq) | ||
| 29 | xhrReq.abort(); | ||
| 30 | |||
| 31 | xhrReq = $.getJSON(xhrUrl, this.options.xhrParams, function(data){ | ||
| 25 | if (data.error !== "ok") { | 32 | if (data.error !== "ok") { |
| 26 | console.log("Error getting data from server "+data.error); | 33 | console.log("Error getting data from server "+data.error); |
| 27 | return; | 34 | return; |
| 28 | } | 35 | } |
| 29 | 36 | ||
| 37 | xhrReq = null; | ||
| 38 | |||
| 30 | return process(data.results); | 39 | return process(data.results); |
| 31 | }); | 40 | }); |
| 32 | }, | 41 | }, |
| @@ -41,6 +50,9 @@ var libtoaster = (function (){ | |||
| 41 | return 0; | 50 | return 0; |
| 42 | } | 51 | } |
| 43 | 52 | ||
| 53 | if (this.$element.val().length === 0) | ||
| 54 | return 0; | ||
| 55 | |||
| 44 | return 1; | 56 | return 1; |
| 45 | }, | 57 | }, |
| 46 | highlighter: function (item) { | 58 | highlighter: function (item) { |
| @@ -52,6 +64,7 @@ var libtoaster = (function (){ | |||
| 52 | sorter: function (items) { return items; }, | 64 | sorter: function (items) { return items; }, |
| 53 | xhrUrl: xhrUrl, | 65 | xhrUrl: xhrUrl, |
| 54 | xhrParams: xhrParams, | 66 | xhrParams: xhrParams, |
| 67 | xhrReq: xhrReq, | ||
| 55 | }); | 68 | }); |
| 56 | 69 | ||
| 57 | 70 | ||
| @@ -528,6 +541,9 @@ $(document).ready(function() { | |||
| 528 | }); | 541 | }); |
| 529 | 542 | ||
| 530 | $(document).ajaxError(function(event, jqxhr, settings, errMsg){ | 543 | $(document).ajaxError(function(event, jqxhr, settings, errMsg){ |
| 544 | if (errMsg === 'abort') | ||
| 545 | return; | ||
| 546 | |||
| 531 | console.warn("Problem with xhr call"); | 547 | console.warn("Problem with xhr call"); |
| 532 | console.warn(errMsg); | 548 | console.warn(errMsg); |
| 533 | console.warn(jqxhr.responseText); | 549 | console.warn(jqxhr.responseText); |
