"use strict"; /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; 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'); function renderLotOccupancies(responseJSON) { var _a, _b; if (responseJSON.lotOccupancies.length === 0) { searchResultsContainerElement.innerHTML = `

There are no ${los.escapedAliases.occupancy} 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 ' + los.escapedAliases.Lot + ')') + '
' + ('' + cityssm.escapeHTML(lotOccupancy.mapName || '') + '') + '') + ('' + lotOccupancy.occupancyStartDateString + '') + ('' + (lotOccupancy.occupancyEndDate ? lotOccupancy.occupancyEndDateString : '(No End Date)') + '') + ('' + occupantsHTML + '') + '' + (lotOccupancy.printEJS ? '' + '' + '' : '') + '' + ''); } searchResultsContainerElement.innerHTML = `
${los.escapedAliases.Occupancy} Type ${los.escapedAliases.Lot} ${los.escapedAliases.OccupancyStartDate} End Date ${los.escapedAliases.Occupants} Print
`; searchResultsContainerElement .querySelector('table') .append(resultsTbodyElement); searchResultsContainerElement.insertAdjacentHTML('beforeend', los.getSearchResultsPagerHTML(limit, responseJSON.offset, responseJSON.count)); (_a = searchResultsContainerElement .querySelector("button[data-page='previous']")) === null || _a === void 0 ? void 0 : _a.addEventListener('click', previousAndGetLotOccupancies); (_b = searchResultsContainerElement .querySelector("button[data-page='next']")) === null || _b === void 0 ? void 0 : _b.addEventListener('click', nextAndGetLotOccupancies); } function getLotOccupancies() { searchResultsContainerElement.innerHTML = los.getLoadingParagraphHTML(`Loading ${exports.aliases.occupancies}...`); cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doSearchLotOccupancies', searchFilterFormElement, renderLotOccupancies); } function resetOffsetAndGetLotOccupancies() { offsetElement.value = '0'; getLotOccupancies(); } function previousAndGetLotOccupancies() { offsetElement.value = Math.max(Number.parseInt(offsetElement.value, 10) - limit, 0).toString(); getLotOccupancies(); } function 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(); })();