"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
const urlPrefix = document.querySelector("main").dataset.urlPrefix;
const lotOccupancyPrints = exports.lotOccupancyPrints;
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 getLotOccupancies = () => {
const offset = Number.parseInt(offsetElement.value, 10);
searchResultsContainerElement.innerHTML =
'
' +
'
' +
"Loading " +
exports.aliases.occupancies +
"..." +
"
";
cityssm.postJSON(urlPrefix + "/lotOccupancies/doSearchLotOccupancies", searchFilterFormElement, (responseJSON) => {
if (responseJSON.lotOccupancies.length === 0) {
searchResultsContainerElement.innerHTML =
'' +
'
There are no ' +
cityssm.escapeHTML(exports.aliases.occupancy.toLowerCase()) +
" records that meet the search criteria.
" +
"
";
return;
}
const resultsTbodyElement = document.createElement("tbody");
const nowDateString = cityssm.dateToString(new Date());
for (const lotOccupancy of responseJSON.lotOccupancies) {
let occupancyTimeHTML = "";
if (lotOccupancy.occupancyStartDateString <= nowDateString &&
(lotOccupancy.occupancyEndDateString === "" ||
lotOccupancy.occupancyEndDateString >= nowDateString)) {
occupancyTimeHTML =
'';
}
else if (lotOccupancy.occupancyStartDateString > nowDateString) {
occupancyTimeHTML =
'';
}
else {
occupancyTimeHTML =
'';
}
let occupantsHTML = "";
for (const occupant of lotOccupancy.lotOccupancyOccupants) {
occupantsHTML +=
'' +
cityssm.escapeHTML(occupant.occupantName) +
"
";
}
resultsTbodyElement.insertAdjacentHTML("beforeend", "" +
('| ' + occupancyTimeHTML + " | ") +
("" +
'' +
cityssm.escapeHTML(lotOccupancy.occupancyType) +
"" +
" | ") +
("" +
(lotOccupancy.lotName
? cityssm.escapeHTML(lotOccupancy.lotName)
: '(No ' +
cityssm.escapeHTML(exports.aliases.lot) +
")") +
" " +
'' +
cityssm.escapeHTML(lotOccupancy.mapName || "") +
"" +
" | ") +
("" + lotOccupancy.occupancyStartDateString + " | ") +
("" +
(lotOccupancy.occupancyEndDate
? lotOccupancy.occupancyEndDateString
: '(No End Date)') +
" | ") +
"" +
occupantsHTML +
" | " +
(lotOccupancyPrints.length > 0
? "" +
'' +
'' +
"" +
" | "
: "") +
"
");
}
searchResultsContainerElement.innerHTML =
'' +
"" +
' | ' +
("" + cityssm.escapeHTML(exports.aliases.occupancy) + " Type | ") +
("" + cityssm.escapeHTML(exports.aliases.lot) + " | ") +
"Start Date | " +
"End Date | " +
("" + cityssm.escapeHTML(exports.aliases.occupants) + " | ") +
(lotOccupancyPrints.length > 0 ? ' | ' : "") +
"
" +
"" +
'' +
('
' +
'
' +
"Displaying " +
(offset + 1).toString() +
" to " +
Math.min(responseJSON.count, limit + offset) +
" of " +
responseJSON.count +
"
" +
"
") +
('
' +
(offset > 0
? '
' +
'" +
"
"
: "") +
(limit + offset < responseJSON.count
? '
' +
'" +
"
"
: "") +
"
") +
"
";
searchResultsContainerElement.querySelector("table").append(resultsTbodyElement);
if (offset > 0) {
searchResultsContainerElement
.querySelector("button[data-page='previous']")
.addEventListener("click", previousAndGetLotOccupancies);
}
if (limit + offset < responseJSON.count) {
searchResultsContainerElement
.querySelector("button[data-page='next']")
.addEventListener("click", nextAndGetLotOccupancies);
}
});
};
const resetOffsetAndGetLotOccupancies = () => {
offsetElement.value = "0";
getLotOccupancies();
};
const previousAndGetLotOccupancies = () => {
offsetElement.value = Math.max(Number.parseInt(offsetElement.value, 10) - limit, 0).toString();
getLotOccupancies();
};
const nextAndGetLotOccupancies = () => {
offsetElement.value = (Number.parseInt(offsetElement.value, 10) + limit).toString();
getLotOccupancies();
};
const filterElements = searchFilterFormElement.querySelectorAll("input, select");
for (const filterElement of filterElements) {
filterElement.addEventListener("change", resetOffsetAndGetLotOccupancies);
}
searchFilterFormElement.addEventListener("submit", (formEvent) => {
formEvent.preventDefault();
resetOffsetAndGetLotOccupancies();
});
getLotOccupancies();
})();