"use strict"; /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ var _a; Object.defineProperty(exports, "__esModule", { value: true }); let lotOccupancyComments = exports.lotOccupancyComments; delete exports.lotOccupancyComments; function openEditLotOccupancyComment(clickEvent) { const lotOccupancyCommentId = Number.parseInt(clickEvent.currentTarget.closest('tr').dataset .lotOccupancyCommentId, 10); const lotOccupancyComment = lotOccupancyComments.find((currentLotOccupancyComment) => { return (currentLotOccupancyComment.lotOccupancyCommentId === lotOccupancyCommentId); }); let editFormElement; let editCloseModalFunction; function editComment(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doUpdateLotOccupancyComment', editFormElement, (responseJSON) => { var _a; if (responseJSON.success) { lotOccupancyComments = responseJSON.lotOccupancyComments; editCloseModalFunction(); renderLotOccupancyComments(); } else { bulmaJS.alert({ title: 'Error Updating Comment', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } cityssm.openHtmlModal('lotOccupancy-editComment', { onshow(modalElement) { los.populateAliases(modalElement); modalElement.querySelector('#lotOccupancyCommentEdit--lotOccupancyId').value = lotOccupancyId; modalElement.querySelector('#lotOccupancyCommentEdit--lotOccupancyCommentId').value = lotOccupancyCommentId.toString(); modalElement.querySelector('#lotOccupancyCommentEdit--lotOccupancyComment').value = lotOccupancyComment.lotOccupancyComment; const lotOccupancyCommentDateStringElement = modalElement.querySelector('#lotOccupancyCommentEdit--lotOccupancyCommentDateString'); lotOccupancyCommentDateStringElement.value = lotOccupancyComment.lotOccupancyCommentDateString; const currentDateString = cityssm.dateToString(new Date()); lotOccupancyCommentDateStringElement.max = lotOccupancyComment.lotOccupancyCommentDateString <= currentDateString ? currentDateString : lotOccupancyComment.lotOccupancyCommentDateString; modalElement.querySelector('#lotOccupancyCommentEdit--lotOccupancyCommentTimeString').value = lotOccupancyComment.lotOccupancyCommentTimeString; }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); los.initializeDatePickers(modalElement); modalElement.querySelector('#lotOccupancyCommentEdit--lotOccupancyComment').focus(); editFormElement = modalElement.querySelector('form'); editFormElement.addEventListener('submit', editComment); editCloseModalFunction = closeModalFunction; }, onremoved() { bulmaJS.toggleHtmlClipped(); } }); } function deleteLotOccupancyComment(clickEvent) { const lotOccupancyCommentId = Number.parseInt(clickEvent.currentTarget.closest('tr').dataset .lotOccupancyCommentId, 10); function doDelete() { cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doDeleteLotOccupancyComment', { lotOccupancyId, lotOccupancyCommentId }, (responseJSON) => { var _a; if (responseJSON.success) { lotOccupancyComments = responseJSON.lotOccupancyComments; renderLotOccupancyComments(); } else { bulmaJS.alert({ title: 'Error Removing Comment', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } bulmaJS.confirm({ title: 'Remove Comment?', message: 'Are you sure you want to remove this comment?', okButton: { text: 'Yes, Remove Comment', callbackFunction: doDelete }, contextualColorName: 'warning' }); } function renderLotOccupancyComments() { var _a, _b, _c; const containerElement = document.querySelector('#container--lotOccupancyComments'); if (lotOccupancyComments.length === 0) { containerElement.innerHTML = '
' + '

There are no comments associated with this record.

' + '
'; return; } const tableElement = document.createElement('table'); tableElement.className = 'table is-fullwidth is-striped is-hoverable'; tableElement.innerHTML = '' + 'Commentor' + 'Comment Date' + 'Comment' + 'Options' + '' + ''; for (const lotOccupancyComment of lotOccupancyComments) { const tableRowElement = document.createElement('tr'); tableRowElement.dataset.lotOccupancyCommentId = lotOccupancyComment.lotOccupancyCommentId.toString(); tableRowElement.innerHTML = '' + cityssm.escapeHTML((_a = lotOccupancyComment.recordCreate_userName) !== null && _a !== void 0 ? _a : '') + '' + '' + ((_b = lotOccupancyComment.lotOccupancyCommentDateString) !== null && _b !== void 0 ? _b : '') + (lotOccupancyComment.lotOccupancyCommentTime === 0 ? '' : ' ' + lotOccupancyComment.lotOccupancyCommentTimeString) + '' + '' + cityssm.escapeHTML((_c = lotOccupancyComment.lotOccupancyComment) !== null && _c !== void 0 ? _c : '') + '' + ('' + '
' + ('') + ('') + '
' + ''); tableRowElement .querySelector('.button--edit') .addEventListener('click', openEditLotOccupancyComment); tableRowElement .querySelector('.button--delete') .addEventListener('click', deleteLotOccupancyComment); tableElement.querySelector('tbody').append(tableRowElement); } containerElement.innerHTML = ''; containerElement.append(tableElement); } (_a = document.querySelector('#button--addComment')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => { let addFormElement; let addCloseModalFunction; function addComment(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/lotOccupancies/doAddLotOccupancyComment', addFormElement, (responseJSON) => { var _a; if (responseJSON.success) { lotOccupancyComments = responseJSON.lotOccupancyComments; addCloseModalFunction(); renderLotOccupancyComments(); } else { bulmaJS.alert({ title: 'Error Adding Comment', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } cityssm.openHtmlModal('lotOccupancy-addComment', { onshow(modalElement) { los.populateAliases(modalElement); modalElement.querySelector('#lotOccupancyCommentAdd--lotOccupancyId').value = lotOccupancyId; }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); modalElement.querySelector('#lotOccupancyCommentAdd--lotOccupancyComment').focus(); addFormElement = modalElement.querySelector('form'); addFormElement.addEventListener('submit', addComment); addCloseModalFunction = closeModalFunction; }, onremoved: () => { bulmaJS.toggleHtmlClipped(); document.querySelector('#button--addComment').focus(); } }); }); renderLotOccupancyComments();