Add callback for search text entery

This commit is contained in:
Oliver Walters 2022-03-28 20:24:07 +11:00
parent 7d68b3209b
commit c4ac7e1877

View File

@ -6,6 +6,7 @@
/* exported
closeSearchPanel,
openSearchPanel,
searchTextChanged,
*/
@ -30,5 +31,64 @@ function openSearchPanel() {
// Finally, grab keyboard focus in the search bar
panel.find('#search-input').focus();
panel.find('#search-input').on('keyup change', searchTextChanged);
}
var searchRequests = [];
var searchInputTimer = null;
var searchText = null;
var searchTextPrevious = null;
function searchTextChanged(event) {
searchText = $('#offcanvas-search').find('#search-input').val();
clearTimeout(searchInputTimer);
searchInputTimer = setTimeout(updateSearch, 250);
};
function updateSearch() {
if (searchText == searchTextPrevious) {
return;
}
if (searchText.length == 0) {
return;
}
searchTextPrevious = searchText;
// Search for matching parts
inventreeGet(
`{% url "api-part-list" %}`,
{
search: searchText,
limit: 10,
offset: 0,
},
{
success: function(results) {
// TODO
}
}
);
// Search for matching stock items
inventreeGet(
'{% url "api-stock-list" %}',
{
search: searchText,
limit: 10,
offset: 0,
},
{
success: function(results) {
// TODO
}
}
)
}