fix add fee

deepsource-autofix-76c6eb20
Dan Gowans 2023-01-17 10:20:52 -05:00
parent e40b86f15e
commit 0d2ea594a1
4 changed files with 67 additions and 56 deletions

View File

@ -1001,7 +1001,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
renderLotOccupancyComments(); renderLotOccupancyComments();
"use strict"; "use strict";
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ /* eslint-disable unicorn/prefer-module */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
let lotOccupancyFees = exports.lotOccupancyFees; let lotOccupancyFees = exports.lotOccupancyFees;
delete exports.lotOccupancyFees; delete exports.lotOccupancyFees;
@ -1128,7 +1128,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
renderLotOccupancyTransactions(); renderLotOccupancyTransactions();
} }
document.querySelector('#button--addFee').addEventListener('click', () => { document.querySelector('#button--addFee').addEventListener('click', () => {
if (hasUnsavedChanges) { if (los.hasUnsavedChanges()) {
bulmaJS.alert({ bulmaJS.alert({
message: 'Please save all unsaved changes before adding fees.', message: 'Please save all unsaved changes before adding fees.',
contextualColorName: 'warning' contextualColorName: 'warning'
@ -1168,11 +1168,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
quantityCloseModalFunction(); quantityCloseModalFunction();
} }
cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', { cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', {
onshow: (modalElement) => { onshow(modalElement) {
; ;
modalElement.querySelector('#lotOccupancyFeeQuantity--quantityUnit').textContent = fee.quantityUnit; modalElement.querySelector('#lotOccupancyFeeQuantity--quantityUnit').textContent = fee.quantityUnit;
}, },
onshown: (modalElement, closeModalFunction) => { onshown(modalElement, closeModalFunction) {
quantityCloseModalFunction = closeModalFunction; quantityCloseModalFunction = closeModalFunction;
quantityElement = modalElement.querySelector('#lotOccupancyFeeQuantity--quantity'); quantityElement = modalElement.querySelector('#lotOccupancyFeeQuantity--quantity');
modalElement modalElement
@ -1184,7 +1184,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
function tryAddFee(clickEvent) { function tryAddFee(clickEvent) {
clickEvent.preventDefault(); clickEvent.preventDefault();
const feeId = Number.parseInt(clickEvent.currentTarget.dataset.feeId, 10); const feeId = Number.parseInt(clickEvent.currentTarget.dataset.feeId, 10);
const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest('.container--feeCategory').dataset.feeCategoryId, 10); const feeCategoryId = Number.parseInt(clickEvent.currentTarget.dataset.feeCategoryId, 10);
const feeCategory = feeCategories.find((currentFeeCategory) => { const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId; return currentFeeCategory.feeCategoryId === feeCategoryId;
}); });
@ -1199,7 +1199,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
} }
function filterFees() { function filterFees() {
var _a, _b; var _a, _b, _c, _d, _e;
const filterStringPieces = feeFilterElement.value const filterStringPieces = feeFilterElement.value
.trim() .trim()
.toLowerCase() .toLowerCase()
@ -1212,19 +1212,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
feeCategory.feeCategoryId.toString(); feeCategory.feeCategoryId.toString();
categoryContainerElement.innerHTML = categoryContainerElement.innerHTML =
'<h4 class="title is-5 mt-2">' + '<h4 class="title is-5 mt-2">' +
cityssm.escapeHTML(feeCategory.feeCategory || '') + cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '') +
'</h4>' + '</h4>' +
'<div class="panel mb-5"></div>'; '<div class="panel mb-5"></div>';
let hasFees = false; let hasFees = false;
for (const fee of feeCategory.fees) { for (const fee of feeCategory.fees) {
if (lotOccupancyFeesContainerElement.querySelector(".container--lotOccupancyFee[data-fee-id='" + // Don't include already applied fees that limit quantity
fee.feeId + if (lotOccupancyFeesContainerElement.querySelector(`.container--lotOccupancyFee[data-fee-id='${fee.feeId}'][data-include-quantity='0']`) !== null) {
"'][data-include-quantity='0']")) {
continue; continue;
} }
let includeFee = true; let includeFee = true;
const feeSearchString = (((_b = fee.feeName) !== null && _b !== void 0 ? _b : '') +
' ' +
((_c = fee.feeDescription) !== null && _c !== void 0 ? _c : '')).toLowerCase();
for (const filterStringPiece of filterStringPieces) { for (const filterStringPiece of filterStringPieces) {
if (!fee.feeName.toLowerCase().includes(filterStringPiece)) { if (!feeSearchString.includes(filterStringPiece)) {
includeFee = false; includeFee = false;
break; break;
} }
@ -1236,14 +1238,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
const panelBlockElement = document.createElement('a'); const panelBlockElement = document.createElement('a');
panelBlockElement.className = 'panel-block is-block container--fee'; panelBlockElement.className = 'panel-block is-block container--fee';
panelBlockElement.dataset.feeId = fee.feeId.toString(); panelBlockElement.dataset.feeId = fee.feeId.toString();
panelBlockElement.dataset.feeCategoryId =
feeCategory.feeCategoryId.toString();
panelBlockElement.href = '#'; panelBlockElement.href = '#';
panelBlockElement.innerHTML = panelBlockElement.innerHTML =
'<strong>' + '<strong>' +
cityssm.escapeHTML((_a = fee.feeName) !== null && _a !== void 0 ? _a : '') + cityssm.escapeHTML((_d = fee.feeName) !== null && _d !== void 0 ? _d : '') +
'</strong><br />' + '</strong><br />' +
'<small>' + '<small>' +
cityssm cityssm
.escapeHTML((_b = fee.feeDescription) !== null && _b !== void 0 ? _b : '') .escapeHTML((_e = fee.feeDescription) !== null && _e !== void 0 ? _e : '')
.replace(/\n/g, '<br />') + .replace(/\n/g, '<br />') +
'</small>'; '</small>';
panelBlockElement.addEventListener('click', tryAddFee); panelBlockElement.addEventListener('click', tryAddFee);
@ -1417,7 +1421,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
}); });
} }
cityssm.openHtmlModal('lotOccupancy-addTransaction', { cityssm.openHtmlModal('lotOccupancy-addTransaction', {
onshow: (modalElement) => { onshow(modalElement) {
los.populateAliases(modalElement); los.populateAliases(modalElement);
modalElement.querySelector('#lotOccupancyTransactionAdd--lotOccupancyId').value = lotOccupancyId.toString(); modalElement.querySelector('#lotOccupancyTransactionAdd--lotOccupancyId').value = lotOccupancyId.toString();
const feeGrandTotal = getFeeGrandTotal(); const feeGrandTotal = getFeeGrandTotal();
@ -1427,14 +1431,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
transactionAmountElement.max = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2); transactionAmountElement.max = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2);
transactionAmountElement.value = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2); transactionAmountElement.value = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2);
}, },
onshown: (modalElement, closeModalFunction) => { onshown(modalElement, closeModalFunction) {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
addCloseModalFunction = closeModalFunction; addCloseModalFunction = closeModalFunction;
modalElement modalElement
.querySelector('form') .querySelector('form')
.addEventListener('submit', doAddTransaction); .addEventListener('submit', doAddTransaction);
}, },
onremoved: () => { onremoved() {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
} }
}); });

View File

@ -1,5 +1,5 @@
"use strict"; "use strict";
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ /* eslint-disable unicorn/prefer-module */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
let lotOccupancyFees = exports.lotOccupancyFees; let lotOccupancyFees = exports.lotOccupancyFees;
delete exports.lotOccupancyFees; delete exports.lotOccupancyFees;
@ -126,7 +126,7 @@ function renderLotOccupancyFees() {
renderLotOccupancyTransactions(); renderLotOccupancyTransactions();
} }
document.querySelector('#button--addFee').addEventListener('click', () => { document.querySelector('#button--addFee').addEventListener('click', () => {
if (hasUnsavedChanges) { if (los.hasUnsavedChanges()) {
bulmaJS.alert({ bulmaJS.alert({
message: 'Please save all unsaved changes before adding fees.', message: 'Please save all unsaved changes before adding fees.',
contextualColorName: 'warning' contextualColorName: 'warning'
@ -166,11 +166,11 @@ document.querySelector('#button--addFee').addEventListener('click', () => {
quantityCloseModalFunction(); quantityCloseModalFunction();
} }
cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', { cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', {
onshow: (modalElement) => { onshow(modalElement) {
; ;
modalElement.querySelector('#lotOccupancyFeeQuantity--quantityUnit').textContent = fee.quantityUnit; modalElement.querySelector('#lotOccupancyFeeQuantity--quantityUnit').textContent = fee.quantityUnit;
}, },
onshown: (modalElement, closeModalFunction) => { onshown(modalElement, closeModalFunction) {
quantityCloseModalFunction = closeModalFunction; quantityCloseModalFunction = closeModalFunction;
quantityElement = modalElement.querySelector('#lotOccupancyFeeQuantity--quantity'); quantityElement = modalElement.querySelector('#lotOccupancyFeeQuantity--quantity');
modalElement modalElement
@ -182,7 +182,7 @@ document.querySelector('#button--addFee').addEventListener('click', () => {
function tryAddFee(clickEvent) { function tryAddFee(clickEvent) {
clickEvent.preventDefault(); clickEvent.preventDefault();
const feeId = Number.parseInt(clickEvent.currentTarget.dataset.feeId, 10); const feeId = Number.parseInt(clickEvent.currentTarget.dataset.feeId, 10);
const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest('.container--feeCategory').dataset.feeCategoryId, 10); const feeCategoryId = Number.parseInt(clickEvent.currentTarget.dataset.feeCategoryId, 10);
const feeCategory = feeCategories.find((currentFeeCategory) => { const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId; return currentFeeCategory.feeCategoryId === feeCategoryId;
}); });
@ -197,7 +197,7 @@ document.querySelector('#button--addFee').addEventListener('click', () => {
} }
} }
function filterFees() { function filterFees() {
var _a, _b; var _a, _b, _c, _d, _e;
const filterStringPieces = feeFilterElement.value const filterStringPieces = feeFilterElement.value
.trim() .trim()
.toLowerCase() .toLowerCase()
@ -210,19 +210,21 @@ document.querySelector('#button--addFee').addEventListener('click', () => {
feeCategory.feeCategoryId.toString(); feeCategory.feeCategoryId.toString();
categoryContainerElement.innerHTML = categoryContainerElement.innerHTML =
'<h4 class="title is-5 mt-2">' + '<h4 class="title is-5 mt-2">' +
cityssm.escapeHTML(feeCategory.feeCategory || '') + cityssm.escapeHTML((_a = feeCategory.feeCategory) !== null && _a !== void 0 ? _a : '') +
'</h4>' + '</h4>' +
'<div class="panel mb-5"></div>'; '<div class="panel mb-5"></div>';
let hasFees = false; let hasFees = false;
for (const fee of feeCategory.fees) { for (const fee of feeCategory.fees) {
if (lotOccupancyFeesContainerElement.querySelector(".container--lotOccupancyFee[data-fee-id='" + // Don't include already applied fees that limit quantity
fee.feeId + if (lotOccupancyFeesContainerElement.querySelector(`.container--lotOccupancyFee[data-fee-id='${fee.feeId}'][data-include-quantity='0']`) !== null) {
"'][data-include-quantity='0']")) {
continue; continue;
} }
let includeFee = true; let includeFee = true;
const feeSearchString = (((_b = fee.feeName) !== null && _b !== void 0 ? _b : '') +
' ' +
((_c = fee.feeDescription) !== null && _c !== void 0 ? _c : '')).toLowerCase();
for (const filterStringPiece of filterStringPieces) { for (const filterStringPiece of filterStringPieces) {
if (!fee.feeName.toLowerCase().includes(filterStringPiece)) { if (!feeSearchString.includes(filterStringPiece)) {
includeFee = false; includeFee = false;
break; break;
} }
@ -234,14 +236,16 @@ document.querySelector('#button--addFee').addEventListener('click', () => {
const panelBlockElement = document.createElement('a'); const panelBlockElement = document.createElement('a');
panelBlockElement.className = 'panel-block is-block container--fee'; panelBlockElement.className = 'panel-block is-block container--fee';
panelBlockElement.dataset.feeId = fee.feeId.toString(); panelBlockElement.dataset.feeId = fee.feeId.toString();
panelBlockElement.dataset.feeCategoryId =
feeCategory.feeCategoryId.toString();
panelBlockElement.href = '#'; panelBlockElement.href = '#';
panelBlockElement.innerHTML = panelBlockElement.innerHTML =
'<strong>' + '<strong>' +
cityssm.escapeHTML((_a = fee.feeName) !== null && _a !== void 0 ? _a : '') + cityssm.escapeHTML((_d = fee.feeName) !== null && _d !== void 0 ? _d : '') +
'</strong><br />' + '</strong><br />' +
'<small>' + '<small>' +
cityssm cityssm
.escapeHTML((_b = fee.feeDescription) !== null && _b !== void 0 ? _b : '') .escapeHTML((_e = fee.feeDescription) !== null && _e !== void 0 ? _e : '')
.replace(/\n/g, '<br />') + .replace(/\n/g, '<br />') +
'</small>'; '</small>';
panelBlockElement.addEventListener('click', tryAddFee); panelBlockElement.addEventListener('click', tryAddFee);
@ -415,7 +419,7 @@ document
}); });
} }
cityssm.openHtmlModal('lotOccupancy-addTransaction', { cityssm.openHtmlModal('lotOccupancy-addTransaction', {
onshow: (modalElement) => { onshow(modalElement) {
los.populateAliases(modalElement); los.populateAliases(modalElement);
modalElement.querySelector('#lotOccupancyTransactionAdd--lotOccupancyId').value = lotOccupancyId.toString(); modalElement.querySelector('#lotOccupancyTransactionAdd--lotOccupancyId').value = lotOccupancyId.toString();
const feeGrandTotal = getFeeGrandTotal(); const feeGrandTotal = getFeeGrandTotal();
@ -425,14 +429,14 @@ document
transactionAmountElement.max = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2); transactionAmountElement.max = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2);
transactionAmountElement.value = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2); transactionAmountElement.value = Math.max(feeGrandTotal - transactionGrandTotal, 0).toFixed(2);
}, },
onshown: (modalElement, closeModalFunction) => { onshown(modalElement, closeModalFunction) {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
addCloseModalFunction = closeModalFunction; addCloseModalFunction = closeModalFunction;
modalElement modalElement
.querySelector('form') .querySelector('form')
.addEventListener('submit', doAddTransaction); .addEventListener('submit', doAddTransaction);
}, },
onremoved: () => { onremoved() {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
} }
}); });

View File

@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ /* eslint-disable unicorn/prefer-module */
import type * as globalTypes from '../../types/globalTypes' import type * as globalTypes from '../../types/globalTypes'
import type * as recordTypes from '../../types/recordTypes' import type * as recordTypes from '../../types/recordTypes'
@ -13,7 +13,6 @@ declare const bulmaJS: BulmaJS
declare const los: globalTypes.LOS declare const los: globalTypes.LOS
declare const lotOccupancyId: string declare const lotOccupancyId: string
declare const hasUnsavedChanges: boolean
let lotOccupancyFees: recordTypes.LotOccupancyFee[] = exports.lotOccupancyFees let lotOccupancyFees: recordTypes.LotOccupancyFee[] = exports.lotOccupancyFees
delete exports.lotOccupancyFees delete exports.lotOccupancyFees
@ -182,7 +181,7 @@ function renderLotOccupancyFees(): void {
} }
document.querySelector('#button--addFee')!.addEventListener('click', () => { document.querySelector('#button--addFee')!.addEventListener('click', () => {
if (hasUnsavedChanges) { if (los.hasUnsavedChanges()) {
bulmaJS.alert({ bulmaJS.alert({
message: 'Please save all unsaved changes before adding fees.', message: 'Please save all unsaved changes before adding fees.',
contextualColorName: 'warning' contextualColorName: 'warning'
@ -234,14 +233,14 @@ document.querySelector('#button--addFee')!.addEventListener('click', () => {
} }
cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', { cityssm.openHtmlModal('lotOccupancy-setFeeQuantity', {
onshow: (modalElement) => { onshow(modalElement) {
;( ;(
modalElement.querySelector( modalElement.querySelector(
'#lotOccupancyFeeQuantity--quantityUnit' '#lotOccupancyFeeQuantity--quantityUnit'
) as HTMLElement ) as HTMLElement
).textContent = fee.quantityUnit! ).textContent = fee.quantityUnit!
}, },
onshown: (modalElement, closeModalFunction) => { onshown(modalElement, closeModalFunction) {
quantityCloseModalFunction = closeModalFunction quantityCloseModalFunction = closeModalFunction
quantityElement = modalElement.querySelector( quantityElement = modalElement.querySelector(
@ -263,11 +262,7 @@ document.querySelector('#button--addFee')!.addEventListener('click', () => {
10 10
) )
const feeCategoryId = Number.parseInt( const feeCategoryId = Number.parseInt(
( (clickEvent.currentTarget as HTMLElement).dataset.feeCategoryId!,
(clickEvent.currentTarget as HTMLElement).closest(
'.container--feeCategory'
) as HTMLElement
).dataset.feeCategoryId!,
10 10
) )
@ -296,32 +291,40 @@ document.querySelector('#button--addFee')!.addEventListener('click', () => {
for (const feeCategory of feeCategories) { for (const feeCategory of feeCategories) {
const categoryContainerElement = document.createElement('div') const categoryContainerElement = document.createElement('div')
categoryContainerElement.className = 'container--feeCategory' categoryContainerElement.className = 'container--feeCategory'
categoryContainerElement.dataset.feeCategoryId = categoryContainerElement.dataset.feeCategoryId =
feeCategory.feeCategoryId.toString() feeCategory.feeCategoryId.toString()
categoryContainerElement.innerHTML = categoryContainerElement.innerHTML =
'<h4 class="title is-5 mt-2">' + '<h4 class="title is-5 mt-2">' +
cityssm.escapeHTML(feeCategory.feeCategory || '') + cityssm.escapeHTML(feeCategory.feeCategory ?? '') +
'</h4>' + '</h4>' +
'<div class="panel mb-5"></div>' '<div class="panel mb-5"></div>'
let hasFees = false let hasFees = false
for (const fee of feeCategory.fees) { for (const fee of feeCategory.fees) {
// Don't include already applied fees that limit quantity
if ( if (
lotOccupancyFeesContainerElement.querySelector( lotOccupancyFeesContainerElement.querySelector(
".container--lotOccupancyFee[data-fee-id='" + `.container--lotOccupancyFee[data-fee-id='${fee.feeId}'][data-include-quantity='0']`
fee.feeId + ) !== null
"'][data-include-quantity='0']"
)
) { ) {
continue continue
} }
let includeFee = true let includeFee = true
const feeSearchString = (
(fee.feeName ?? '') +
' ' +
(fee.feeDescription ?? '')
).toLowerCase()
for (const filterStringPiece of filterStringPieces) { for (const filterStringPiece of filterStringPieces) {
if (!fee.feeName!.toLowerCase().includes(filterStringPiece)) { if (!feeSearchString.includes(filterStringPiece)) {
includeFee = false includeFee = false
break break
} }
@ -336,6 +339,8 @@ document.querySelector('#button--addFee')!.addEventListener('click', () => {
const panelBlockElement = document.createElement('a') const panelBlockElement = document.createElement('a')
panelBlockElement.className = 'panel-block is-block container--fee' panelBlockElement.className = 'panel-block is-block container--fee'
panelBlockElement.dataset.feeId = fee.feeId.toString() panelBlockElement.dataset.feeId = fee.feeId.toString()
panelBlockElement.dataset.feeCategoryId =
feeCategory.feeCategoryId.toString()
panelBlockElement.href = '#' panelBlockElement.href = '#'
panelBlockElement.innerHTML = panelBlockElement.innerHTML =
@ -362,13 +367,11 @@ document.querySelector('#button--addFee')!.addEventListener('click', () => {
cityssm.openHtmlModal('lotOccupancy-addFee', { cityssm.openHtmlModal('lotOccupancy-addFee', {
onshow(modalElement) { onshow(modalElement) {
feeFilterElement = modalElement.querySelector( feeFilterElement = modalElement.querySelector('#feeSelect--feeName')!
'#feeSelect--feeName'
) as HTMLInputElement
feeFilterResultsElement = modalElement.querySelector( feeFilterResultsElement = modalElement.querySelector(
'#resultsContainer--feeSelect' '#resultsContainer--feeSelect'
) as HTMLElement )!
cityssm.postJSON( cityssm.postJSON(
los.urlPrefix + '/lotOccupancies/doGetFees', los.urlPrefix + '/lotOccupancies/doGetFees',
@ -585,7 +588,7 @@ document
} }
cityssm.openHtmlModal('lotOccupancy-addTransaction', { cityssm.openHtmlModal('lotOccupancy-addTransaction', {
onshow: (modalElement) => { onshow(modalElement) {
los.populateAliases(modalElement) los.populateAliases(modalElement)
;( ;(
modalElement.querySelector( modalElement.querySelector(
@ -610,7 +613,7 @@ document
0 0
).toFixed(2) ).toFixed(2)
}, },
onshown: (modalElement, closeModalFunction) => { onshown(modalElement, closeModalFunction) {
bulmaJS.toggleHtmlClipped() bulmaJS.toggleHtmlClipped()
addCloseModalFunction = closeModalFunction addCloseModalFunction = closeModalFunction
@ -619,7 +622,7 @@ document
.querySelector('form')! .querySelector('form')!
.addEventListener('submit', doAddTransaction) .addEventListener('submit', doAddTransaction)
}, },
onremoved: () => { onremoved() {
bulmaJS.toggleHtmlClipped() bulmaJS.toggleHtmlClipped()
} }
}) })

File diff suppressed because one or more lines are too long