"use strict";
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable max-lines */
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
const sunrise = exports.sunrise;
const workOrderId = document.querySelector('#workOrderEdit--workOrderId').value;
let workOrderBurialSites = exports.workOrderBurialSites;
delete exports.workOrderBurialSites;
let workOrderContracts = exports.workOrderContracts;
delete exports.workOrderContracts;
function deleteContract(clickEvent) {
const contractId = clickEvent.currentTarget.closest('.container--contract').dataset.contractId;
function doDelete() {
cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doDeleteWorkOrderContract`, {
workOrderId,
contractId
}, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
workOrderContracts = responseJSON.workOrderContracts;
renderRelatedBurialSitesAndContracts();
}
else {
bulmaJS.alert({
title: 'Error Deleting Relationship',
message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger'
});
}
});
}
bulmaJS.confirm({
title: 'Delete Contract Relationship',
message: `Are you sure you want to remove the relationship to this contract record from this work order?
Note that the contract will remain.`,
contextualColorName: 'warning',
okButton: {
text: 'Yes, Delete Relationship',
callbackFunction: doDelete
}
});
}
function addBurialSite(burialSiteId, callbackFunction) {
cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doAddWorkOrderBurialSite`, {
workOrderId,
burialSiteId
}, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
workOrderBurialSites = responseJSON.workOrderBurialSites;
renderRelatedBurialSitesAndContracts();
}
else {
bulmaJS.alert({
title: 'Error Adding Burial Site',
message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger'
});
}
if (callbackFunction !== undefined) {
callbackFunction(responseJSON.success);
}
});
}
function addContract(contractId, callbackFunction) {
cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doAddWorkOrderContract`, {
workOrderId,
contractId
}, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
workOrderContracts = responseJSON.workOrderContracts;
renderRelatedBurialSitesAndContracts();
}
else {
bulmaJS.alert({
title: 'Error Adding Contract',
message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger'
});
}
if (callbackFunction !== undefined) {
callbackFunction(responseJSON.success);
}
});
}
function addBurialSiteFromContract(clickEvent) {
const burialSiteId = clickEvent.currentTarget.dataset.burialSiteId ?? '';
addBurialSite(burialSiteId);
}
// eslint-disable-next-line complexity
function renderRelatedContracts() {
const contractsContainerElement = document.querySelector('#container--contracts');
document.querySelector(".tabs a[href='#relatedTab--contracts'] .tag").textContent = workOrderContracts.length.toString();
if (workOrderContracts.length === 0) {
contractsContainerElement.innerHTML = `
There are no contracts associated with this work order.
`;
return;
}
contractsContainerElement.innerHTML = `
|
Contract Type |
Burial Site |
Contract Date |
End Date |
Interments |
|
`;
const currentDateString = cityssm.dateToString(new Date());
for (const contract of workOrderContracts) {
const rowElement = document.createElement('tr');
rowElement.className = 'container--contract';
rowElement.dataset.contractId = contract.contractId.toString();
const isActive = !(contract.contractEndDate &&
contract.contractEndDateString < currentDateString);
const hasBurialSiteRecord = contract.burialSiteId &&
workOrderBurialSites.some((burialSite) => contract.burialSiteId === burialSite.burialSiteId);
// eslint-disable-next-line no-unsanitized/property
rowElement.innerHTML = `
${isActive
? ''
: ''}
|
${cityssm.escapeHTML(contract.contractType ?? '')}
#${contract.contractId}
| `;
if (contract.burialSiteId) {
// eslint-disable-next-line no-unsanitized/method
rowElement.insertAdjacentHTML('beforeend', `
${cityssm.escapeHTML(contract.burialSiteName ?? '')}
${hasBurialSiteRecord
? ''
: ` `}
| `);
}
else {
rowElement.insertAdjacentHTML('beforeend', '(No Burial Site) | ');
}
let intermentsHTML = '';
for (const interment of contract.contractInterments ?? []) {
intermentsHTML += `
${cityssm.escapeHTML(interment.deceasedName ?? '')}
`;
}
// eslint-disable-next-line no-unsanitized/method
rowElement.insertAdjacentHTML('beforeend', `
${contract.contractStartDateString}
|
${contract.contractEndDate
? contract.contractEndDateString
: '(No End Date)'}
|
${contract.contractInterments.length === 0
? '(No Interments)'
: ``}
|
| `);
rowElement
.querySelector('.button--addBurialSite')
?.addEventListener('click', addBurialSiteFromContract);
rowElement
.querySelector('.button--deleteContract')
?.addEventListener('click', deleteContract);
contractsContainerElement.querySelector('tbody')?.append(rowElement);
}
}
function openEditBurialSiteStatus(clickEvent) {
const burialSiteId = Number.parseInt(clickEvent.currentTarget.closest('.container--burialSite').dataset.burialSiteId ?? '', 10);
const burialSite = workOrderBurialSites.find((potentialBurialSite) => potentialBurialSite.burialSiteId === burialSiteId);
let editCloseModalFunction;
function doUpdateBurialSiteStatus(submitEvent) {
submitEvent.preventDefault();
cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doUpdateBurialSiteStatus`, submitEvent.currentTarget, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
workOrderBurialSites = responseJSON.workOrderBurialSites;
renderRelatedBurialSitesAndContracts();
editCloseModalFunction();
}
else {
bulmaJS.alert({
title: 'Error Deleting Relationship',
message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger'
});
}
});
}
cityssm.openHtmlModal('burialSite-editBurialSiteStatus', {
onshow(modalElement) {
sunrise.populateAliases(modalElement);
modalElement.querySelector('#burialSiteStatusEdit--burialSiteId').value = burialSiteId.toString();
modalElement.querySelector('#burialSiteStatusEdit--burialSiteName').value = burialSite.burialSiteName ?? '';
const burialSiteStatusElement = modalElement.querySelector('#burialSiteStatusEdit--burialSiteStatusId');
let statusFound = false;
for (const burialSiteStatus of exports.burialSiteStatuses) {
const optionElement = document.createElement('option');
optionElement.value = burialSiteStatus.burialSiteStatusId.toString();
optionElement.textContent = burialSiteStatus.burialSiteStatus;
if (burialSiteStatus.burialSiteStatusId ===
burialSite.burialSiteStatusId) {
statusFound = true;
}
burialSiteStatusElement.append(optionElement);
}
if (!statusFound && burialSite.burialSiteStatusId) {
const optionElement = document.createElement('option');
optionElement.value = burialSite.burialSiteStatusId.toString();
optionElement.textContent = burialSite.burialSiteStatus ?? '';
burialSiteStatusElement.append(optionElement);
}
if (burialSite.burialSiteStatusId) {
burialSiteStatusElement.value =
burialSite.burialSiteStatusId.toString();
}
// eslint-disable-next-line no-unsanitized/method
modalElement
.querySelector('form')
?.insertAdjacentHTML('beforeend', ``);
},
onshown(modalElement, closeModalFunction) {
editCloseModalFunction = closeModalFunction;
bulmaJS.toggleHtmlClipped();
modalElement
.querySelector('form')
?.addEventListener('submit', doUpdateBurialSiteStatus);
},
onremoved() {
bulmaJS.toggleHtmlClipped();
}
});
}
function deleteBurialSite(clickEvent) {
const burialSiteId = clickEvent.currentTarget.closest('.container--burialSite').dataset.burialSiteId;
function doDelete() {
cityssm.postJSON(`${sunrise.urlPrefix}/workOrders/doDeleteWorkOrderBurialSite`, {
workOrderId,
burialSiteId
}, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
workOrderBurialSites = responseJSON.workOrderBurialSites;
renderRelatedBurialSitesAndContracts();
}
else {
bulmaJS.alert({
title: 'Error Deleting Relationship',
message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger'
});
}
});
}
bulmaJS.confirm({
title: 'Delete Burial Site Relationship',
message: `Are you sure you want to remove the relationship to this burial site from this work order?
Note that the record will remain.`,
contextualColorName: 'warning',
okButton: {
text: 'Yes, Delete Relationship',
callbackFunction: doDelete
}
});
}
function renderRelatedBurialSites() {
const burialSitesContainerElement = document.querySelector('#container--burialSites');
document.querySelector(".tabs a[href='#relatedTab--burialSites'] .tag").textContent = workOrderBurialSites.length.toString();
if (workOrderBurialSites.length === 0) {
burialSitesContainerElement.innerHTML = `
There are no burial sites associated with this work order.
`;
return;
}
burialSitesContainerElement.innerHTML = `
| Burial Site |
Cemetery |
Burial Site Type |
Status |
|
`;
for (const burialSite of workOrderBurialSites) {
const rowElement = document.createElement('tr');
rowElement.className = 'container--burialSite';
rowElement.dataset.burialSiteId = burialSite.burialSiteId.toString();
// eslint-disable-next-line no-unsanitized/property
rowElement.innerHTML = `
${cityssm.escapeHTML(burialSite.burialSiteName ?? '')}
|
${cityssm.escapeHTML(burialSite.cemeteryName ?? '')}
|
${cityssm.escapeHTML(burialSite.burialSiteType ?? '')}
|
${burialSite.burialSiteStatusId
? cityssm.escapeHTML(burialSite.burialSiteStatus ?? '')
: '(No Status)'}
|
| `;
rowElement
.querySelector('.button--editBurialSiteStatus')
?.addEventListener('click', openEditBurialSiteStatus);
rowElement
.querySelector('.button--deleteBurialSite')
?.addEventListener('click', deleteBurialSite);
burialSitesContainerElement.querySelector('tbody')?.append(rowElement);
}
}
function renderRelatedBurialSitesAndContracts() {
renderRelatedContracts();
renderRelatedBurialSites();
}
renderRelatedBurialSitesAndContracts();
function doAddContract(clickEvent) {
const rowElement = clickEvent.currentTarget.closest('tr');
const contractId = rowElement.dataset.contractId ?? '';
addContract(contractId, (success) => {
if (success) {
rowElement.remove();
}
});
}
document
.querySelector('#button--addContract')
?.addEventListener('click', (addClickEvent) => {
addClickEvent.preventDefault();
let searchFormElement;
let searchResultsContainerElement;
function doSearch(event) {
event?.preventDefault();
// eslint-disable-next-line no-unsanitized/property
searchResultsContainerElement.innerHTML =
sunrise.getLoadingParagraphHTML('Searching...');
cityssm.postJSON(`${sunrise.urlPrefix}/contracts/doSearchContracts`, searchFormElement, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.contracts.length === 0) {
searchResultsContainerElement.innerHTML = `
There are no records that meet the search criteria.
`;
return;
}
searchResultsContainerElement.innerHTML = `
|
Contract Type |
Burial Site |
Contract Date |
End Date |
Interments |
`;
for (const contract of responseJSON.contracts) {
const rowElement = document.createElement('tr');
rowElement.className = 'container--contract';
rowElement.dataset.contractId = contract.contractId.toString();
rowElement.innerHTML = `
|
${cityssm.escapeHTML(contract.contractType ?? '')}
| `;
if (contract.burialSiteId) {
rowElement.insertAdjacentHTML('beforeend', `${cityssm.escapeHTML(contract.burialSiteName ?? '')} | `);
}
else {
rowElement.insertAdjacentHTML('beforeend', '(No Burial Site) | ');
}
// eslint-disable-next-line no-unsanitized/method
rowElement.insertAdjacentHTML('beforeend', `
${contract.contractStartDateString}
|
${contract.contractEndDate
? contract.contractEndDateString
: '(No End Date)'}
|
${(contract.contractInterments ?? []).length === 0
? `
(No ${cityssm.escapeHTML(contract.isPreneed ?? false
? 'Recipients'
: 'Deceased')})
`
: cityssm.escapeHTML(contract.contractInterments[0].deceasedName) +
(contract.contractInterments.length > 1
? ` plus
${(contract.contractInterments.length - 1).toString()}`
: '')} | `);
rowElement
.querySelector('.button--addContract')
?.addEventListener('click', doAddContract);
searchResultsContainerElement
.querySelector('tbody')
?.append(rowElement);
}
});
}
cityssm.openHtmlModal('workOrder-addContract', {
onshow(modalElement) {
sunrise.populateAliases(modalElement);
searchFormElement = modalElement.querySelector('form');
searchResultsContainerElement = modalElement.querySelector('#resultsContainer--contractAdd');
modalElement.querySelector('#contractSearch--notWorkOrderId').value = workOrderId;
modalElement.querySelector('#contractSearch--contractEffectiveDateString').value = document.querySelector('#workOrderEdit--workOrderOpenDateString').value;
doSearch();
},
onshown(modalElement) {
bulmaJS.toggleHtmlClipped();
const deceasedNameElement = modalElement.querySelector('#contractSearch--deceasedName');
deceasedNameElement.addEventListener('change', doSearch);
deceasedNameElement.focus();
modalElement.querySelector('#contractSearch--burialSiteName').addEventListener('change', doSearch);
searchFormElement.addEventListener('submit', doSearch);
},
onremoved() {
bulmaJS.toggleHtmlClipped();
document.querySelector('#button--addContract').focus();
}
});
});
function doAddBurialSite(clickEvent) {
const rowElement = clickEvent.currentTarget.closest('tr');
const burialSiteId = rowElement.dataset.burialSiteId ?? '';
addBurialSite(burialSiteId, (success) => {
if (success) {
rowElement.remove();
}
});
}
document
.querySelector('#button--addBurialSite')
?.addEventListener('click', (addClickEvent) => {
addClickEvent.preventDefault();
let searchFormElement;
let searchResultsContainerElement;
function doSearch(event) {
event?.preventDefault();
// eslint-disable-next-line no-unsanitized/property
searchResultsContainerElement.innerHTML =
sunrise.getLoadingParagraphHTML('Searching...');
cityssm.postJSON(`${sunrise.urlPrefix}/burialSites/doSearchBurialSites`, searchFormElement, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
if (responseJSON.burialSites.length === 0) {
searchResultsContainerElement.innerHTML = `
There are no records that meet the search criteria.
`;
return;
}
searchResultsContainerElement.innerHTML = `
|
Burial Site |
Cemetery |
Burial Site Type |
Status |
`;
for (const burialSite of responseJSON.burialSites) {
const rowElement = document.createElement('tr');
rowElement.className = 'container--burialSite';
rowElement.dataset.burialSiteId =
burialSite.burialSiteId.toString();
rowElement.innerHTML = `
|
${cityssm.escapeHTML(burialSite.burialSiteName ?? '')}
|
${cityssm.escapeHTML(burialSite.cemeteryName ?? '')}
|
${cityssm.escapeHTML(burialSite.burialSiteType ?? '')}
|
${cityssm.escapeHTML(burialSite.burialSiteStatus ?? '')}
| `;
rowElement
.querySelector('.button--addBurialSite')
?.addEventListener('click', doAddBurialSite);
searchResultsContainerElement
.querySelector('tbody')
?.append(rowElement);
}
});
}
cityssm.openHtmlModal('workOrder-addBurialSite', {
onshow(modalElement) {
sunrise.populateAliases(modalElement);
searchFormElement = modalElement.querySelector('form');
searchResultsContainerElement = modalElement.querySelector('#resultsContainer--burialSiteAdd');
modalElement.querySelector('#burialSiteSearch--notWorkOrderId').value = workOrderId;
const burialSiteStatusElement = modalElement.querySelector('#burialSiteSearch--burialSiteStatusId');
for (const burialSiteStatus of exports.burialSiteStatuses) {
const optionElement = document.createElement('option');
optionElement.value = burialSiteStatus.burialSiteStatusId.toString();
optionElement.textContent = burialSiteStatus.burialSiteStatus;
burialSiteStatusElement.append(optionElement);
}
doSearch();
},
onshown(modalElement) {
bulmaJS.toggleHtmlClipped();
const burialSiteNameElement = modalElement.querySelector('#burialSiteSearch--burialSiteName');
burialSiteNameElement.addEventListener('change', doSearch);
burialSiteNameElement.focus();
modalElement
.querySelector('#burialSiteSearch--burialSiteStatusId')
?.addEventListener('change', doSearch);
searchFormElement.addEventListener('submit', doSearch);
},
onremoved() {
bulmaJS.toggleHtmlClipped();
document.querySelector('#button--addBurialSite').focus();
}
});
});
})();