diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.d.ts b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.d.ts new file mode 100644 index 00000000..9621c611 --- /dev/null +++ b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.d.ts @@ -0,0 +1,3 @@ +import type { RequestHandler } from "express"; +export declare const handler: RequestHandler; +export default handler; diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js new file mode 100644 index 00000000..b298c4ac --- /dev/null +++ b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js @@ -0,0 +1,11 @@ +import { addLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/addLotOccupancyOccupant.js"; +import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js"; +export const handler = async (request, response) => { + addLotOccupancyOccupant(request.body, request.session); + const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); + response.json({ + success: true, + lotOccupancyOccupants + }); +}; +export default handler; diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts new file mode 100644 index 00000000..94a0d1aa --- /dev/null +++ b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts @@ -0,0 +1,27 @@ +import type { + RequestHandler +} from "express"; + +import { + addLotOccupancyOccupant +} from "../../helpers/lotOccupancyDB/addLotOccupancyOccupant.js"; + +import { + getLotOccupancyOccupants +} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js"; + + +export const handler: RequestHandler = async (request, response) => { + + addLotOccupancyOccupant(request.body, request.session); + + const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); + + response.json({ + success: true, + lotOccupancyOccupants + }); +}; + + +export default handler; \ No newline at end of file diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.d.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.d.ts new file mode 100644 index 00000000..9621c611 --- /dev/null +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.d.ts @@ -0,0 +1,3 @@ +import type { RequestHandler } from "express"; +export declare const handler: RequestHandler; +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.js b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.js new file mode 100644 index 00000000..6a0907b0 --- /dev/null +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.js @@ -0,0 +1,11 @@ +import { deleteLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js"; +import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js"; +export const handler = async (request, response) => { + deleteLotOccupancyOccupant(request.body.lotOccupancyId, request.body.lotOccupantIndex, request.session); + const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); + response.json({ + success: true, + lotOccupancyOccupants + }); +}; +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts new file mode 100644 index 00000000..adea17fc --- /dev/null +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts @@ -0,0 +1,27 @@ +import type { + RequestHandler +} from "express"; + +import { + deleteLotOccupancyOccupant +} from "../../helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js"; + +import { + getLotOccupancyOccupants +} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js"; + + +export const handler: RequestHandler = async (request, response) => { + + deleteLotOccupancyOccupant(request.body.lotOccupancyId, request.body.lotOccupantIndex, request.session); + + const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); + + response.json({ + success: true, + lotOccupancyOccupants + }); +}; + + +export default handler; \ No newline at end of file diff --git a/handlers/lotOccupancies-post/doSearchLotOccupancies.ts b/handlers/lotOccupancies-post/doSearchLotOccupancies.ts index 3b5ea26a..7870fe89 100644 --- a/handlers/lotOccupancies-post/doSearchLotOccupancies.ts +++ b/handlers/lotOccupancies-post/doSearchLotOccupancies.ts @@ -1,20 +1,24 @@ -import type { RequestHandler } from "express"; +import type { + RequestHandler +} from "express"; -import { getLotOccupancies } from "../../helpers/lotOccupancyDB/getLotOccupancies.js"; +import { + getLotOccupancies +} from "../../helpers/lotOccupancyDB/getLotOccupancies.js"; export const handler: RequestHandler = async (request, response) => { - const result = getLotOccupancies(request.body, { - limit: request.body.limit, - offset: request.body.offset, - includeOccupants: true - }); + const result = getLotOccupancies(request.body, { + limit: request.body.limit, + offset: request.body.offset, + includeOccupants: true + }); - response.json({ - count: result.count, - lotOccupancies: result.lotOccupancies - }); + response.json({ + count: result.count, + lotOccupancies: result.lotOccupancies + }); }; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts b/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts index 4070100b..719ff058 100644 --- a/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts @@ -1,16 +1,20 @@ -import type { RequestHandler } from "express"; +import type { + RequestHandler +} from "express"; -import { updateLotOccupancy } from "../../helpers/lotOccupancyDB/updateLotOccupancy.js"; +import { + updateLotOccupancy +} from "../../helpers/lotOccupancyDB/updateLotOccupancy.js"; export const handler: RequestHandler = async (request, response) => { - const success = updateLotOccupancy(request.body, request.session); + const success = updateLotOccupancy(request.body, request.session); - response.json({ - success, - lotOccupancyId: request.body.lotOccupancyId - }); + response.json({ + success, + lotOccupancyId: request.body.lotOccupancyId + }); }; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.d.ts b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.d.ts new file mode 100644 index 00000000..9621c611 --- /dev/null +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.d.ts @@ -0,0 +1,3 @@ +import type { RequestHandler } from "express"; +export declare const handler: RequestHandler; +export default handler; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js new file mode 100644 index 00000000..b7ed4331 --- /dev/null +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js @@ -0,0 +1,11 @@ +import { updateLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/updateLotOccupancyOccupant.js"; +import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js"; +export const handler = async (request, response) => { + updateLotOccupancyOccupant(request.body, request.session); + const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); + response.json({ + success: true, + lotOccupancyOccupants + }); +}; +export default handler; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts new file mode 100644 index 00000000..7cd98440 --- /dev/null +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts @@ -0,0 +1,27 @@ +import type { + RequestHandler +} from "express"; + +import { + updateLotOccupancyOccupant +} from "../../helpers/lotOccupancyDB/updateLotOccupancyOccupant.js"; + +import { + getLotOccupancyOccupants +} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js"; + + +export const handler: RequestHandler = async (request, response) => { + + updateLotOccupancyOccupant(request.body, request.session); + + const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); + + response.json({ + success: true, + lotOccupancyOccupants + }); +}; + + +export default handler; \ No newline at end of file diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.d.ts b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.d.ts new file mode 100644 index 00000000..1716e61e --- /dev/null +++ b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.d.ts @@ -0,0 +1,3 @@ +import type * as recordTypes from "../../types/recordTypes"; +export declare const deleteLotOccupancyOccupant: (lotOccupancyId: number | string, lotOccupantIndex: number | string, requestSession: recordTypes.PartialSession) => boolean; +export default deleteLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js new file mode 100644 index 00000000..cb00dbfa --- /dev/null +++ b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js @@ -0,0 +1,16 @@ +import sqlite from "better-sqlite3"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const deleteLotOccupancyOccupant = (lotOccupancyId, lotOccupantIndex, requestSession) => { + const database = sqlite(databasePath); + const rightNowMillis = Date.now(); + const result = database + .prepare("update LotOccupancyOccupants" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotOccupancyId = ?" + + " and lotOccupantIndex = ?") + .run(requestSession.user.userName, rightNowMillis, lotOccupancyId, lotOccupantIndex); + database.close(); + return (result.changes > 0); +}; +export default deleteLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts new file mode 100644 index 00000000..de217a3e --- /dev/null +++ b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts @@ -0,0 +1,36 @@ +import sqlite from "better-sqlite3"; + +import { + lotOccupancyDB as databasePath +} from "../../data/databasePaths.js"; + +import type * as recordTypes from "../../types/recordTypes"; + + +export const deleteLotOccupancyOccupant = + (lotOccupancyId: number | string, + lotOccupantIndex: number | string, + requestSession: recordTypes.PartialSession): boolean => { + + const database = sqlite(databasePath); + + const rightNowMillis = Date.now(); + + const result = database + .prepare("update LotOccupancyOccupants" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotOccupancyId = ?" + + " and lotOccupantIndex = ?") + .run(requestSession.user.userName, + rightNowMillis, + lotOccupancyId, + lotOccupantIndex); + + database.close(); + + return (result.changes > 0); + }; + + +export default deleteLotOccupancyOccupant; \ No newline at end of file diff --git a/helpers/lotOccupancyDB/updateLotOccupancyOccupant.d.ts b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.d.ts new file mode 100644 index 00000000..5a2476d5 --- /dev/null +++ b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.d.ts @@ -0,0 +1,15 @@ +import type * as recordTypes from "../../types/recordTypes"; +interface UpdateLotOccupancyOccupantForm { + lotOccupancyId: string | number; + lotOccupantIndex: string | number; + lotOccupantTypeId: string | number; + occupantName: string; + occupantAddress1: string; + occupantAddress2: string; + occupantCity: string; + occupantProvince: string; + occupantPostalCode: string; + occupantPhoneNumber: string; +} +export declare const updateLotOccupancyOccupant: (lotOccupancyOccupantForm: UpdateLotOccupancyOccupantForm, requestSession: recordTypes.PartialSession) => boolean; +export default updateLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/updateLotOccupancyOccupant.js b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.js new file mode 100644 index 00000000..713e5ec9 --- /dev/null +++ b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.js @@ -0,0 +1,25 @@ +import sqlite from "better-sqlite3"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const updateLotOccupancyOccupant = (lotOccupancyOccupantForm, requestSession) => { + const database = sqlite(databasePath); + const rightNowMillis = Date.now(); + const results = database + .prepare("update LotOccupancyOccupants" + + " set occupantName = ?," + + " occupantAddress1 = ?," + + " occupantAddress2 = ?," + + " occupantCity = ?," + + " occupantProvince = ?," + + " occupantPostalCode = ?," + + " occupantPhoneNumber = ?," + + " lotOccupantTypeId = ?," + + " recordUpdate_userName = ?," + + " recordUpdate_timeMillis = ?" + + " where recordDelete_timeMillis is null" + + " and lotOccupancyId = ?" + + " and lotOccupantIndex = ?") + .run(lotOccupancyOccupantForm.occupantName, lotOccupancyOccupantForm.occupantAddress1, lotOccupancyOccupantForm.occupantAddress2, lotOccupancyOccupantForm.occupantCity, lotOccupancyOccupantForm.occupantProvince, lotOccupancyOccupantForm.occupantPostalCode, lotOccupancyOccupantForm.occupantPhoneNumber, lotOccupancyOccupantForm.lotOccupantTypeId, requestSession.user.userName, rightNowMillis, lotOccupancyOccupantForm.lotOccupancyId, lotOccupancyOccupantForm.lotOccupantIndex); + database.close(); + return results.changes > 0; +}; +export default updateLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts new file mode 100644 index 00000000..669dbde6 --- /dev/null +++ b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts @@ -0,0 +1,65 @@ +import sqlite from "better-sqlite3"; + +import { + lotOccupancyDB as databasePath +} from "../../data/databasePaths.js"; + +import type * as recordTypes from "../../types/recordTypes"; + + +interface UpdateLotOccupancyOccupantForm { + lotOccupancyId: string | number; + lotOccupantIndex: string | number; + lotOccupantTypeId: string | number; + occupantName: string; + occupantAddress1: string; + occupantAddress2: string; + occupantCity: string; + occupantProvince: string; + occupantPostalCode: string; + occupantPhoneNumber: string; +} + + +export const updateLotOccupancyOccupant = + (lotOccupancyOccupantForm: UpdateLotOccupancyOccupantForm, requestSession: recordTypes.PartialSession): boolean => { + + const database = sqlite(databasePath); + + const rightNowMillis = Date.now(); + + const results = database + .prepare("update LotOccupancyOccupants" + + " set occupantName = ?," + + " occupantAddress1 = ?," + + " occupantAddress2 = ?," + + " occupantCity = ?," + + " occupantProvince = ?," + + " occupantPostalCode = ?," + + " occupantPhoneNumber = ?," + + " lotOccupantTypeId = ?," + + " recordUpdate_userName = ?," + + " recordUpdate_timeMillis = ?" + + " where recordDelete_timeMillis is null" + + " and lotOccupancyId = ?" + + " and lotOccupantIndex = ?") + .run(lotOccupancyOccupantForm.occupantName, + lotOccupancyOccupantForm.occupantAddress1, + lotOccupancyOccupantForm.occupantAddress2, + lotOccupancyOccupantForm.occupantCity, + lotOccupancyOccupantForm.occupantProvince, + lotOccupancyOccupantForm.occupantPostalCode, + lotOccupancyOccupantForm.occupantPhoneNumber, + lotOccupancyOccupantForm.lotOccupantTypeId, + requestSession.user.userName, + rightNowMillis, + lotOccupancyOccupantForm.lotOccupancyId, + lotOccupancyOccupantForm.lotOccupantIndex); + + database.close(); + + return results.changes > 0; + }; + + +export default updateLotOccupancyOccupant; \ No newline at end of file diff --git a/public-typescript/lotOccupancyEdit.js b/public-typescript/lotOccupancyEdit.js index 41e72c42..6c815de5 100644 --- a/public-typescript/lotOccupancyEdit.js +++ b/public-typescript/lotOccupancyEdit.js @@ -158,6 +158,103 @@ Object.defineProperty(exports, "__esModule", { value: true }); los.initializeUnlockFieldButtons(formElement); if (!isCreate) { let lotOccupancyOccupants = 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(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; + }, + onshown: (modalElement, closeModalFunction) => { + bulmaJS.toggleHtmlClipped(); + 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(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); @@ -200,16 +297,54 @@ Object.defineProperty(exports, "__esModule", { value: true }); "") + "" + ""); + 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", () => { + let addFormElement; + let addCloseModalFunction; + const addOccupant = (submitEvent) => { + submitEvent.preventDefault(); + cityssm.postJSON(urlPrefix + "/lotOccupancies/doAddLotOccupancyOccupant", addFormElement, (responseJSON) => { + if (responseJSON.success) { + lotOccupancyOccupants = responseJSON.lotOccupancyOccupants; + addCloseModalFunction(); + renderLotOccupancyOccupants(); + } + else { + bulmaJS.alert({ + title: "Error Adding " + exports.aliases.occupant, + message: responseJSON.errorMessage, + contextualColorName: "danger" + }); + } + }); + }; cityssm.openHtmlModal("lotOccupancy-addOccupant", { onshow: (modalElement) => { los.populateAliases(modalElement); + modalElement.querySelector("#lotOccupancyOccupantAdd--lotOccupancyId").value = lotOccupancyId; + const lotOccupantTypeSelectElement = modalElement.querySelector("#lotOccupancyOccupantAdd--lotOccupantTypeId"); + for (const lotOccupantType of exports.lotOccupantTypes) { + const optionElement = document.createElement("option"); + optionElement.value = lotOccupantType.lotOccupantTypeId.toString(); + optionElement.textContent = lotOccupantType.lotOccupantType; + lotOccupantTypeSelectElement.append(optionElement); + } modalElement.querySelector("#lotOccupancyOccupantAdd--occupantCity").value = exports.occupantCityDefault; modalElement.querySelector("#lotOccupancyOccupantAdd--occupantProvince").value = exports.occupantProvinceDefault; + }, + onshown: (modalElement, closeModalFunction) => { + bulmaJS.toggleHtmlClipped(); + addFormElement = modalElement.querySelector("form"); + addFormElement.addEventListener("submit", addOccupant); + addCloseModalFunction = closeModalFunction; + }, + onremoved: () => { + bulmaJS.toggleHtmlClipped(); } }); }); diff --git a/public-typescript/lotOccupancyEdit.ts b/public-typescript/lotOccupancyEdit.ts index 6b82c690..cf438f00 100644 --- a/public-typescript/lotOccupancyEdit.ts +++ b/public-typescript/lotOccupancyEdit.ts @@ -8,7 +8,7 @@ import type { } from "@cityssm/bulma-webapp-js/src/types"; import type { - BulmaJS + BulmaJS, StringConfigProperties } from "@cityssm/bulma-js/types"; declare const cityssm: cityssmGlobal; @@ -249,6 +249,129 @@ declare const bulmaJS: BulmaJS; if (!isCreate) { let lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = 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(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; + }, + onshown: (modalElement, closeModalFunction) => { + + bulmaJS.toggleHtmlClipped(); + + 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(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; @@ -290,17 +413,20 @@ declare const bulmaJS: BulmaJS; "") + ("" + cityssm.escapeHTML(lotOccupancyOccupant.occupantPhoneNumber) + "") + ("" + - "
" + + "
" + ("") + + "" + + " Edit" + + "") + ("") + + "" + + "") + "
" + ""); + tableRowElement.querySelector(".button--edit").addEventListener("click", openEditLotOccupancyOccupant); + tableRowElement.querySelector(".button--delete").addEventListener("click", deleteLotOccupancyOccupant); + tableElement.querySelector("tbody").append(tableRowElement); } @@ -309,12 +435,60 @@ declare const bulmaJS: BulmaJS; document.querySelector("#button--addOccupant").addEventListener("click", () => { + let addFormElement: HTMLFormElement; + let addCloseModalFunction: () => void; + + const addOccupant = (submitEvent: SubmitEvent) => { + + submitEvent.preventDefault(); + + cityssm.postJSON(urlPrefix + "/lotOccupancies/doAddLotOccupancyOccupant", + addFormElement, + (responseJSON: { success: boolean; errorMessage?: string; lotOccupancyOccupants?: recordTypes.LotOccupancyOccupant[]; }) => { + + if (responseJSON.success) { + lotOccupancyOccupants = responseJSON.lotOccupancyOccupants; + addCloseModalFunction(); + renderLotOccupancyOccupants(); + } else { + bulmaJS.alert({ + title: "Error Adding " + exports.aliases.occupant, + message: responseJSON.errorMessage, + contextualColorName: "danger" + }); + } + }); + }; + cityssm.openHtmlModal("lotOccupancy-addOccupant", { onshow: (modalElement) => { los.populateAliases(modalElement); + (modalElement.querySelector("#lotOccupancyOccupantAdd--lotOccupancyId") as HTMLInputElement).value = lotOccupancyId; + + const lotOccupantTypeSelectElement = modalElement.querySelector("#lotOccupancyOccupantAdd--lotOccupantTypeId") as HTMLSelectElement; + + for (const lotOccupantType of (exports.lotOccupantTypes as recordTypes.LotOccupantType[])) { + const optionElement = document.createElement("option"); + optionElement.value = lotOccupantType.lotOccupantTypeId.toString(); + optionElement.textContent = lotOccupantType.lotOccupantType; + lotOccupantTypeSelectElement.append(optionElement); + } + (modalElement.querySelector("#lotOccupancyOccupantAdd--occupantCity") as HTMLInputElement).value = exports.occupantCityDefault; (modalElement.querySelector("#lotOccupancyOccupantAdd--occupantProvince") as HTMLInputElement).value = exports.occupantProvinceDefault; + }, + onshown: (modalElement, closeModalFunction) => { + + bulmaJS.toggleHtmlClipped(); + + addFormElement = modalElement.querySelector("form"); + addFormElement.addEventListener("submit", addOccupant); + + addCloseModalFunction = closeModalFunction; + }, + onremoved: () => { + bulmaJS.toggleHtmlClipped(); } }); }); diff --git a/public/html/lotOccupancy-addOccupant.html b/public/html/lotOccupancy-addOccupant.html index 7362e8cd..3c37b17f 100644 --- a/public/html/lotOccupancy-addOccupant.html +++ b/public/html/lotOccupancy-addOccupant.html @@ -13,7 +13,7 @@
-
+
@@ -40,7 +40,7 @@
- +
@@ -48,7 +48,7 @@
- +
@@ -56,7 +56,7 @@
- +
@@ -64,7 +64,7 @@
- +
diff --git a/public/html/lotOccupancy-editOccupant.html b/public/html/lotOccupancy-editOccupant.html new file mode 100644 index 00000000..05ffd7e1 --- /dev/null +++ b/public/html/lotOccupancy-editOccupant.html @@ -0,0 +1,81 @@ + \ No newline at end of file diff --git a/public/javascripts/lotOccupancyEdit.min.js b/public/javascripts/lotOccupancyEdit.min.js index 1db3951e..11ef1f09 100644 --- a/public/javascripts/lotOccupancyEdit.min.js +++ b/public/javascripts/lotOccupancyEdit.min.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const e=exports.los,t=document.querySelector("main").dataset.urlPrefix,c=""===document.querySelector("#lotOccupancy--lotOccupancyId").value;let a=!1,s=c;const n=()=>{a||(a=!0,cityssm.enableNavBlocker())},o=document.querySelector("#form--lotOccupancy");o.addEventListener("submit",e=>{e.preventDefault(),cityssm.postJSON(t+"/lotOccupancies/"+(c?"doCreateLotOccupancy":"doUpdateLotOccupancy"),o,e=>{e.success?(a=!1,cityssm.disableNavBlocker(),c||s?window.location.href=t+"/lotOccupancies/"+e.lotOccupancyId+"/edit?t="+Date.now():bulmaJS.alert({message:exports.aliases.occupancy+" Updated Successfully",contextualColorName:"success"})):bulmaJS.alert({title:"Error Saving "+exports.aliases.occupancy,message:e.errorMessage,contextualColorName:"danger"})})});const l=o.querySelectorAll("input, select");for(const e of l)e.addEventListener("change",n);if(!c){const e=document.querySelector("#lotOccupancy--occupancyTypeId"),t=e.value;e.addEventListener("change",()=>{e.value!==t&&bulmaJS.confirm({title:"Confirm Change",message:"Are you sure you want to change the "+exports.aliases.occupancy.toLowerCase()+" type?\nThis change affects the additional fields associated with this record, and may also affect the available fees.",contextualColorName:"warning",okButton:{text:"Yes, Keep the Change",callbackFunction:()=>{s=!0}},cancelButton:{text:"Revert the Change",callbackFunction:()=>{e.value=t}}})})}if(document.querySelector("#lotOccupancy--lotName").addEventListener("click",c=>{const a=c.currentTarget.value;let s,o,l;const r=e=>{e.preventDefault();const t=e.currentTarget;document.querySelector("#lotOccupancy--lotId").value=t.dataset.lotId,document.querySelector("#lotOccupancy--lotName").value=t.dataset.lotName,n(),s()},u=()=>{l.innerHTML='


Searching...

',cityssm.postJSON(t+"/lots/doSearchLots",o,e=>{if(0===e.count)return void(l.innerHTML='

No results.

');const t=document.createElement("div");t.className="panel";for(const c of e.lots){const e=document.createElement("a");e.className="panel-block is-block",e.href="#",e.dataset.lotId=c.lotId.toString(),e.dataset.lotName=c.lotName,e.innerHTML='
'+cityssm.escapeHTML(c.lotName)+'
'+cityssm.escapeHTML(c.mapName)+'
'+cityssm.escapeHTML(c.lotStatus)+'
'+(c.lotOccupancyCount>0?"Currently Occupied":"")+"
",e.addEventListener("click",r),t.append(e)}l.innerHTML="",l.append(t)})};cityssm.openHtmlModal("lotOccupancy-selectLot",{onshow:t=>{e.populateAliases(t)},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),s=t;const c=e.querySelector("#lotSelect--lotName");c.value=a,c.focus(),c.addEventListener("change",u),e.querySelector("#lotSelect--occupancyStatus").addEventListener("change",u),o=e.querySelector("#form--lotSelect"),l=e.querySelector("#resultsContainer--lotSelect"),o.addEventListener("submit",e=>{e.preventDefault()}),u()},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})}),document.querySelector("#lotOccupancy--occupancyStartDateString").addEventListener("change",()=>{document.querySelector("#lotOccupancy--occupancyEndDateString").min=document.querySelector("#lotOccupancy--occupancyStartDateString").value}),e.initializeUnlockFieldButtons(o),!c){let t=exports.lotOccupancyOccupants;const c=()=>{const e=document.querySelector("#container--lotOccupancyOccupants");if(cityssm.clearElement(e),0===t.length)return void(e.innerHTML='

There are no '+exports.aliases.occupants.toLowerCase()+" associated with this record.

");const c=document.createElement("table");c.className="table is-fullwidth is-striped is-hoverable",c.innerHTML=""+exports.aliases.occupant+" Type"+exports.aliases.occupant+"AddressPhone Number";for(const e of t){const t=document.createElement("tr");t.dataset.lotOccupantIndex=e.lotOccupantIndex.toString(),t.innerHTML=""+cityssm.escapeHTML(e.lotOccupantType)+""+cityssm.escapeHTML(e.occupantName)+""+cityssm.escapeHTML(e.occupantAddress1)+"
"+(e.occupantAddress2?cityssm.escapeHTML(e.occupantAddress2)+"
":"")+cityssm.escapeHTML(e.occupantCity)+", "+cityssm.escapeHTML(e.occupantProvince)+"
"+cityssm.escapeHTML(e.occupantPostalCode)+""+cityssm.escapeHTML(e.occupantPhoneNumber)+'
',c.querySelector("tbody").append(t)}e.append(c)};document.querySelector("#button--addOccupant").addEventListener("click",()=>{cityssm.openHtmlModal("lotOccupancy-addOccupant",{onshow:t=>{e.populateAliases(t),t.querySelector("#lotOccupancyOccupantAdd--occupantCity").value=exports.occupantCityDefault,t.querySelector("#lotOccupancyOccupantAdd--occupantProvince").value=exports.occupantProvinceDefault}})}),c()}})(); \ No newline at end of file +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const e=exports.los,t=document.querySelector("main").dataset.urlPrefix,c=document.querySelector("#lotOccupancy--lotOccupancyId").value,a=""===c;let o=!1,n=a;const s=()=>{o||(o=!0,cityssm.enableNavBlocker())},l=document.querySelector("#form--lotOccupancy");l.addEventListener("submit",e=>{e.preventDefault(),cityssm.postJSON(t+"/lotOccupancies/"+(a?"doCreateLotOccupancy":"doUpdateLotOccupancy"),l,e=>{e.success?(o=!1,cityssm.disableNavBlocker(),a||n?window.location.href=t+"/lotOccupancies/"+e.lotOccupancyId+"/edit?t="+Date.now():bulmaJS.alert({message:exports.aliases.occupancy+" Updated Successfully",contextualColorName:"success"})):bulmaJS.alert({title:"Error Saving "+exports.aliases.occupancy,message:e.errorMessage,contextualColorName:"danger"})})});const u=l.querySelectorAll("input, select");for(const e of u)e.addEventListener("change",s);if(!a){const e=document.querySelector("#lotOccupancy--occupancyTypeId"),t=e.value;e.addEventListener("change",()=>{e.value!==t&&bulmaJS.confirm({title:"Confirm Change",message:"Are you sure you want to change the "+exports.aliases.occupancy.toLowerCase()+" type?\nThis change affects the additional fields associated with this record, and may also affect the available fees.",contextualColorName:"warning",okButton:{text:"Yes, Keep the Change",callbackFunction:()=>{n=!0}},cancelButton:{text:"Revert the Change",callbackFunction:()=>{e.value=t}}})})}if(document.querySelector("#lotOccupancy--lotName").addEventListener("click",c=>{const a=c.currentTarget.value;let o,n,l;const u=e=>{e.preventDefault();const t=e.currentTarget;document.querySelector("#lotOccupancy--lotId").value=t.dataset.lotId,document.querySelector("#lotOccupancy--lotName").value=t.dataset.lotName,s(),o()},r=()=>{l.innerHTML='


Searching...

',cityssm.postJSON(t+"/lots/doSearchLots",n,e=>{if(0===e.count)return void(l.innerHTML='

No results.

');const t=document.createElement("div");t.className="panel";for(const c of e.lots){const e=document.createElement("a");e.className="panel-block is-block",e.href="#",e.dataset.lotId=c.lotId.toString(),e.dataset.lotName=c.lotName,e.innerHTML='
'+cityssm.escapeHTML(c.lotName)+'
'+cityssm.escapeHTML(c.mapName)+'
'+cityssm.escapeHTML(c.lotStatus)+'
'+(c.lotOccupancyCount>0?"Currently Occupied":"")+"
",e.addEventListener("click",u),t.append(e)}l.innerHTML="",l.append(t)})};cityssm.openHtmlModal("lotOccupancy-selectLot",{onshow:t=>{e.populateAliases(t)},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),o=t;const c=e.querySelector("#lotSelect--lotName");c.value=a,c.focus(),c.addEventListener("change",r),e.querySelector("#lotSelect--occupancyStatus").addEventListener("change",r),n=e.querySelector("#form--lotSelect"),l=e.querySelector("#resultsContainer--lotSelect"),n.addEventListener("submit",e=>{e.preventDefault()}),r()},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})}),document.querySelector("#lotOccupancy--occupancyStartDateString").addEventListener("change",()=>{document.querySelector("#lotOccupancy--occupancyEndDateString").min=document.querySelector("#lotOccupancy--occupancyStartDateString").value}),e.initializeUnlockFieldButtons(l),!a){let a=exports.lotOccupancyOccupants;const o=o=>{const n=Number.parseInt(o.currentTarget.closest("tr").dataset.lotOccupantIndex,10),l=a.find(e=>e.lotOccupantIndex===n);let u,r;const p=e=>{e.preventDefault(),cityssm.postJSON(t+"/lotOccupancies/doUpdateLotOccupancyOccupant",u,e=>{e.success?(a=e.lotOccupancyOccupants,r(),s()):bulmaJS.alert({title:"Error Updating "+exports.aliases.occupant,message:e.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("lotOccupancy-editOccupant",{onshow:t=>{e.populateAliases(t),t.querySelector("#lotOccupancyOccupantEdit--lotOccupancyId").value=c,t.querySelector("#lotOccupancyOccupantEdit--lotOccupantIndex").value=n.toString();const a=t.querySelector("#lotOccupancyOccupantEdit--lotOccupantTypeId");let o=!1;for(const e of exports.lotOccupantTypes){const t=document.createElement("option");t.value=e.lotOccupantTypeId.toString(),t.textContent=e.lotOccupantType,e.lotOccupantTypeId===l.lotOccupantTypeId&&(t.selected=!0,o=!0),a.append(t)}if(!o){const e=document.createElement("option");e.value=l.lotOccupantTypeId.toString(),e.textContent=l.lotOccupantType,e.selected=!0,a.append(e)}t.querySelector("#lotOccupancyOccupantEdit--occupantName").value=l.occupantName,t.querySelector("#lotOccupancyOccupantEdit--occupantAddress1").value=l.occupantAddress1,t.querySelector("#lotOccupancyOccupantEdit--occupantAddress2").value=l.occupantAddress2,t.querySelector("#lotOccupancyOccupantEdit--occupantCity").value=l.occupantCity,t.querySelector("#lotOccupancyOccupantEdit--occupantProvince").value=l.occupantProvince,t.querySelector("#lotOccupancyOccupantEdit--occupantPostalCode").value=l.occupantPostalCode,t.querySelector("#lotOccupancyOccupantEdit--occupantPhoneNumber").value=l.occupantPhoneNumber},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),(u=e.querySelector("form")).addEventListener("submit",p),r=t},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},n=e=>{const o=e.currentTarget.closest("tr").dataset.lotOccupantIndex;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:()=>{cityssm.postJSON(t+"/lotOccupancies/doDeleteLotOccupancyOccupant",{lotOccupancyId:c,lotOccupantIndex:o},e=>{e.success?(a=e.lotOccupancyOccupants,s()):bulmaJS.alert({title:"Error Removing "+exports.aliases.occupant,message:e.errorMessage,contextualColorName:"danger"})})}},contextualColorName:"warning"})},s=()=>{const e=document.querySelector("#container--lotOccupancyOccupants");if(cityssm.clearElement(e),0===a.length)return void(e.innerHTML='

There are no '+exports.aliases.occupants.toLowerCase()+" associated with this record.

");const t=document.createElement("table");t.className="table is-fullwidth is-striped is-hoverable",t.innerHTML=""+exports.aliases.occupant+" Type"+exports.aliases.occupant+"AddressPhone Number";for(const e of a){const c=document.createElement("tr");c.dataset.lotOccupantIndex=e.lotOccupantIndex.toString(),c.innerHTML=""+cityssm.escapeHTML(e.lotOccupantType)+""+cityssm.escapeHTML(e.occupantName)+""+cityssm.escapeHTML(e.occupantAddress1)+"
"+(e.occupantAddress2?cityssm.escapeHTML(e.occupantAddress2)+"
":"")+cityssm.escapeHTML(e.occupantCity)+", "+cityssm.escapeHTML(e.occupantProvince)+"
"+cityssm.escapeHTML(e.occupantPostalCode)+""+cityssm.escapeHTML(e.occupantPhoneNumber)+'
',c.querySelector(".button--edit").addEventListener("click",o),c.querySelector(".button--delete").addEventListener("click",n),t.querySelector("tbody").append(c)}e.append(t)};document.querySelector("#button--addOccupant").addEventListener("click",()=>{let o,n;const l=e=>{e.preventDefault(),cityssm.postJSON(t+"/lotOccupancies/doAddLotOccupancyOccupant",o,e=>{e.success?(a=e.lotOccupancyOccupants,n(),s()):bulmaJS.alert({title:"Error Adding "+exports.aliases.occupant,message:e.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("lotOccupancy-addOccupant",{onshow:t=>{e.populateAliases(t),t.querySelector("#lotOccupancyOccupantAdd--lotOccupancyId").value=c;const a=t.querySelector("#lotOccupancyOccupantAdd--lotOccupantTypeId");for(const e of exports.lotOccupantTypes){const t=document.createElement("option");t.value=e.lotOccupantTypeId.toString(),t.textContent=e.lotOccupantType,a.append(t)}t.querySelector("#lotOccupancyOccupantAdd--occupantCity").value=exports.occupantCityDefault,t.querySelector("#lotOccupancyOccupantAdd--occupantProvince").value=exports.occupantProvinceDefault},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),(o=e.querySelector("form")).addEventListener("submit",l),n=t},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})}),s()}})(); \ No newline at end of file diff --git a/routes/lotOccupancies.js b/routes/lotOccupancies.js index 771ab48f..e5b27771 100644 --- a/routes/lotOccupancies.js +++ b/routes/lotOccupancies.js @@ -4,6 +4,9 @@ import handler_doSearchLotOccupancies from "../handlers/lotOccupancies-post/doSe import handler_view from "../handlers/lotOccupancies-get/view.js"; import handler_edit from "../handlers/lotOccupancies-get/edit.js"; import handler_doUpdateLotOccupancy from "../handlers/lotOccupancies-post/doUpdateLotOccupancy.js"; +import handler_doAddLotOccupancyOccupant from "../handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js"; +import handler_doUpdateLotOccupancyOccupant from "../handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js"; +import handler_doDeleteLotOccupancyOccupant from "../handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.js"; import * as permissionHandlers from "../handlers/permissions.js"; export const router = Router(); router.get("/", handler_search); @@ -11,4 +14,7 @@ router.post("/doSearchLotOccupancies", handler_doSearchLotOccupancies); router.get("/:lotOccupancyId", handler_view); router.get("/:lotOccupancyId/edit", permissionHandlers.updateGetHandler, handler_edit); router.post("/doUpdateLotOccupancy", permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancy); +router.post("/doAddLotOccupancyOccupant", permissionHandlers.updatePostHandler, handler_doAddLotOccupancyOccupant); +router.post("/doUpdateLotOccupancyOccupant", permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancyOccupant); +router.post("/doDeleteLotOccupancyOccupant", permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancyOccupant); export default router; diff --git a/routes/lotOccupancies.ts b/routes/lotOccupancies.ts index 88848e29..77b89f4e 100644 --- a/routes/lotOccupancies.ts +++ b/routes/lotOccupancies.ts @@ -10,6 +10,10 @@ import handler_view from "../handlers/lotOccupancies-get/view.js"; import handler_edit from "../handlers/lotOccupancies-get/edit.js"; import handler_doUpdateLotOccupancy from "../handlers/lotOccupancies-post/doUpdateLotOccupancy.js"; +import handler_doAddLotOccupancyOccupant from "../handlers/lotOccupancies-post/doAddLotOccupancyOccupant.js"; +import handler_doUpdateLotOccupancyOccupant from "../handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js"; +import handler_doDeleteLotOccupancyOccupant from "../handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.js"; + import * as permissionHandlers from "../handlers/permissions.js"; @@ -36,5 +40,17 @@ router.post("/doUpdateLotOccupancy", permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancy); +router.post("/doAddLotOccupancyOccupant", + permissionHandlers.updatePostHandler, + handler_doAddLotOccupancyOccupant); + +router.post("/doUpdateLotOccupancyOccupant", + permissionHandlers.updatePostHandler, + handler_doUpdateLotOccupancyOccupant); + +router.post("/doDeleteLotOccupancyOccupant", + permissionHandlers.updatePostHandler, + handler_doDeleteLotOccupancyOccupant); + export default router; \ No newline at end of file