"use strict"; /* eslint-disable @typescript-eslint/indent */ /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; const feeCategoriesContainerElement = document.querySelector('#container--feeCategories'); let feeCategories = exports.feeCategories; delete exports.feeCategories; function renderFeeCategories() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; if (feeCategories.length === 0) { feeCategoriesContainerElement.innerHTML = `

There are no available fees.

`; return; } feeCategoriesContainerElement.innerHTML = ''; for (const feeCategory of feeCategories) { const feeCategoryContainerElement = document.createElement('section'); feeCategoryContainerElement.className = 'panel container--feeCategory'; feeCategoryContainerElement.dataset.feeCategoryId = feeCategory.feeCategoryId.toString(); feeCategoryContainerElement.innerHTML = '
' + '
' + ('
' + '

' + cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '') + '

' + '
') + ('
' + '
' + (feeCategory.fees.length === 0 ? '
' + '' + '
' : '') + ('
' + '' + '
') + ('
' + '' + '
') + ('
' + los.getMoveUpDownButtonFieldHTML('button--moveFeeCategoryUp', 'button--moveFeeCategoryDown') + '
') + '
') + '
' + '
'; if (feeCategory.fees.length === 0) { feeCategoryContainerElement.insertAdjacentHTML('beforeend', `

There are no fees in the "${cityssm.escapeHTML((_b = feeCategory.feeCategory) !== null && _b !== void 0 ? _b : '')}" category.

`); feeCategoryContainerElement .querySelector('.button--deleteFeeCategory') .addEventListener('click', confirmDeleteFeeCategory); } for (const fee of feeCategory.fees) { const panelBlockElement = document.createElement('div'); panelBlockElement.className = 'panel-block is-block container--fee'; panelBlockElement.dataset.feeId = fee.feeId.toString(); const hasTagsBlock = ((_c = fee.isRequired) !== null && _c !== void 0 ? _c : false) || fee.occupancyTypeId !== undefined || fee.lotTypeId !== undefined; panelBlockElement.innerHTML = '
' + ('
' + '

' + '' + cityssm.escapeHTML((_d = fee.feeName) !== null && _d !== void 0 ? _d : '') + '
' + '' + cityssm .escapeHTML((_e = fee.feeDescription) !== null && _e !== void 0 ? _e : '') .replace(/\n/g, '
') + '
' + '

' + (hasTagsBlock ? '

' + (((_f = fee.isRequired) !== null && _f !== void 0 ? _f : false) ? 'Required' : '') + (((_g = fee.occupancyTypeId) !== null && _g !== void 0 ? _g : -1) === -1 ? '' : ' ' + ' ' + '' + cityssm.escapeHTML((_h = fee.occupancyType) !== null && _h !== void 0 ? _h : '') + '' + '') + (((_j = fee.lotTypeId) !== null && _j !== void 0 ? _j : -1) === -1 ? '' : ' ' + ' ' + '' + cityssm.escapeHTML((_k = fee.lotType) !== null && _k !== void 0 ? _k : '') + '' + '') + '

' : '') + '
') + ('
' + '
' + ('
' + (fee.feeFunction ? cityssm.escapeHTML(fee.feeFunction) + '
' + 'Fee Function' : '$' + ((_l = fee.feeAmount) !== null && _l !== void 0 ? _l : 0).toFixed(2) + '
' + 'Fee') + '
') + ('
' + (fee.taxPercentage ? fee.taxPercentage.toString() + '%' : '$' + ((_m = fee.taxAmount) !== null && _m !== void 0 ? _m : 0).toFixed(2)) + '
Tax' + '
') + ('
' + (fee.includeQuantity ? cityssm.escapeHTML((_o = fee.quantityUnit) !== null && _o !== void 0 ? _o : '') + '
' + 'Quantity' : '') + '
') + '
' + '
') + ('
' + los.getMoveUpDownButtonFieldHTML('button--moveFeeUp', 'button--moveFeeDown') + '
' + '
') + '
'; panelBlockElement .querySelector('a') .addEventListener('click', openEditFee); panelBlockElement.querySelector('.button--moveFeeUp').addEventListener('click', moveFee); panelBlockElement.querySelector('.button--moveFeeDown').addEventListener('click', moveFee); feeCategoryContainerElement.append(panelBlockElement); } feeCategoryContainerElement .querySelector('.button--editFeeCategory') .addEventListener('click', openEditFeeCategory); feeCategoryContainerElement .querySelector('.button--addFee') .addEventListener('click', openAddFee); feeCategoryContainerElement.querySelector('.button--moveFeeCategoryUp').addEventListener('click', moveFeeCategory); feeCategoryContainerElement.querySelector('.button--moveFeeCategoryDown').addEventListener('click', moveFeeCategory); feeCategoriesContainerElement.append(feeCategoryContainerElement); } } /* * Fee Categories */ document .querySelector('#button--addFeeCategory') .addEventListener('click', () => { let addCloseModalFunction; function doAddFeeCategory(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doAddFeeCategory', submitEvent.currentTarget, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; addCloseModalFunction(); renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Creating Fee Category', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } cityssm.openHtmlModal('adminFees-addFeeCategory', { onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); modalElement.querySelector('#feeCategoryAdd--feeCategory').focus(); addCloseModalFunction = closeModalFunction; modalElement .querySelector('form') .addEventListener('submit', doAddFeeCategory); }, onremoved() { bulmaJS.toggleHtmlClipped(); document.querySelector('#button--addFeeCategory').focus(); } }); }); function openEditFeeCategory(clickEvent) { const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest('.container--feeCategory').dataset.feeCategoryId, 10); const feeCategory = feeCategories.find((currentFeeCategory) => { return currentFeeCategory.feeCategoryId === feeCategoryId; }); let editCloseModalFunction; function doUpdateFeeCategory(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doUpdateFeeCategory', submitEvent.currentTarget, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; editCloseModalFunction(); renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Updating Fee Category', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } cityssm.openHtmlModal('adminFees-editFeeCategory', { onshow(modalElement) { ; modalElement.querySelector('#feeCategoryEdit--feeCategoryId').value = feeCategory.feeCategoryId.toString(); modalElement.querySelector('#feeCategoryEdit--feeCategory').value = feeCategory.feeCategory; }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); editCloseModalFunction = closeModalFunction; modalElement .querySelector('form') .addEventListener('submit', doUpdateFeeCategory); modalElement.querySelector('#feeCategoryEdit--feeCategory').focus(); }, onremoved: () => { bulmaJS.toggleHtmlClipped(); } }); } function confirmDeleteFeeCategory(clickEvent) { const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest('.container--feeCategory').dataset.feeCategoryId, 10); function doDelete() { cityssm.postJSON(los.urlPrefix + '/admin/doDeleteFeeCategory', { feeCategoryId }, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Updating Fee Category', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } bulmaJS.confirm({ title: 'Delete Fee Category?', message: 'Are you sure you want to delete this fee category?', contextualColorName: 'warning', okButton: { text: 'Yes, Delete the Fee Category', callbackFunction: doDelete } }); } function moveFeeCategory(clickEvent) { const buttonElement = clickEvent.currentTarget; const feeCategoryId = buttonElement.closest('.container--feeCategory').dataset.feeCategoryId; cityssm.postJSON(los.urlPrefix + '/admin/' + (buttonElement.dataset.direction === 'up' ? 'doMoveFeeCategoryUp' : 'doMoveFeeCategoryDown'), { feeCategoryId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Moving Fee Category', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } /* * Fees */ function openAddFee(clickEvent) { const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest('.container--feeCategory').dataset.feeCategoryId, 10); let addCloseModalFunction; function doAddFee(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doAddFee', submitEvent.currentTarget, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; addCloseModalFunction(); renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Adding Fee', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } cityssm.openHtmlModal('adminFees-addFee', { onshow(modalElement) { const feeCategoryElement = modalElement.querySelector('#feeAdd--feeCategoryId'); for (const feeCategory of feeCategories) { const optionElement = document.createElement('option'); optionElement.value = feeCategory.feeCategoryId.toString(); optionElement.textContent = feeCategory.feeCategory; if (feeCategory.feeCategoryId === feeCategoryId) { optionElement.selected = true; } feeCategoryElement.append(optionElement); } const occupancyTypeElement = modalElement.querySelector('#feeAdd--occupancyTypeId'); for (const occupancyType of exports.occupancyTypes) { const optionElement = document.createElement('option'); optionElement.value = occupancyType.occupancyTypeId.toString(); optionElement.textContent = occupancyType.occupancyType; occupancyTypeElement.append(optionElement); } const lotTypeElement = modalElement.querySelector('#feeAdd--lotTypeId'); for (const lotType of exports.lotTypes) { const optionElement = document.createElement('option'); optionElement.value = lotType.lotTypeId.toString(); optionElement.textContent = lotType.lotType; lotTypeElement.append(optionElement); } ; modalElement.querySelector('#feeAdd--taxPercentage').value = exports.taxPercentageDefault.toString(); los.populateAliases(modalElement); }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); addCloseModalFunction = closeModalFunction; modalElement.querySelector('form').addEventListener('submit', doAddFee); modalElement.querySelector('#feeAdd--feeName').focus(); modalElement.querySelector('#feeAdd--feeFunction').addEventListener('change', () => { const feeAmountElement = modalElement.querySelector('#feeAdd--feeAmount'); const feeFunctionElement = modalElement.querySelector('#feeAdd--feeFunction'); if (feeFunctionElement.value === '') { feeFunctionElement .closest('.select') .classList.remove('is-success'); feeAmountElement.classList.add('is-success'); feeAmountElement.disabled = false; } else { feeFunctionElement.closest('.select').classList.add('is-success'); feeAmountElement.classList.remove('is-success'); feeAmountElement.disabled = true; } }); modalElement .querySelector('#feeAdd--taxPercentage') .addEventListener('keyup', () => { const taxAmountElement = modalElement.querySelector('#feeAdd--taxAmount'); const taxPercentageElement = modalElement.querySelector('#feeAdd--taxPercentage'); if (taxPercentageElement.value === '') { taxPercentageElement.classList.remove('is-success'); taxAmountElement.classList.add('is-success'); taxAmountElement.disabled = false; } else { taxPercentageElement.classList.add('is-success'); taxAmountElement.classList.remove('is-success'); taxAmountElement.disabled = true; } }); modalElement .querySelector('#feeAdd--includeQuantity') .addEventListener('change', () => { ; modalElement.querySelector('#feeAdd--quantityUnit').disabled = modalElement.querySelector('#feeAdd--includeQuantity').value === ''; }); }, onremoved() { bulmaJS.toggleHtmlClipped(); } }); } function openEditFee(clickEvent) { clickEvent.preventDefault(); const feeContainerElement = clickEvent.currentTarget.closest('.container--fee'); const feeId = Number.parseInt(feeContainerElement.dataset.feeId, 10); const feeCategoryId = Number.parseInt(feeContainerElement.closest('.container--feeCategory') .dataset.feeCategoryId); const feeCategory = feeCategories.find((currentFeeCategory) => { return currentFeeCategory.feeCategoryId === feeCategoryId; }); const fee = feeCategory.fees.find((currentFee) => { return currentFee.feeId === feeId; }); let editCloseModalFunction; let editModalElement; function doUpdateFee(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(los.urlPrefix + '/admin/doUpdateFee', submitEvent.currentTarget, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; editCloseModalFunction(); renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Updating Fee', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } function confirmDeleteFee(clickEvent) { clickEvent.preventDefault(); function doDelete() { cityssm.postJSON(los.urlPrefix + '/admin/doDeleteFee', { feeId }, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; editCloseModalFunction(); renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Deleting Fee', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } bulmaJS.confirm({ title: 'Delete Fee?', message: 'Are you sure you want to delete this fee?', contextualColorName: 'warning', okButton: { text: 'Yes, Delete the Fee', callbackFunction: doDelete } }); } function toggleFeeFields() { const feeAmountElement = editModalElement.querySelector('#feeEdit--feeAmount'); const feeFunctionElement = editModalElement.querySelector('#feeEdit--feeFunction'); if (feeFunctionElement.value === '') { feeFunctionElement.closest('.select').classList.remove('is-success'); feeAmountElement.classList.add('is-success'); feeAmountElement.disabled = false; } else { feeFunctionElement.closest('.select').classList.add('is-success'); feeAmountElement.classList.remove('is-success'); feeAmountElement.disabled = true; } } function toggleTaxFields() { const taxAmountElement = editModalElement.querySelector('#feeEdit--taxAmount'); const taxPercentageElement = editModalElement.querySelector('#feeEdit--taxPercentage'); if (taxPercentageElement.value === '') { taxPercentageElement.classList.remove('is-success'); taxAmountElement.classList.add('is-success'); taxAmountElement.disabled = false; } else { taxPercentageElement.classList.add('is-success'); taxAmountElement.classList.remove('is-success'); taxAmountElement.disabled = true; } } function toggleQuantityFields() { const includeQuanitityValue = editModalElement.querySelector('#feeEdit--includeQuantity').value; editModalElement.querySelector('#feeEdit--quantityUnit').disabled = includeQuanitityValue === ''; } cityssm.openHtmlModal('adminFees-editFee', { onshow(modalElement) { var _a, _b, _c, _d, _e, _f; editModalElement = modalElement; modalElement.querySelector('#feeEdit--feeId').value = fee.feeId.toString(); const feeCategoryElement = modalElement.querySelector('#feeEdit--feeCategoryId'); for (const feeCategory of feeCategories) { const optionElement = document.createElement('option'); optionElement.value = feeCategory.feeCategoryId.toString(); optionElement.textContent = feeCategory.feeCategory; if (feeCategory.feeCategoryId === feeCategoryId) { optionElement.selected = true; } feeCategoryElement.append(optionElement); } ; modalElement.querySelector('#feeEdit--feeName').value = (_a = fee.feeName) !== null && _a !== void 0 ? _a : ''; modalElement.querySelector('#feeEdit--feeAccount').value = (_b = fee.feeAccount) !== null && _b !== void 0 ? _b : ''; modalElement.querySelector('#feeEdit--feeDescription').value = (_c = fee.feeDescription) !== null && _c !== void 0 ? _c : ''; const occupancyTypeElement = modalElement.querySelector('#feeEdit--occupancyTypeId'); for (const occupancyType of exports.occupancyTypes) { const optionElement = document.createElement('option'); optionElement.value = occupancyType.occupancyTypeId.toString(); optionElement.textContent = occupancyType.occupancyType; if (occupancyType.occupancyTypeId === fee.occupancyTypeId) { optionElement.selected = true; } occupancyTypeElement.append(optionElement); } const lotTypeElement = modalElement.querySelector('#feeEdit--lotTypeId'); for (const lotType of exports.lotTypes) { const optionElement = document.createElement('option'); optionElement.value = lotType.lotTypeId.toString(); optionElement.textContent = lotType.lotType; if (lotType.lotTypeId === fee.lotTypeId) { optionElement.selected = true; } lotTypeElement.append(optionElement); } ; modalElement.querySelector('#feeEdit--feeAmount').value = fee.feeAmount ? fee.feeAmount.toFixed(2) : ''; modalElement .querySelector('#feeEdit--feeFunction') .addEventListener('change', toggleFeeFields); toggleFeeFields(); modalElement.querySelector('#feeEdit--taxAmount').value = fee.taxAmount ? fee.taxAmount.toFixed(2) : ''; const taxPercentageElement = modalElement.querySelector('#feeEdit--taxPercentage'); taxPercentageElement.value = fee.taxPercentage ? fee.taxPercentage.toString() : ''; taxPercentageElement.addEventListener('keyup', toggleTaxFields); toggleTaxFields(); const includeQuantityElement = modalElement.querySelector('#feeEdit--includeQuantity'); if ((_d = fee.includeQuantity) !== null && _d !== void 0 ? _d : false) { includeQuantityElement.value = '1'; } includeQuantityElement.addEventListener('change', toggleQuantityFields); modalElement.querySelector('#feeEdit--quantityUnit').value = (_e = fee.quantityUnit) !== null && _e !== void 0 ? _e : ''; toggleQuantityFields(); if ((_f = fee.isRequired) !== null && _f !== void 0 ? _f : false) { ; modalElement.querySelector('#feeEdit--isRequired').value = '1'; } los.populateAliases(modalElement); }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); editCloseModalFunction = closeModalFunction; modalElement .querySelector('form') .addEventListener('submit', doUpdateFee); bulmaJS.init(modalElement); modalElement .querySelector('.button--deleteFee') .addEventListener('click', confirmDeleteFee); }, onremoved: () => { bulmaJS.toggleHtmlClipped(); } }); } function moveFee(clickEvent) { const buttonElement = clickEvent.currentTarget; const feeContainerElement = buttonElement.closest('.container--fee'); const feeId = feeContainerElement.dataset.feeId; cityssm.postJSON(los.urlPrefix + '/admin/' + (buttonElement.dataset.direction === 'up' ? 'doMoveFeeUp' : 'doMoveFeeDown'), { feeId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, (rawResponseJSON) => { var _a; const responseJSON = rawResponseJSON; if (responseJSON.success) { feeCategories = responseJSON.feeCategories; renderFeeCategories(); } else { bulmaJS.alert({ title: 'Error Moving Fee', message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '', contextualColorName: 'danger' }); } }); } /* * Initialize */ renderFeeCategories(); })();