"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
const urlPrefix = document.querySelector("main").dataset.urlPrefix;
const searchFilterFormElement = document.querySelector("#form--searchFilters");
const searchResultsContainerElement = document.querySelector("#container--searchResults");
const limit = Number.parseInt(document.querySelector("#searchFilter--limit").value, 10);
const offsetElement = document.querySelector("#searchFilter--offset");
const getLots = () => {
const offset = Number.parseInt(offsetElement.value, 10);
searchResultsContainerElement.innerHTML = "
" +
" " +
"Loading " + exports.aliases.lots + "..." +
"
";
cityssm.postJSON(urlPrefix + "/lots/doSearchLots", searchFilterFormElement, (responseJSON) => {
if (responseJSON.lots.length === 0) {
searchResultsContainerElement.innerHTML = "" +
"
There are no " + exports.aliases.lots.toLowerCase() + " that meet the search criteria.
" +
"
";
return;
}
const resultsTbodyElement = document.createElement("tbody");
for (const lot of responseJSON.lots) {
resultsTbodyElement.insertAdjacentHTML("beforeend", "" +
("" +
"" +
lot.lotName +
" " +
" ") +
("" +
"" +
lot.mapName +
" " +
" ") +
"" + lot.lotType + " " +
("" +
lot.lotStatus + " " +
(lot.lotOccupancyCount > 0 ? "Currently Occupied " : "") +
" ") +
" ");
}
searchResultsContainerElement.innerHTML = "" +
"" +
"" + exports.aliases.lot + " " +
"" + exports.aliases.map + " " +
"" + exports.aliases.lot + " Type " +
"Status " +
" " +
"" +
"" +
("
" +
"
" +
"Displaying " + (offset + 1).toString() +
" to " + Math.min(responseJSON.count, limit + offset) +
" of " + responseJSON.count +
"
" +
"
") +
("
" +
(offset > 0 ?
"
" +
"" +
" " +
" " +
"
" :
"") +
(limit + offset < responseJSON.count
? "
" +
"" +
"Next " +
" " +
" " +
"
"
: "") +
"
") +
"
";
searchResultsContainerElement.querySelector("table").append(resultsTbodyElement);
if (offset > 0) {
searchResultsContainerElement.querySelector("button[data-page='previous']").addEventListener("click", previousAndGetLots);
}
if (limit + offset < responseJSON.count) {
searchResultsContainerElement.querySelector("button[data-page='next']").addEventListener("click", nextAndGetLots);
}
});
};
const resetOffsetAndGetLots = () => {
offsetElement.value = "0";
getLots();
};
const previousAndGetLots = () => {
offsetElement.value = Math.max(Number.parseInt(offsetElement.value, 10) - limit, 0).toString();
getLots();
};
const nextAndGetLots = () => {
offsetElement.value = (Number.parseInt(offsetElement.value, 10) + limit).toString();
getLots();
};
const filterElements = searchFilterFormElement.querySelectorAll("input, select");
for (const filterElement of filterElements) {
filterElement.addEventListener("change", resetOffsetAndGetLots);
}
searchFilterFormElement.addEventListener("submit", (formEvent) => {
formEvent.preventDefault();
resetOffsetAndGetLots();
});
getLots();
})();