refactoring

deepsource-autofix-76c6eb20
Dan Gowans 2022-12-29 13:11:21 -05:00
parent 830053b820
commit cb3c2c4492
8 changed files with 692 additions and 719 deletions

View File

@ -88,7 +88,7 @@ declare const bulmaJS: BulmaJS;
"</div>" + "</div>" +
"</div>"; "</div>";
if (feeCategory.fees!.length === 0) { if (feeCategory.fees.length === 0) {
feeCategoryContainerElement.insertAdjacentHTML( feeCategoryContainerElement.insertAdjacentHTML(
"beforeend", "beforeend",
'<div class="panel-block is-block">' + '<div class="panel-block is-block">' +
@ -100,7 +100,7 @@ declare const bulmaJS: BulmaJS;
"</div>" "</div>"
); );
} else { } else {
for (const fee of feeCategory.fees!) { for (const fee of feeCategory.fees) {
const panelBlockElement = document.createElement("div"); const panelBlockElement = document.createElement("div");
panelBlockElement.className = "panel-block is-block container--fee"; panelBlockElement.className = "panel-block is-block container--fee";
@ -524,7 +524,7 @@ declare const bulmaJS: BulmaJS;
for (const feeCategory of feeCategories) { for (const feeCategory of feeCategories) {
const optionElement = document.createElement("option"); const optionElement = document.createElement("option");
optionElement.value = feeCategory.feeCategoryId!.toString(); optionElement.value = feeCategory.feeCategoryId.toString();
optionElement.textContent = feeCategory.feeCategory!; optionElement.textContent = feeCategory.feeCategory!;
if (feeCategory.feeCategoryId === feeCategoryId) { if (feeCategory.feeCategoryId === feeCategoryId) {
@ -653,7 +653,7 @@ declare const bulmaJS: BulmaJS;
return currentFeeCategory.feeCategoryId === feeCategoryId; return currentFeeCategory.feeCategoryId === feeCategoryId;
})!; })!;
const fee = feeCategory.fees!.find((currentFee) => { const fee = feeCategory.fees.find((currentFee) => {
return currentFee.feeId === feeId; return currentFee.feeId === feeId;
})!; })!;
@ -781,7 +781,7 @@ declare const bulmaJS: BulmaJS;
editModalElement = modalElement; editModalElement = modalElement;
(modalElement.querySelector("#feeEdit--feeId") as HTMLInputElement).value = (modalElement.querySelector("#feeEdit--feeId") as HTMLInputElement).value =
fee.feeId!.toString(); fee.feeId.toString();
const feeCategoryElement = modalElement.querySelector( const feeCategoryElement = modalElement.querySelector(
"#feeEdit--feeCategoryId" "#feeEdit--feeCategoryId"
@ -789,7 +789,7 @@ declare const bulmaJS: BulmaJS;
for (const feeCategory of feeCategories) { for (const feeCategory of feeCategories) {
const optionElement = document.createElement("option"); const optionElement = document.createElement("option");
optionElement.value = feeCategory.feeCategoryId!.toString(); optionElement.value = feeCategory.feeCategoryId.toString();
optionElement.textContent = feeCategory.feeCategory!; optionElement.textContent = feeCategory.feeCategory!;
if (feeCategory.feeCategoryId === feeCategoryId) { if (feeCategory.feeCategoryId === feeCategoryId) {

View File

@ -344,7 +344,7 @@ declare const bulmaJS: BulmaJS;
modalElement.querySelector( modalElement.querySelector(
"#lotTypeFieldEdit--lotTypeFieldId" "#lotTypeFieldEdit--lotTypeFieldId"
) as HTMLInputElement ) as HTMLInputElement
).value = lotTypeField.lotTypeFieldId!.toString(); ).value = lotTypeField.lotTypeFieldId.toString();
( (
modalElement.querySelector( modalElement.querySelector(
@ -494,7 +494,7 @@ declare const bulmaJS: BulmaJS;
panelBlockElement.classList.add("is-hidden"); panelBlockElement.classList.add("is-hidden");
} }
panelBlockElement.dataset.lotTypeFieldId = lotTypeField.lotTypeFieldId!.toString(); panelBlockElement.dataset.lotTypeFieldId = lotTypeField.lotTypeFieldId.toString();
panelBlockElement.innerHTML = panelBlockElement.innerHTML =
'<div class="level is-mobile">' + '<div class="level is-mobile">' +

View File

@ -485,6 +485,190 @@ Object.defineProperty(exports, "__esModule", { value: true });
"use strict"; "use strict";
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
let lotOccupancyOccupants;
const openEditLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotOccupantIndex, 10);
const lotOccupancyOccupant = lotOccupancyOccupants.find((currentLotOccupancyOccupant) => {
return currentLotOccupancyOccupant.lotOccupantIndex === lotOccupantIndex;
});
let editFormElement;
let editCloseModalFunction;
const editOccupant = (submitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doUpdateLotOccupancyOccupant", editFormElement, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
editCloseModalFunction();
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
cityssm.openHtmlModal("lotOccupancy-editOccupant", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupancyId").value = lotOccupancyId;
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantIndex").value = lotOccupantIndex.toString();
const lotOccupantTypeSelectElement = modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId");
let lotOccupantTypeSelected = false;
for (const lotOccupantType of exports.lotOccupantTypes) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupantType.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupantType.lotOccupantType;
if (lotOccupantType.lotOccupantTypeId === lotOccupancyOccupant.lotOccupantTypeId) {
optionElement.selected = true;
lotOccupantTypeSelected = true;
}
lotOccupantTypeSelectElement.append(optionElement);
}
if (!lotOccupantTypeSelected) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupancyOccupant.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupancyOccupant.lotOccupantType;
optionElement.selected = true;
lotOccupantTypeSelectElement.append(optionElement);
}
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantName").value = lotOccupancyOccupant.occupantName;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress1").value = lotOccupancyOccupant.occupantAddress1;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress2").value = lotOccupancyOccupant.occupantAddress2;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantCity").value = lotOccupancyOccupant.occupantCity;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantProvince").value = lotOccupancyOccupant.occupantProvince;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPostalCode").value = lotOccupancyOccupant.occupantPostalCode;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPhoneNumber").value = lotOccupancyOccupant.occupantPhoneNumber;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantEmailAddress").value = lotOccupancyOccupant.occupantEmailAddress;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantComment").value = lotOccupancyOccupant.occupantComment;
},
onshown: (modalElement, closeModalFunction) => {
bulmaJS.toggleHtmlClipped();
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId").focus();
editFormElement = modalElement.querySelector("form");
editFormElement.addEventListener("submit", editOccupant);
editCloseModalFunction = closeModalFunction;
},
onremoved: () => {
bulmaJS.toggleHtmlClipped();
}
});
};
const deleteLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = clickEvent.currentTarget.closest("tr").dataset
.lotOccupantIndex;
const doDelete = () => {
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doDeleteLotOccupancyOccupant", {
lotOccupancyId,
lotOccupantIndex
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Removing " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
bulmaJS.confirm({
title: "Remove " + exports.aliases.occupant + "?",
message: "Are you sure you want to remove this " + exports.aliases.occupant.toLowerCase() + "?",
okButton: {
text: "Yes, Remove " + exports.aliases.occupant,
callbackFunction: doDelete
},
contextualColorName: "warning"
});
};
const renderLotOccupancyOccupants = () => {
const occupantsContainer = document.querySelector("#container--lotOccupancyOccupants");
cityssm.clearElement(occupantsContainer);
if (lotOccupancyOccupants.length === 0) {
occupantsContainer.innerHTML =
'<div class="message is-warning">' +
'<p class="message-body">There are no ' +
exports.aliases.occupants.toLowerCase() +
" associated with this record.</p>" +
"</div>";
return;
}
const tableElement = document.createElement("table");
tableElement.className = "table is-fullwidth is-striped is-hoverable";
tableElement.innerHTML =
"<thead><tr>" +
("<th>" + exports.aliases.occupant + "</th>") +
"<th>Address</th>" +
"<th>Other Contact</th>" +
"<th>Comment</th>" +
'<th class="is-hidden-print"><span class="is-sr-only">Options</span></th>' +
"</tr></thead>" +
"<tbody></tbody>";
for (const lotOccupancyOccupant of lotOccupancyOccupants) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantIndex =
lotOccupancyOccupant.lotOccupantIndex.toString();
tableRowElement.innerHTML =
"<td>" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantName || "(No Name)") +
"<br />" +
('<span class="tag">' +
'<i class="fas fa-fw fa-' +
cityssm.escapeHTML(lotOccupancyOccupant.fontAwesomeIconClass) +
'" aria-hidden="true"></i>' +
' <span class="ml-1">' +
cityssm.escapeHTML(lotOccupancyOccupant.lotOccupantType) +
"</span>" +
"</span>") +
"</td>" +
("<td>" +
(lotOccupancyOccupant.occupantAddress1
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress1) + "<br />"
: "") +
(lotOccupancyOccupant.occupantAddress2
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress2) + "<br />"
: "") +
(lotOccupancyOccupant.occupantCity
? cityssm.escapeHTML(lotOccupancyOccupant.occupantCity) + ", "
: "") +
cityssm.escapeHTML(lotOccupancyOccupant.occupantProvince || "") +
"<br />" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantPostalCode || "") +
"</td>") +
("<td>" +
(lotOccupancyOccupant.occupantPhoneNumber
? cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) + "<br />"
: "") +
(lotOccupancyOccupant.occupantEmailAddress
? cityssm.escapeHTML(lotOccupancyOccupant.occupantEmailAddress)
: "") +
"</td>") +
("<td>" + cityssm.escapeHTML(lotOccupancyOccupant.occupantComment) + "</td>") +
('<td class="is-hidden-print">' +
'<div class="buttons are-small is-justify-content-end">' +
('<button class="button is-primary button--edit" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
" <span>Edit</span>" +
"</button>") +
('<button class="button is-light is-danger button--delete" data-tooltip="Delete ' +
cityssm.escapeHTML(exports.aliases.occupant) +
'" type="button" aria-label="Delete">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>") +
"</div>" +
"</td>");
tableRowElement.querySelector(".button--edit").addEventListener("click", openEditLotOccupancyOccupant);
tableRowElement.querySelector(".button--delete").addEventListener("click", deleteLotOccupancyOccupant);
tableElement.querySelector("tbody").append(tableRowElement);
}
occupantsContainer.append(tableElement);
};
if (isCreate) { if (isCreate) {
const lotOccupantTypeIdElement = document.querySelector("#lotOccupancy--lotOccupantTypeId"); const lotOccupantTypeIdElement = document.querySelector("#lotOccupancy--lotOccupantTypeId");
lotOccupantTypeIdElement.addEventListener("change", () => { lotOccupantTypeIdElement.addEventListener("change", () => {
@ -495,195 +679,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
}); });
} }
else { else {
let lotOccupancyOccupants = exports.lotOccupancyOccupants; lotOccupancyOccupants = exports.lotOccupancyOccupants;
delete exports.lotOccupancyOccupants; delete exports.lotOccupancyOccupants;
const openEditLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotOccupantIndex, 10);
const lotOccupancyOccupant = lotOccupancyOccupants.find((currentLotOccupancyOccupant) => {
return currentLotOccupancyOccupant.lotOccupantIndex === lotOccupantIndex;
});
let editFormElement;
let editCloseModalFunction;
const editOccupant = (submitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doUpdateLotOccupancyOccupant", editFormElement, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
editCloseModalFunction();
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
cityssm.openHtmlModal("lotOccupancy-editOccupant", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupancyId").value = lotOccupancyId;
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantIndex").value = lotOccupantIndex.toString();
const lotOccupantTypeSelectElement = modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId");
let lotOccupantTypeSelected = false;
for (const lotOccupantType of exports.lotOccupantTypes) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupantType.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupantType.lotOccupantType;
if (lotOccupantType.lotOccupantTypeId ===
lotOccupancyOccupant.lotOccupantTypeId) {
optionElement.selected = true;
lotOccupantTypeSelected = true;
}
lotOccupantTypeSelectElement.append(optionElement);
}
if (!lotOccupantTypeSelected) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupancyOccupant.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupancyOccupant.lotOccupantType;
optionElement.selected = true;
lotOccupantTypeSelectElement.append(optionElement);
}
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantName").value = lotOccupancyOccupant.occupantName;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress1").value = lotOccupancyOccupant.occupantAddress1;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress2").value = lotOccupancyOccupant.occupantAddress2;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantCity").value = lotOccupancyOccupant.occupantCity;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantProvince").value = lotOccupancyOccupant.occupantProvince;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPostalCode").value = lotOccupancyOccupant.occupantPostalCode;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPhoneNumber").value = lotOccupancyOccupant.occupantPhoneNumber;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantEmailAddress").value = lotOccupancyOccupant.occupantEmailAddress;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantComment").value = lotOccupancyOccupant.occupantComment;
},
onshown: (modalElement, closeModalFunction) => {
bulmaJS.toggleHtmlClipped();
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId").focus();
editFormElement = modalElement.querySelector("form");
editFormElement.addEventListener("submit", editOccupant);
editCloseModalFunction = closeModalFunction;
},
onremoved: () => {
bulmaJS.toggleHtmlClipped();
}
});
};
const deleteLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = clickEvent.currentTarget.closest("tr")
.dataset.lotOccupantIndex;
const doDelete = () => {
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doDeleteLotOccupancyOccupant", {
lotOccupancyId,
lotOccupantIndex
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Removing " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
bulmaJS.confirm({
title: "Remove " + exports.aliases.occupant + "?",
message: "Are you sure you want to remove this " +
exports.aliases.occupant.toLowerCase() +
"?",
okButton: {
text: "Yes, Remove " + exports.aliases.occupant,
callbackFunction: doDelete
},
contextualColorName: "warning"
});
};
const renderLotOccupancyOccupants = () => {
const occupantsContainer = document.querySelector("#container--lotOccupancyOccupants");
cityssm.clearElement(occupantsContainer);
if (lotOccupancyOccupants.length === 0) {
occupantsContainer.innerHTML =
'<div class="message is-warning">' +
'<p class="message-body">There are no ' +
exports.aliases.occupants.toLowerCase() +
" associated with this record.</p>" +
"</div>";
return;
}
const tableElement = document.createElement("table");
tableElement.className = "table is-fullwidth is-striped is-hoverable";
tableElement.innerHTML =
"<thead><tr>" +
("<th>" + exports.aliases.occupant + "</th>") +
"<th>Address</th>" +
"<th>Other Contact</th>" +
"<th>Comment</th>" +
'<th class="is-hidden-print"><span class="is-sr-only">Options</span></th>' +
"</tr></thead>" +
"<tbody></tbody>";
for (const lotOccupancyOccupant of lotOccupancyOccupants) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantIndex =
lotOccupancyOccupant.lotOccupantIndex.toString();
tableRowElement.innerHTML =
"<td>" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantName || "(No Name)") +
"<br />" +
('<span class="tag">' +
'<i class="fas fa-fw fa-' +
cityssm.escapeHTML(lotOccupancyOccupant.fontAwesomeIconClass) +
'" aria-hidden="true"></i>' +
' <span class="ml-1">' +
cityssm.escapeHTML(lotOccupancyOccupant.lotOccupantType) +
"</span>" +
"</span>") +
"</td>" +
("<td>" +
(lotOccupancyOccupant.occupantAddress1
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress1) + "<br />"
: "") +
(lotOccupancyOccupant.occupantAddress2
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress2) + "<br />"
: "") +
(lotOccupancyOccupant.occupantCity
? cityssm.escapeHTML(lotOccupancyOccupant.occupantCity) + ", "
: "") +
cityssm.escapeHTML(lotOccupancyOccupant.occupantProvince || "") +
"<br />" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantPostalCode || "") +
"</td>") +
("<td>" +
(lotOccupancyOccupant.occupantPhoneNumber
? cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) +
"<br />"
: "") +
(lotOccupancyOccupant.occupantEmailAddress
? cityssm.escapeHTML(lotOccupancyOccupant.occupantEmailAddress)
: "") +
"</td>") +
("<td>" + cityssm.escapeHTML(lotOccupancyOccupant.occupantComment) + "</td>") +
('<td class="is-hidden-print">' +
'<div class="buttons are-small is-justify-content-end">' +
('<button class="button is-primary button--edit" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
" <span>Edit</span>" +
"</button>") +
('<button class="button is-light is-danger button--delete" data-tooltip="Delete ' +
cityssm.escapeHTML(exports.aliases.occupant) +
'" type="button" aria-label="Delete">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>") +
"</div>" +
"</td>");
tableRowElement.querySelector(".button--edit").addEventListener("click", openEditLotOccupancyOccupant);
tableRowElement.querySelector(".button--delete").addEventListener("click", deleteLotOccupancyOccupant);
tableElement.querySelector("tbody").append(tableRowElement);
}
occupantsContainer.append(tableElement);
};
document.querySelector("#button--addOccupant").addEventListener("click", () => { document.querySelector("#button--addOccupant").addEventListener("click", () => {
let addCloseModalFunction; let addCloseModalFunction;
let addFormElement; let addFormElement;
@ -764,8 +761,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
cityssm.escapeHTML(occupant.occupantAddress1 || "") + cityssm.escapeHTML(occupant.occupantAddress1 || "") +
"<br />" + "<br />" +
(occupant.occupantAddress2 (occupant.occupantAddress2
? cityssm.escapeHTML(occupant.occupantAddress2) + ? cityssm.escapeHTML(occupant.occupantAddress2) + "<br />"
"<br />"
: "") + : "") +
cityssm.escapeHTML(occupant.occupantCity || "") + cityssm.escapeHTML(occupant.occupantCity || "") +
", " + ", " +

View File

@ -1,6 +1,190 @@
"use strict"; "use strict";
/* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */ /* eslint-disable @typescript-eslint/no-non-null-assertion, unicorn/prefer-module */
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
let lotOccupancyOccupants;
const openEditLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotOccupantIndex, 10);
const lotOccupancyOccupant = lotOccupancyOccupants.find((currentLotOccupancyOccupant) => {
return currentLotOccupancyOccupant.lotOccupantIndex === lotOccupantIndex;
});
let editFormElement;
let editCloseModalFunction;
const editOccupant = (submitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doUpdateLotOccupancyOccupant", editFormElement, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
editCloseModalFunction();
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
cityssm.openHtmlModal("lotOccupancy-editOccupant", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupancyId").value = lotOccupancyId;
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantIndex").value = lotOccupantIndex.toString();
const lotOccupantTypeSelectElement = modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId");
let lotOccupantTypeSelected = false;
for (const lotOccupantType of exports.lotOccupantTypes) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupantType.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupantType.lotOccupantType;
if (lotOccupantType.lotOccupantTypeId === lotOccupancyOccupant.lotOccupantTypeId) {
optionElement.selected = true;
lotOccupantTypeSelected = true;
}
lotOccupantTypeSelectElement.append(optionElement);
}
if (!lotOccupantTypeSelected) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupancyOccupant.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupancyOccupant.lotOccupantType;
optionElement.selected = true;
lotOccupantTypeSelectElement.append(optionElement);
}
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantName").value = lotOccupancyOccupant.occupantName;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress1").value = lotOccupancyOccupant.occupantAddress1;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress2").value = lotOccupancyOccupant.occupantAddress2;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantCity").value = lotOccupancyOccupant.occupantCity;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantProvince").value = lotOccupancyOccupant.occupantProvince;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPostalCode").value = lotOccupancyOccupant.occupantPostalCode;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPhoneNumber").value = lotOccupancyOccupant.occupantPhoneNumber;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantEmailAddress").value = lotOccupancyOccupant.occupantEmailAddress;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantComment").value = lotOccupancyOccupant.occupantComment;
},
onshown: (modalElement, closeModalFunction) => {
bulmaJS.toggleHtmlClipped();
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId").focus();
editFormElement = modalElement.querySelector("form");
editFormElement.addEventListener("submit", editOccupant);
editCloseModalFunction = closeModalFunction;
},
onremoved: () => {
bulmaJS.toggleHtmlClipped();
}
});
};
const deleteLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = clickEvent.currentTarget.closest("tr").dataset
.lotOccupantIndex;
const doDelete = () => {
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doDeleteLotOccupancyOccupant", {
lotOccupancyId,
lotOccupantIndex
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Removing " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
bulmaJS.confirm({
title: "Remove " + exports.aliases.occupant + "?",
message: "Are you sure you want to remove this " + exports.aliases.occupant.toLowerCase() + "?",
okButton: {
text: "Yes, Remove " + exports.aliases.occupant,
callbackFunction: doDelete
},
contextualColorName: "warning"
});
};
const renderLotOccupancyOccupants = () => {
const occupantsContainer = document.querySelector("#container--lotOccupancyOccupants");
cityssm.clearElement(occupantsContainer);
if (lotOccupancyOccupants.length === 0) {
occupantsContainer.innerHTML =
'<div class="message is-warning">' +
'<p class="message-body">There are no ' +
exports.aliases.occupants.toLowerCase() +
" associated with this record.</p>" +
"</div>";
return;
}
const tableElement = document.createElement("table");
tableElement.className = "table is-fullwidth is-striped is-hoverable";
tableElement.innerHTML =
"<thead><tr>" +
("<th>" + exports.aliases.occupant + "</th>") +
"<th>Address</th>" +
"<th>Other Contact</th>" +
"<th>Comment</th>" +
'<th class="is-hidden-print"><span class="is-sr-only">Options</span></th>' +
"</tr></thead>" +
"<tbody></tbody>";
for (const lotOccupancyOccupant of lotOccupancyOccupants) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantIndex =
lotOccupancyOccupant.lotOccupantIndex.toString();
tableRowElement.innerHTML =
"<td>" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantName || "(No Name)") +
"<br />" +
('<span class="tag">' +
'<i class="fas fa-fw fa-' +
cityssm.escapeHTML(lotOccupancyOccupant.fontAwesomeIconClass) +
'" aria-hidden="true"></i>' +
' <span class="ml-1">' +
cityssm.escapeHTML(lotOccupancyOccupant.lotOccupantType) +
"</span>" +
"</span>") +
"</td>" +
("<td>" +
(lotOccupancyOccupant.occupantAddress1
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress1) + "<br />"
: "") +
(lotOccupancyOccupant.occupantAddress2
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress2) + "<br />"
: "") +
(lotOccupancyOccupant.occupantCity
? cityssm.escapeHTML(lotOccupancyOccupant.occupantCity) + ", "
: "") +
cityssm.escapeHTML(lotOccupancyOccupant.occupantProvince || "") +
"<br />" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantPostalCode || "") +
"</td>") +
("<td>" +
(lotOccupancyOccupant.occupantPhoneNumber
? cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) + "<br />"
: "") +
(lotOccupancyOccupant.occupantEmailAddress
? cityssm.escapeHTML(lotOccupancyOccupant.occupantEmailAddress)
: "") +
"</td>") +
("<td>" + cityssm.escapeHTML(lotOccupancyOccupant.occupantComment) + "</td>") +
('<td class="is-hidden-print">' +
'<div class="buttons are-small is-justify-content-end">' +
('<button class="button is-primary button--edit" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
" <span>Edit</span>" +
"</button>") +
('<button class="button is-light is-danger button--delete" data-tooltip="Delete ' +
cityssm.escapeHTML(exports.aliases.occupant) +
'" type="button" aria-label="Delete">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>") +
"</div>" +
"</td>");
tableRowElement.querySelector(".button--edit").addEventListener("click", openEditLotOccupancyOccupant);
tableRowElement.querySelector(".button--delete").addEventListener("click", deleteLotOccupancyOccupant);
tableElement.querySelector("tbody").append(tableRowElement);
}
occupantsContainer.append(tableElement);
};
if (isCreate) { if (isCreate) {
const lotOccupantTypeIdElement = document.querySelector("#lotOccupancy--lotOccupantTypeId"); const lotOccupantTypeIdElement = document.querySelector("#lotOccupancy--lotOccupantTypeId");
lotOccupantTypeIdElement.addEventListener("change", () => { lotOccupantTypeIdElement.addEventListener("change", () => {
@ -11,195 +195,8 @@ if (isCreate) {
}); });
} }
else { else {
let lotOccupancyOccupants = exports.lotOccupancyOccupants; lotOccupancyOccupants = exports.lotOccupancyOccupants;
delete exports.lotOccupancyOccupants; delete exports.lotOccupancyOccupants;
const openEditLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotOccupantIndex, 10);
const lotOccupancyOccupant = lotOccupancyOccupants.find((currentLotOccupancyOccupant) => {
return currentLotOccupancyOccupant.lotOccupantIndex === lotOccupantIndex;
});
let editFormElement;
let editCloseModalFunction;
const editOccupant = (submitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doUpdateLotOccupancyOccupant", editFormElement, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
editCloseModalFunction();
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
cityssm.openHtmlModal("lotOccupancy-editOccupant", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupancyId").value = lotOccupancyId;
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantIndex").value = lotOccupantIndex.toString();
const lotOccupantTypeSelectElement = modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId");
let lotOccupantTypeSelected = false;
for (const lotOccupantType of exports.lotOccupantTypes) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupantType.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupantType.lotOccupantType;
if (lotOccupantType.lotOccupantTypeId ===
lotOccupancyOccupant.lotOccupantTypeId) {
optionElement.selected = true;
lotOccupantTypeSelected = true;
}
lotOccupantTypeSelectElement.append(optionElement);
}
if (!lotOccupantTypeSelected) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupancyOccupant.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupancyOccupant.lotOccupantType;
optionElement.selected = true;
lotOccupantTypeSelectElement.append(optionElement);
}
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantName").value = lotOccupancyOccupant.occupantName;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress1").value = lotOccupancyOccupant.occupantAddress1;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantAddress2").value = lotOccupancyOccupant.occupantAddress2;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantCity").value = lotOccupancyOccupant.occupantCity;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantProvince").value = lotOccupancyOccupant.occupantProvince;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPostalCode").value = lotOccupancyOccupant.occupantPostalCode;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantPhoneNumber").value = lotOccupancyOccupant.occupantPhoneNumber;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantEmailAddress").value = lotOccupancyOccupant.occupantEmailAddress;
modalElement.querySelector("#lotOccupancyOccupantEdit--occupantComment").value = lotOccupancyOccupant.occupantComment;
},
onshown: (modalElement, closeModalFunction) => {
bulmaJS.toggleHtmlClipped();
modalElement.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId").focus();
editFormElement = modalElement.querySelector("form");
editFormElement.addEventListener("submit", editOccupant);
editCloseModalFunction = closeModalFunction;
},
onremoved: () => {
bulmaJS.toggleHtmlClipped();
}
});
};
const deleteLotOccupancyOccupant = (clickEvent) => {
const lotOccupantIndex = clickEvent.currentTarget.closest("tr")
.dataset.lotOccupantIndex;
const doDelete = () => {
cityssm.postJSON(los.urlPrefix + "/lotOccupancies/doDeleteLotOccupancyOccupant", {
lotOccupancyId,
lotOccupantIndex
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
renderLotOccupancyOccupants();
}
else {
bulmaJS.alert({
title: "Error Removing " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
};
bulmaJS.confirm({
title: "Remove " + exports.aliases.occupant + "?",
message: "Are you sure you want to remove this " +
exports.aliases.occupant.toLowerCase() +
"?",
okButton: {
text: "Yes, Remove " + exports.aliases.occupant,
callbackFunction: doDelete
},
contextualColorName: "warning"
});
};
const renderLotOccupancyOccupants = () => {
const occupantsContainer = document.querySelector("#container--lotOccupancyOccupants");
cityssm.clearElement(occupantsContainer);
if (lotOccupancyOccupants.length === 0) {
occupantsContainer.innerHTML =
'<div class="message is-warning">' +
'<p class="message-body">There are no ' +
exports.aliases.occupants.toLowerCase() +
" associated with this record.</p>" +
"</div>";
return;
}
const tableElement = document.createElement("table");
tableElement.className = "table is-fullwidth is-striped is-hoverable";
tableElement.innerHTML =
"<thead><tr>" +
("<th>" + exports.aliases.occupant + "</th>") +
"<th>Address</th>" +
"<th>Other Contact</th>" +
"<th>Comment</th>" +
'<th class="is-hidden-print"><span class="is-sr-only">Options</span></th>' +
"</tr></thead>" +
"<tbody></tbody>";
for (const lotOccupancyOccupant of lotOccupancyOccupants) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantIndex =
lotOccupancyOccupant.lotOccupantIndex.toString();
tableRowElement.innerHTML =
"<td>" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantName || "(No Name)") +
"<br />" +
('<span class="tag">' +
'<i class="fas fa-fw fa-' +
cityssm.escapeHTML(lotOccupancyOccupant.fontAwesomeIconClass) +
'" aria-hidden="true"></i>' +
' <span class="ml-1">' +
cityssm.escapeHTML(lotOccupancyOccupant.lotOccupantType) +
"</span>" +
"</span>") +
"</td>" +
("<td>" +
(lotOccupancyOccupant.occupantAddress1
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress1) + "<br />"
: "") +
(lotOccupancyOccupant.occupantAddress2
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress2) + "<br />"
: "") +
(lotOccupancyOccupant.occupantCity
? cityssm.escapeHTML(lotOccupancyOccupant.occupantCity) + ", "
: "") +
cityssm.escapeHTML(lotOccupancyOccupant.occupantProvince || "") +
"<br />" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantPostalCode || "") +
"</td>") +
("<td>" +
(lotOccupancyOccupant.occupantPhoneNumber
? cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) +
"<br />"
: "") +
(lotOccupancyOccupant.occupantEmailAddress
? cityssm.escapeHTML(lotOccupancyOccupant.occupantEmailAddress)
: "") +
"</td>") +
("<td>" + cityssm.escapeHTML(lotOccupancyOccupant.occupantComment) + "</td>") +
('<td class="is-hidden-print">' +
'<div class="buttons are-small is-justify-content-end">' +
('<button class="button is-primary button--edit" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
" <span>Edit</span>" +
"</button>") +
('<button class="button is-light is-danger button--delete" data-tooltip="Delete ' +
cityssm.escapeHTML(exports.aliases.occupant) +
'" type="button" aria-label="Delete">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>") +
"</div>" +
"</td>");
tableRowElement.querySelector(".button--edit").addEventListener("click", openEditLotOccupancyOccupant);
tableRowElement.querySelector(".button--delete").addEventListener("click", deleteLotOccupancyOccupant);
tableElement.querySelector("tbody").append(tableRowElement);
}
occupantsContainer.append(tableElement);
};
document.querySelector("#button--addOccupant").addEventListener("click", () => { document.querySelector("#button--addOccupant").addEventListener("click", () => {
let addCloseModalFunction; let addCloseModalFunction;
let addFormElement; let addFormElement;
@ -280,8 +277,7 @@ else {
cityssm.escapeHTML(occupant.occupantAddress1 || "") + cityssm.escapeHTML(occupant.occupantAddress1 || "") +
"<br />" + "<br />" +
(occupant.occupantAddress2 (occupant.occupantAddress2
? cityssm.escapeHTML(occupant.occupantAddress2) + ? cityssm.escapeHTML(occupant.occupantAddress2) + "<br />"
"<br />"
: "") + : "") +
cityssm.escapeHTML(occupant.occupantCity || "") + cityssm.escapeHTML(occupant.occupantCity || "") +
", " + ", " +

View File

@ -16,6 +16,305 @@ declare const lotOccupancyId: string;
declare const isCreate: boolean; declare const isCreate: boolean;
declare const formElement: HTMLFormElement; declare const formElement: HTMLFormElement;
let lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[];
const openEditLotOccupancyOccupant = (clickEvent: Event) => {
const lotOccupantIndex = Number.parseInt(
(clickEvent.currentTarget as HTMLElement).closest("tr")!.dataset.lotOccupantIndex!,
10
);
const lotOccupancyOccupant = lotOccupancyOccupants.find((currentLotOccupancyOccupant) => {
return currentLotOccupancyOccupant.lotOccupantIndex === lotOccupantIndex;
})!;
let editFormElement: HTMLFormElement;
let editCloseModalFunction: () => void;
const editOccupant = (submitEvent: SubmitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(
los.urlPrefix + "/lotOccupancies/doUpdateLotOccupancyOccupant",
editFormElement,
(responseJSON: {
success: boolean;
errorMessage?: string;
lotOccupancyOccupants?: recordTypes.LotOccupancyOccupant[];
}) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants!;
editCloseModalFunction();
renderLotOccupancyOccupants();
} else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
}
);
};
cityssm.openHtmlModal("lotOccupancy-editOccupant", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupancyId"
) as HTMLInputElement
).value = lotOccupancyId;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupantIndex"
) as HTMLInputElement
).value = lotOccupantIndex.toString();
const lotOccupantTypeSelectElement = modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupantTypeId"
) as HTMLSelectElement;
let lotOccupantTypeSelected = false;
for (const lotOccupantType of exports.lotOccupantTypes as recordTypes.LotOccupantType[]) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupantType.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupantType.lotOccupantType;
if (lotOccupantType.lotOccupantTypeId === lotOccupancyOccupant.lotOccupantTypeId) {
optionElement.selected = true;
lotOccupantTypeSelected = true;
}
lotOccupantTypeSelectElement.append(optionElement);
}
if (!lotOccupantTypeSelected) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupancyOccupant.lotOccupantTypeId!.toString();
optionElement.textContent = lotOccupancyOccupant.lotOccupantType as string;
optionElement.selected = true;
lotOccupantTypeSelectElement.append(optionElement);
}
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantName"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantName!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantAddress1"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantAddress1!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantAddress2"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantAddress2!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantCity"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantCity!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantProvince"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantProvince!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantPostalCode"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantPostalCode!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantPhoneNumber"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantPhoneNumber!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantEmailAddress"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantEmailAddress!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantComment"
) as HTMLTextAreaElement
).value = lotOccupancyOccupant.occupantComment!;
},
onshown: (modalElement, closeModalFunction) => {
bulmaJS.toggleHtmlClipped();
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupantTypeId"
) as HTMLInputElement
).focus();
editFormElement = modalElement.querySelector("form")!;
editFormElement.addEventListener("submit", editOccupant);
editCloseModalFunction = closeModalFunction;
},
onremoved: () => {
bulmaJS.toggleHtmlClipped();
}
});
};
const deleteLotOccupancyOccupant = (clickEvent: Event) => {
const lotOccupantIndex = (clickEvent.currentTarget as HTMLElement).closest("tr")!.dataset
.lotOccupantIndex;
const doDelete = () => {
cityssm.postJSON(
los.urlPrefix + "/lotOccupancies/doDeleteLotOccupancyOccupant",
{
lotOccupancyId,
lotOccupantIndex
},
(responseJSON: {
success: boolean;
errorMessage?: string;
lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[];
}) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
renderLotOccupancyOccupants();
} else {
bulmaJS.alert({
title: "Error Removing " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
}
);
};
bulmaJS.confirm({
title: "Remove " + exports.aliases.occupant + "?",
message:
"Are you sure you want to remove this " + exports.aliases.occupant.toLowerCase() + "?",
okButton: {
text: "Yes, Remove " + exports.aliases.occupant,
callbackFunction: doDelete
},
contextualColorName: "warning"
});
};
const renderLotOccupancyOccupants = () => {
const occupantsContainer = document.querySelector(
"#container--lotOccupancyOccupants"
) as HTMLElement;
cityssm.clearElement(occupantsContainer);
if (lotOccupancyOccupants.length === 0) {
occupantsContainer.innerHTML =
'<div class="message is-warning">' +
'<p class="message-body">There are no ' +
exports.aliases.occupants.toLowerCase() +
" associated with this record.</p>" +
"</div>";
return;
}
const tableElement = document.createElement("table");
tableElement.className = "table is-fullwidth is-striped is-hoverable";
tableElement.innerHTML =
"<thead><tr>" +
("<th>" + exports.aliases.occupant + "</th>") +
"<th>Address</th>" +
"<th>Other Contact</th>" +
"<th>Comment</th>" +
'<th class="is-hidden-print"><span class="is-sr-only">Options</span></th>' +
"</tr></thead>" +
"<tbody></tbody>";
for (const lotOccupancyOccupant of lotOccupancyOccupants) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantIndex =
lotOccupancyOccupant.lotOccupantIndex!.toString();
tableRowElement.innerHTML =
"<td>" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantName || "(No Name)") +
"<br />" +
('<span class="tag">' +
'<i class="fas fa-fw fa-' +
cityssm.escapeHTML(lotOccupancyOccupant.fontAwesomeIconClass!) +
'" aria-hidden="true"></i>' +
' <span class="ml-1">' +
cityssm.escapeHTML(lotOccupancyOccupant.lotOccupantType!) +
"</span>" +
"</span>") +
"</td>" +
("<td>" +
(lotOccupancyOccupant.occupantAddress1
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress1) + "<br />"
: "") +
(lotOccupancyOccupant.occupantAddress2
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress2) + "<br />"
: "") +
(lotOccupancyOccupant.occupantCity
? cityssm.escapeHTML(lotOccupancyOccupant.occupantCity) + ", "
: "") +
cityssm.escapeHTML(lotOccupancyOccupant.occupantProvince || "") +
"<br />" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantPostalCode || "") +
"</td>") +
("<td>" +
(lotOccupancyOccupant.occupantPhoneNumber
? cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) + "<br />"
: "") +
(lotOccupancyOccupant.occupantEmailAddress
? cityssm.escapeHTML(lotOccupancyOccupant.occupantEmailAddress)
: "") +
"</td>") +
("<td>" + cityssm.escapeHTML(lotOccupancyOccupant.occupantComment!) + "</td>") +
('<td class="is-hidden-print">' +
'<div class="buttons are-small is-justify-content-end">' +
('<button class="button is-primary button--edit" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
" <span>Edit</span>" +
"</button>") +
('<button class="button is-light is-danger button--delete" data-tooltip="Delete ' +
cityssm.escapeHTML(exports.aliases.occupant) +
'" type="button" aria-label="Delete">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>") +
"</div>" +
"</td>");
(tableRowElement.querySelector(".button--edit") as HTMLButtonElement).addEventListener(
"click",
openEditLotOccupancyOccupant
);
(tableRowElement.querySelector(".button--delete") as HTMLButtonElement).addEventListener(
"click",
deleteLotOccupancyOccupant
);
tableElement.querySelector("tbody")!.append(tableRowElement);
}
occupantsContainer.append(tableElement);
};
if (isCreate) { if (isCreate) {
const lotOccupantTypeIdElement = document.querySelector( const lotOccupantTypeIdElement = document.querySelector(
"#lotOccupancy--lotOccupantTypeId" "#lotOccupancy--lotOccupantTypeId"
@ -31,314 +330,9 @@ if (isCreate) {
} }
}); });
} else { } else {
let lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = lotOccupancyOccupants = exports.lotOccupancyOccupants;
exports.lotOccupancyOccupants;
delete exports.lotOccupancyOccupants; delete exports.lotOccupancyOccupants;
const openEditLotOccupancyOccupant = (clickEvent: Event) => {
const lotOccupantIndex = Number.parseInt(
(clickEvent.currentTarget as HTMLElement).closest("tr")!.dataset.lotOccupantIndex!,
10
);
const lotOccupancyOccupant = lotOccupancyOccupants.find(
(currentLotOccupancyOccupant) => {
return currentLotOccupancyOccupant.lotOccupantIndex === lotOccupantIndex;
}
)!;
let editFormElement: HTMLFormElement;
let editCloseModalFunction: () => void;
const editOccupant = (submitEvent: SubmitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(
los.urlPrefix + "/lotOccupancies/doUpdateLotOccupancyOccupant",
editFormElement,
(responseJSON: {
success: boolean;
errorMessage?: string;
lotOccupancyOccupants?: recordTypes.LotOccupancyOccupant[];
}) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants!;
editCloseModalFunction();
renderLotOccupancyOccupants();
} else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
}
);
};
cityssm.openHtmlModal("lotOccupancy-editOccupant", {
onshow: (modalElement) => {
los.populateAliases(modalElement);
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupancyId"
) as HTMLInputElement
).value = lotOccupancyId;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupantIndex"
) as HTMLInputElement
).value = lotOccupantIndex.toString();
const lotOccupantTypeSelectElement = modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupantTypeId"
) as HTMLSelectElement;
let lotOccupantTypeSelected = false;
for (const lotOccupantType of exports.lotOccupantTypes as recordTypes.LotOccupantType[]) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupantType.lotOccupantTypeId.toString();
optionElement.textContent = lotOccupantType.lotOccupantType;
if (
lotOccupantType.lotOccupantTypeId ===
lotOccupancyOccupant.lotOccupantTypeId
) {
optionElement.selected = true;
lotOccupantTypeSelected = true;
}
lotOccupantTypeSelectElement.append(optionElement);
}
if (!lotOccupantTypeSelected) {
const optionElement = document.createElement("option");
optionElement.value = lotOccupancyOccupant.lotOccupantTypeId!.toString();
optionElement.textContent = lotOccupancyOccupant.lotOccupantType as string;
optionElement.selected = true;
lotOccupantTypeSelectElement.append(optionElement);
}
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantName"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantName!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantAddress1"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantAddress1!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantAddress2"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantAddress2!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantCity"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantCity!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantProvince"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantProvince!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantPostalCode"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantPostalCode!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantPhoneNumber"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantPhoneNumber!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantEmailAddress"
) as HTMLInputElement
).value = lotOccupancyOccupant.occupantEmailAddress!;
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--occupantComment"
) as HTMLTextAreaElement
).value = lotOccupancyOccupant.occupantComment!;
},
onshown: (modalElement, closeModalFunction) => {
bulmaJS.toggleHtmlClipped();
(
modalElement.querySelector(
"#lotOccupancyOccupantEdit--lotOccupantTypeId"
) as HTMLInputElement
).focus();
editFormElement = modalElement.querySelector("form")!;
editFormElement.addEventListener("submit", editOccupant);
editCloseModalFunction = closeModalFunction;
},
onremoved: () => {
bulmaJS.toggleHtmlClipped();
}
});
};
const deleteLotOccupancyOccupant = (clickEvent: Event) => {
const lotOccupantIndex = (clickEvent.currentTarget as HTMLElement).closest("tr")!
.dataset.lotOccupantIndex;
const doDelete = () => {
cityssm.postJSON(
los.urlPrefix + "/lotOccupancies/doDeleteLotOccupancyOccupant",
{
lotOccupancyId,
lotOccupantIndex
},
(responseJSON: {
success: boolean;
errorMessage?: string;
lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[];
}) => {
if (responseJSON.success) {
lotOccupancyOccupants = responseJSON.lotOccupancyOccupants;
renderLotOccupancyOccupants();
} else {
bulmaJS.alert({
title: "Error Removing " + exports.aliases.occupant,
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
}
);
};
bulmaJS.confirm({
title: "Remove " + exports.aliases.occupant + "?",
message:
"Are you sure you want to remove this " +
exports.aliases.occupant.toLowerCase() +
"?",
okButton: {
text: "Yes, Remove " + exports.aliases.occupant,
callbackFunction: doDelete
},
contextualColorName: "warning"
});
};
const renderLotOccupancyOccupants = () => {
const occupantsContainer = document.querySelector(
"#container--lotOccupancyOccupants"
) as HTMLElement;
cityssm.clearElement(occupantsContainer);
if (lotOccupancyOccupants.length === 0) {
occupantsContainer.innerHTML =
'<div class="message is-warning">' +
'<p class="message-body">There are no ' +
exports.aliases.occupants.toLowerCase() +
" associated with this record.</p>" +
"</div>";
return;
}
const tableElement = document.createElement("table");
tableElement.className = "table is-fullwidth is-striped is-hoverable";
tableElement.innerHTML =
"<thead><tr>" +
("<th>" + exports.aliases.occupant + "</th>") +
"<th>Address</th>" +
"<th>Other Contact</th>" +
"<th>Comment</th>" +
'<th class="is-hidden-print"><span class="is-sr-only">Options</span></th>' +
"</tr></thead>" +
"<tbody></tbody>";
for (const lotOccupancyOccupant of lotOccupancyOccupants) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantIndex =
lotOccupancyOccupant.lotOccupantIndex!.toString();
tableRowElement.innerHTML =
"<td>" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantName || "(No Name)") +
"<br />" +
('<span class="tag">' +
'<i class="fas fa-fw fa-' +
cityssm.escapeHTML(lotOccupancyOccupant.fontAwesomeIconClass!) +
'" aria-hidden="true"></i>' +
' <span class="ml-1">' +
cityssm.escapeHTML(lotOccupancyOccupant.lotOccupantType!) +
"</span>" +
"</span>") +
"</td>" +
("<td>" +
(lotOccupancyOccupant.occupantAddress1
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress1) + "<br />"
: "") +
(lotOccupancyOccupant.occupantAddress2
? cityssm.escapeHTML(lotOccupancyOccupant.occupantAddress2) + "<br />"
: "") +
(lotOccupancyOccupant.occupantCity
? cityssm.escapeHTML(lotOccupancyOccupant.occupantCity) + ", "
: "") +
cityssm.escapeHTML(lotOccupancyOccupant.occupantProvince || "") +
"<br />" +
cityssm.escapeHTML(lotOccupancyOccupant.occupantPostalCode || "") +
"</td>") +
("<td>" +
(lotOccupancyOccupant.occupantPhoneNumber
? cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) +
"<br />"
: "") +
(lotOccupancyOccupant.occupantEmailAddress
? cityssm.escapeHTML(lotOccupancyOccupant.occupantEmailAddress)
: "") +
"</td>") +
("<td>" + cityssm.escapeHTML(lotOccupancyOccupant.occupantComment!) + "</td>") +
('<td class="is-hidden-print">' +
'<div class="buttons are-small is-justify-content-end">' +
('<button class="button is-primary button--edit" type="button">' +
'<span class="icon is-small"><i class="fas fa-pencil-alt" aria-hidden="true"></i></span>' +
" <span>Edit</span>" +
"</button>") +
('<button class="button is-light is-danger button--delete" data-tooltip="Delete ' +
cityssm.escapeHTML(exports.aliases.occupant) +
'" type="button" aria-label="Delete">' +
'<i class="fas fa-trash" aria-hidden="true"></i>' +
"</button>") +
"</div>" +
"</td>");
(
tableRowElement.querySelector(".button--edit") as HTMLButtonElement
).addEventListener("click", openEditLotOccupancyOccupant);
(
tableRowElement.querySelector(".button--delete") as HTMLButtonElement
).addEventListener("click", deleteLotOccupancyOccupant);
tableElement.querySelector("tbody")!.append(tableRowElement);
}
occupantsContainer.append(tableElement);
};
(document.querySelector("#button--addOccupant") as HTMLButtonElement).addEventListener( (document.querySelector("#button--addOccupant") as HTMLButtonElement).addEventListener(
"click", "click",
() => { () => {
@ -464,8 +458,7 @@ if (isCreate) {
cityssm.escapeHTML(occupant.occupantAddress1 || "") + cityssm.escapeHTML(occupant.occupantAddress1 || "") +
"<br />" + "<br />" +
(occupant.occupantAddress2 (occupant.occupantAddress2
? cityssm.escapeHTML(occupant.occupantAddress2) + ? cityssm.escapeHTML(occupant.occupantAddress2) + "<br />"
"<br />"
: "") + : "") +
cityssm.escapeHTML(occupant.occupantCity || "") + cityssm.escapeHTML(occupant.occupantCity || "") +
", " + ", " +

File diff suppressed because one or more lines are too long

View File

@ -32,7 +32,7 @@ export interface LotType extends Record {
lotTypeFields?: LotTypeField[]; lotTypeFields?: LotTypeField[];
} }
export interface LotTypeField extends Record { export interface LotTypeField extends Record {
lotTypeFieldId?: number; lotTypeFieldId: number;
lotTypeField?: string; lotTypeField?: string;
lotTypeId?: number; lotTypeId?: number;
lotType: LotType; lotType: LotType;
@ -78,7 +78,6 @@ export interface LotComment extends Record {
} }
export interface LotField extends LotTypeField, Record { export interface LotField extends LotTypeField, Record {
lotId?: number; lotId?: number;
lotTypeFieldId?: number;
lotFieldValue?: string; lotFieldValue?: string;
} }
export interface OccupancyType extends Record { export interface OccupancyType extends Record {
@ -106,13 +105,13 @@ export interface LotOccupantType extends Record {
orderNumber?: number; orderNumber?: number;
} }
export interface FeeCategory extends Record { export interface FeeCategory extends Record {
feeCategoryId?: number; feeCategoryId: number;
feeCategory?: string; feeCategory: string;
fees?: Fee[]; fees: Fee[];
orderNumber?: number; orderNumber?: number;
} }
export interface Fee extends Record { export interface Fee extends Record {
feeId?: number; feeId: number;
feeCategoryId?: number; feeCategoryId?: number;
feeCategory?: string; feeCategory?: string;
feeName?: string; feeName?: string;
@ -132,11 +131,7 @@ export interface Fee extends Record {
} }
export interface LotOccupancyFee extends Fee, Record { export interface LotOccupancyFee extends Fee, Record {
lotOccupancyId?: number; lotOccupancyId?: number;
feeId?: number;
feeName?: string;
quantity?: number; quantity?: number;
feeAmount?: number;
taxAmount?: number;
} }
export interface LotOccupancyTransaction extends Record { export interface LotOccupancyTransaction extends Record {
lotOccupancyId?: number; lotOccupancyId?: number;

View File

@ -44,7 +44,7 @@ export interface LotType extends Record {
} }
export interface LotTypeField extends Record { export interface LotTypeField extends Record {
lotTypeFieldId?: number; lotTypeFieldId: number;
lotTypeField?: string; lotTypeField?: string;
lotTypeId?: number; lotTypeId?: number;
@ -107,7 +107,6 @@ export interface LotComment extends Record {
export interface LotField extends LotTypeField, Record { export interface LotField extends LotTypeField, Record {
lotId?: number; lotId?: number;
lotTypeFieldId?: number;
lotFieldValue?: string; lotFieldValue?: string;
} }
@ -139,14 +138,14 @@ export interface LotOccupantType extends Record {
} }
export interface FeeCategory extends Record { export interface FeeCategory extends Record {
feeCategoryId?: number; feeCategoryId: number;
feeCategory?: string; feeCategory: string;
fees?: Fee[]; fees: Fee[];
orderNumber?: number; orderNumber?: number;
} }
export interface Fee extends Record { export interface Fee extends Record {
feeId?: number; feeId: number;
feeCategoryId?: number; feeCategoryId?: number;
feeCategory?: string; feeCategory?: string;
@ -176,13 +175,7 @@ export interface Fee extends Record {
export interface LotOccupancyFee extends Fee, Record { export interface LotOccupancyFee extends Fee, Record {
lotOccupancyId?: number; lotOccupancyId?: number;
feeId?: number;
feeName?: string;
quantity?: number; quantity?: number;
feeAmount?: number;
taxAmount?: number;
} }
export interface LotOccupancyTransaction extends Record { export interface LotOccupancyTransaction extends Record {