37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
|
hideLoading()
|
||
|
|
||
|
async function findByOrigDest() {
|
||
|
showLoading()
|
||
|
const formData = await fetchOrigDest()
|
||
|
log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`)
|
||
|
const endpoint = `pis/${formData.origin}/${formData.destination}`
|
||
|
const json = await getApi(endpoint)
|
||
|
if (json == false) {
|
||
|
await noData()
|
||
|
} else {
|
||
|
await displayData(json)
|
||
|
}
|
||
|
document.getElementById('crs-box').style = 'display:none'
|
||
|
document.getElementById('result-box').style = 'display:block'
|
||
|
hideLoading()
|
||
|
}
|
||
|
|
||
|
async function fetchOrigDest() {
|
||
|
var orig = document.getElementById("origin").value
|
||
|
var dest = document.getElementById("destination").value
|
||
|
return {origin: orig, destination: dest}
|
||
|
}
|
||
|
|
||
|
async function displayData(json) {
|
||
|
log(`displayData: ${JSON.stringify(json)}`)
|
||
|
}
|
||
|
|
||
|
async function noData() {
|
||
|
msg = '<p>No results found</p>'
|
||
|
document.getElementById('result-box').insertAdjacentHTML("beforeend", msg)
|
||
|
}
|
||
|
|
||
|
async function reset() {
|
||
|
document.getElementById('result-box').style = 'display:none'
|
||
|
document.getElementById('crs-box').style = 'display:block'
|
||
|
}
|