diff --git a/static/find-code.html b/static/find-code.html index 1682262..8441198 100644 --- a/static/find-code.html +++ b/static/find-code.html @@ -32,10 +32,10 @@

Code Lookup

Enter one known code in the relevant box below and hit submit. Where they exist, the other code types will be filled in.

-

You cannot lookup by STANME as the values are not unique.

+

You cannot yet lookup by Station name as the values are not unique.

Station name search will be added in the future.


-
+



@@ -44,8 +44,9 @@


-
-
+
+
+ \ No newline at end of file diff --git a/static/js/find-code.js b/static/js/find-code.js index 083216b..ff18002 100644 --- a/static/js/find-code.js +++ b/static/js/find-code.js @@ -20,18 +20,22 @@ async function fetchEntry(){ async function parseData(values){ if (values.crs != ""){ - getData("crs", values.crs) + var data = await getData("crs", values.crs) } else if (values.nlc != ""){ - getData("nlc", values.nlc) + var data = await getData("nlc", values.nlc) } else if (values.tiploc != ""){ - getData("tiploc", values.tiploc) + var data = await getData("tiploc", values.tiploc) } else if (values.stanox != ""){ - getData("stanox", values.stanox) + var data = await getData("stanox", values.stanox) } else if (values.name != ""){ - getData("name", values.name) + var data = await getData("name", values.name) } else { errorNoData() + data = {status: "failed"} + return } + + displayData(data); } async function getData(type, value){ @@ -46,6 +50,26 @@ async function getData(type, value){ } } +async function displayData(data){ + if (data.status === "failed" || data == ""){ + errorNotFound() + } + document.getElementById("name").value = data['0']['NLCDESC'] + document.getElementById("3alpha").value = data['0']['3ALPHA'] + document.getElementById("nlc").value = data['0']['NLC'] + document.getElementById("tiploc").value = data['0']['TIPLOC'] + document.getElementById("stanox").value = data['0']['STANOX'] +// document.getElementById("stanme").value = data['0']['STANME'] // NOT PRESENT IN CORPUS +} + +async function clearForm(){ + document.getElementById("name").value = "" + document.getElementById("3alpha").value = "" + document.getElementById("nlc").value = "" + document.getElementById("tiploc").value = "" + document.getElementById("stanox").value = "" +} + async function errorNoData(){ console.log("No data entered") window.alert("You haven't entered any data") @@ -54,4 +78,9 @@ async function errorNoData(){ async function errorFetch(err){ console.log("Error fetching data") console.log(err) +} + +async function errorNotFound(){ + console.log("Location not found") + window.alert("No location was found. Check and try again.") } \ No newline at end of file