66 lines
1.4 KiB
JavaScript
66 lines
1.4 KiB
JavaScript
var searchAddressTimer = false;
|
|
|
|
$(document).ready(function() {
|
|
/*
|
|
* Address search
|
|
*/
|
|
|
|
$("#owner_text").keyup(function() {
|
|
var search_string = $("#owner_text").val();
|
|
|
|
/*
|
|
* Rate limit search, by waiting 400 ms before really searching
|
|
* If input is received while waiting, clear timeout and set it anew
|
|
*/
|
|
|
|
// clear timeout if it is set
|
|
if(searchAddressTimer) {
|
|
clearTimeout(searchAddressTimer);
|
|
}
|
|
// wait for additional input before starting the search
|
|
searchAddressTimer = setTimeout(searchAddress, 400, "owner", search_string);
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Prevent accidental submit
|
|
*/
|
|
|
|
$('#owner_text').keydown(function() {
|
|
if(event.keyCode == 13) {
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
});
|
|
|
|
function searchAddress(type = "owner", search_string) {
|
|
if(search_string.length < 2) return;
|
|
console.log("suchen...");
|
|
|
|
|
|
$.get(baseurl + "Address/Api",{
|
|
do: "findAddress",
|
|
search: search_string
|
|
},
|
|
function(success) {
|
|
console.log(success);
|
|
if(success.status != "OK") {
|
|
return;
|
|
}
|
|
showAddressResults(type, success.result);
|
|
},
|
|
"json");
|
|
|
|
$("#address_results").show();
|
|
}
|
|
|
|
function showAddressResults(type, result) {
|
|
console.log(type);
|
|
|
|
result.addresses.forEach(function(address) {
|
|
cnosole.log(address);
|
|
});
|
|
} |