2022-12-09 04:51:56 +00:00
|
|
|
//Search stuff
|
2022-11-29 15:48:18 +00:00
|
|
|
|
|
|
|
document.querySelector("#searchType").addEventListener("change", e =>
|
|
|
|
{
|
|
|
|
if (e.target.value === "pn")
|
|
|
|
{
|
|
|
|
document.querySelector("#searchField").placeholder = "Find vehicle";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
document.querySelector("#searchField").placeholder = "Find owner";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelector("#searchForm").addEventListener("submit", e =>
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append("searchType", document.querySelector("#searchType").value);
|
|
|
|
formData.append("searchField", document.querySelector("#searchField").value);
|
|
|
|
|
|
|
|
fetch("search.php", {
|
|
|
|
method: "POST",
|
|
|
|
body: formData
|
|
|
|
}).then(res => res.json().then(json =>
|
|
|
|
{
|
|
|
|
if (json.message === "ok")
|
|
|
|
{
|
|
|
|
document.querySelector("#searchResults thead tr").innerHTML = "";
|
|
|
|
document.querySelector("#searchResults tbody").innerHTML = "";
|
2022-12-15 14:50:58 +00:00
|
|
|
|
|
|
|
for (const key of Object.keys(json.data[0]))
|
2022-11-29 15:48:18 +00:00
|
|
|
{
|
|
|
|
let header = key.substring(key.indexOf("_") + 1)
|
|
|
|
header = header.charAt(0).toUpperCase() + header.slice(1);
|
|
|
|
document.querySelector("#searchResults thead tr").innerHTML += `<th>${header}</th>`;
|
2022-12-15 14:50:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 15:48:18 +00:00
|
|
|
let body = "";
|
2022-12-15 14:50:58 +00:00
|
|
|
for (const row of json.data)
|
2022-11-29 15:48:18 +00:00
|
|
|
{
|
|
|
|
body += "<tr>";
|
2022-12-15 14:50:58 +00:00
|
|
|
for (const key of Object.keys(row))
|
2022-11-29 15:48:18 +00:00
|
|
|
{
|
|
|
|
body += `<td>${(row[key] === "null" || row[key] === null) ? "N/A" : row[key]}</td>`;
|
2022-12-15 14:50:58 +00:00
|
|
|
}
|
2022-11-29 15:48:18 +00:00
|
|
|
body += "</tr>";
|
2022-12-15 14:50:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 15:48:18 +00:00
|
|
|
document.querySelector("#searchResults tbody").innerHTML = body;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
alert("No search results found");
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|