From 040f1bd55345fa063f0ff1afe9743aef21be44e8 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Tue, 20 Sep 2022 14:15:30 -0400 Subject: [PATCH] delete lot --- handlers/lots-post/doDeleteLot.d.ts | 3 + handlers/lots-post/doDeleteLot.js | 8 ++ handlers/lots-post/doDeleteLot.ts | 16 ++++ helpers/lotOccupancyDB/deleteLot.d.ts | 3 + helpers/lotOccupancyDB/deleteLot.js | 27 ++++++ helpers/lotOccupancyDB/deleteLot.ts | 47 ++++++++++ public-typescript/lotEdit.js | 66 +++++++++----- public-typescript/lotEdit.ts | 121 +++++++++++++------------- public/javascripts/lotEdit.min.js | 2 +- routes/lots.js | 2 + routes/lots.ts | 21 ++--- views/lot-edit.ejs | 42 ++++++--- 12 files changed, 251 insertions(+), 107 deletions(-) create mode 100644 handlers/lots-post/doDeleteLot.d.ts create mode 100644 handlers/lots-post/doDeleteLot.js create mode 100644 handlers/lots-post/doDeleteLot.ts create mode 100644 helpers/lotOccupancyDB/deleteLot.d.ts create mode 100644 helpers/lotOccupancyDB/deleteLot.js create mode 100644 helpers/lotOccupancyDB/deleteLot.ts diff --git a/handlers/lots-post/doDeleteLot.d.ts b/handlers/lots-post/doDeleteLot.d.ts new file mode 100644 index 00000000..9621c611 --- /dev/null +++ b/handlers/lots-post/doDeleteLot.d.ts @@ -0,0 +1,3 @@ +import type { RequestHandler } from "express"; +export declare const handler: RequestHandler; +export default handler; diff --git a/handlers/lots-post/doDeleteLot.js b/handlers/lots-post/doDeleteLot.js new file mode 100644 index 00000000..ec62e3fa --- /dev/null +++ b/handlers/lots-post/doDeleteLot.js @@ -0,0 +1,8 @@ +import { deleteLot } from "../../helpers/lotOccupancyDB/deleteLot.js"; +export const handler = async (request, response) => { + const success = deleteLot(request.body.lotId, request.session); + response.json({ + success + }); +}; +export default handler; diff --git a/handlers/lots-post/doDeleteLot.ts b/handlers/lots-post/doDeleteLot.ts new file mode 100644 index 00000000..b3b0007d --- /dev/null +++ b/handlers/lots-post/doDeleteLot.ts @@ -0,0 +1,16 @@ +import type { RequestHandler } from "express"; + +import { deleteLot } from "../../helpers/lotOccupancyDB/deleteLot.js"; + +export const handler: RequestHandler = async (request, response) => { + const success = deleteLot( + request.body.lotId, + request.session + ); + + response.json({ + success + }); +}; + +export default handler; diff --git a/helpers/lotOccupancyDB/deleteLot.d.ts b/helpers/lotOccupancyDB/deleteLot.d.ts new file mode 100644 index 00000000..c0235b58 --- /dev/null +++ b/helpers/lotOccupancyDB/deleteLot.d.ts @@ -0,0 +1,3 @@ +import type * as recordTypes from "../../types/recordTypes"; +export declare const deleteLot: (lotId: number | string, requestSession: recordTypes.PartialSession) => boolean; +export default deleteLot; diff --git a/helpers/lotOccupancyDB/deleteLot.js b/helpers/lotOccupancyDB/deleteLot.js new file mode 100644 index 00000000..03cd89c1 --- /dev/null +++ b/helpers/lotOccupancyDB/deleteLot.js @@ -0,0 +1,27 @@ +import sqlite from "better-sqlite3"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const deleteLot = (lotId, requestSession) => { + const database = sqlite(databasePath); + const rightNowMillis = Date.now(); + const result = database + .prepare("update Lots" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotId = ?") + .run(requestSession.user.userName, rightNowMillis, lotId); + database + .prepare("update LotComments" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotId = ?") + .run(requestSession.user.userName, rightNowMillis, lotId); + database + .prepare("update LotFields" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotId = ?") + .run(requestSession.user.userName, rightNowMillis, lotId); + database.close(); + return result.changes > 0; +}; +export default deleteLot; diff --git a/helpers/lotOccupancyDB/deleteLot.ts b/helpers/lotOccupancyDB/deleteLot.ts new file mode 100644 index 00000000..45a89184 --- /dev/null +++ b/helpers/lotOccupancyDB/deleteLot.ts @@ -0,0 +1,47 @@ +import sqlite from "better-sqlite3"; + +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; + +import type * as recordTypes from "../../types/recordTypes"; + +export const deleteLot = ( + lotId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); + + const rightNowMillis = Date.now(); + + const result = database + .prepare( + "update Lots" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotId); + + database + .prepare( + "update LotComments" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotId); + + database + .prepare( + "update LotFields" + + " set recordDelete_userName = ?," + + " recordDelete_timeMillis = ?" + + " where lotId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotId); + + database.close(); + + return result.changes > 0; +}; + +export default deleteLot; diff --git a/public-typescript/lotEdit.js b/public-typescript/lotEdit.js index 0628d8e3..0f572c27 100644 --- a/public-typescript/lotEdit.js +++ b/public-typescript/lotEdit.js @@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; const urlPrefix = document.querySelector("main").dataset.urlPrefix; - const lotId = document.querySelector("#lot--lotId") - .value; + const lotId = document.querySelector("#lot--lotId").value; const isCreate = lotId === ""; const formElement = document.querySelector("#form--lot"); const updateLot = (formEvent) => { @@ -12,8 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); cityssm.postJSON(urlPrefix + "/lots/" + (isCreate ? "doCreateLot" : "doUpdateLot"), formElement, (responseJSON) => { if (responseJSON.success) { if (isCreate) { - window.location.href = - urlPrefix + "/lots/" + responseJSON.lotId + "/edit"; + window.location.href = urlPrefix + "/lots/" + responseJSON.lotId + "/edit"; } else { bulmaJS.alert({ @@ -33,11 +31,43 @@ Object.defineProperty(exports, "__esModule", { value: true }); }; formElement.addEventListener("submit", updateLot); los.initializeUnlockFieldButtons(formElement); + if (!isCreate) { + document.querySelector("#button--deleteLot").addEventListener("click", (clickEvent) => { + clickEvent.preventDefault(); + const doDelete = () => { + cityssm.postJSON(urlPrefix + "/lots/doDeleteLot", { + lotId + }, (responseJSON) => { + if (responseJSON.success) { + cityssm.disableNavBlocker(); + window.location.href = urlPrefix + "/lots/?t=" + Date.now(); + } + else { + bulmaJS.alert({ + title: "Error Deleting " + exports.aliases.lot, + message: responseJSON.errorMessage, + contextualColorName: "danger" + }); + } + }); + }; + bulmaJS.confirm({ + title: "Delete " + exports.aliases.lot, + message: "Are you sure you want to delete this " + + exports.aliases.lot.toLowerCase() + + "?", + contextualColorName: "warning", + okButton: { + text: "Yes, Delete " + exports.aliases.lot, + callbackFunction: doDelete + } + }); + }); + } let lotComments = exports.lotComments; delete exports.lotComments; const openEditLotComment = (clickEvent) => { - const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset - .lotCommentId, 10); + const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotCommentId, 10); const lotComment = lotComments.find((currentLotComment) => { return currentLotComment.lotCommentId === lotCommentId; }); @@ -63,7 +93,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); cityssm.openHtmlModal("lot-editComment", { onshow: (modalElement) => { los.populateAliases(modalElement); - modalElement.querySelector("#lotCommentEdit--lotId").value = lotId; + modalElement.querySelector("#lotCommentEdit--lotId").value = + lotId; modalElement.querySelector("#lotCommentEdit--lotCommentId").value = lotCommentId.toString(); modalElement.querySelector("#lotCommentEdit--lotComment").value = lotComment.lotComment; modalElement.querySelector("#lotCommentEdit--lotCommentDateString").value = lotComment.lotCommentDateString; @@ -82,8 +113,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); }; const deleteLotComment = (clickEvent) => { - const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset - .lotCommentId, 10); + const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotCommentId, 10); const doDelete = () => { cityssm.postJSON(urlPrefix + "/lots/doDeleteLotComment", { lotId, @@ -133,17 +163,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); ""; for (const lotComment of lotComments) { const tableRowElement = document.createElement("tr"); - tableRowElement.dataset.lotCommentId = - lotComment.lotCommentId.toString(); + tableRowElement.dataset.lotCommentId = lotComment.lotCommentId.toString(); tableRowElement.innerHTML = "" + cityssm.escapeHTML(lotComment.recordCreate_userName) + "" + "" + lotComment.lotCommentDateString + - (lotComment.lotCommentTime === 0 - ? "" - : " " + lotComment.lotCommentTimeString) + + (lotComment.lotCommentTime === 0 ? "" : " " + lotComment.lotCommentTimeString) + "" + "" + cityssm.escapeHTML(lotComment.lotComment) + @@ -185,10 +212,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); cityssm.openHtmlModal("lot-addComment", { onshow(modalElement) { los.populateAliases(modalElement); - modalElement.querySelector("#lotCommentAdd--lotId").value = lotId; - modalElement - .querySelector("form") - .addEventListener("submit", doAddComment); + modalElement.querySelector("#lotCommentAdd--lotId").value = + lotId; + modalElement.querySelector("form").addEventListener("submit", doAddComment); }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); @@ -202,9 +228,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); }; if (!isCreate) { - document - .querySelector("#lotComments--add") - .addEventListener("click", openAddCommentModal); + document.querySelector("#lotComments--add").addEventListener("click", openAddCommentModal); renderLotComments(); } })(); diff --git a/public-typescript/lotEdit.ts b/public-typescript/lotEdit.ts index ae6a4c94..064fb13f 100644 --- a/public-typescript/lotEdit.ts +++ b/public-typescript/lotEdit.ts @@ -15,8 +15,7 @@ declare const bulmaJS: BulmaJS; const urlPrefix = document.querySelector("main").dataset.urlPrefix; - const lotId = (document.querySelector("#lot--lotId") as HTMLInputElement) - .value; + const lotId = (document.querySelector("#lot--lotId") as HTMLInputElement).value; const isCreate = lotId === ""; // Main form @@ -29,19 +28,13 @@ declare const bulmaJS: BulmaJS; cityssm.postJSON( urlPrefix + "/lots/" + (isCreate ? "doCreateLot" : "doUpdateLot"), formElement, - (responseJSON: { - success: boolean; - lotId?: number; - errorMessage?: string; - }) => { + (responseJSON: { success: boolean; lotId?: number; errorMessage?: string }) => { if (responseJSON.success) { if (isCreate) { - window.location.href = - urlPrefix + "/lots/" + responseJSON.lotId + "/edit"; + window.location.href = urlPrefix + "/lots/" + responseJSON.lotId + "/edit"; } else { bulmaJS.alert({ - message: - exports.aliases.lot + " Updated Successfully", + message: exports.aliases.lot + " Updated Successfully", contextualColorName: "success" }); } @@ -60,6 +53,46 @@ declare const bulmaJS: BulmaJS; los.initializeUnlockFieldButtons(formElement); + if (!isCreate) { + document.querySelector("#button--deleteLot").addEventListener("click", (clickEvent) => { + clickEvent.preventDefault(); + + const doDelete = () => { + cityssm.postJSON( + urlPrefix + "/lots/doDeleteLot", + { + lotId + }, + (responseJSON: { success: boolean; errorMessage?: string }) => { + if (responseJSON.success) { + cityssm.disableNavBlocker(); + window.location.href = urlPrefix + "/lots/?t=" + Date.now(); + } else { + bulmaJS.alert({ + title: "Error Deleting " + exports.aliases.lot, + message: responseJSON.errorMessage, + contextualColorName: "danger" + }); + } + } + ); + }; + + bulmaJS.confirm({ + title: "Delete " + exports.aliases.lot, + message: + "Are you sure you want to delete this " + + exports.aliases.lot.toLowerCase() + + "?", + contextualColorName: "warning", + okButton: { + text: "Yes, Delete " + exports.aliases.lot, + callbackFunction: doDelete + } + }); + }); + } + // Comments let lotComments: recordTypes.LotComment[] = exports.lotComments; @@ -67,8 +100,7 @@ declare const bulmaJS: BulmaJS; const openEditLotComment = (clickEvent: Event) => { const lotCommentId = Number.parseInt( - (clickEvent.currentTarget as HTMLElement).closest("tr").dataset - .lotCommentId, + (clickEvent.currentTarget as HTMLElement).closest("tr").dataset.lotCommentId, 10 ); @@ -109,21 +141,14 @@ declare const bulmaJS: BulmaJS; onshow: (modalElement) => { los.populateAliases(modalElement); + (modalElement.querySelector("#lotCommentEdit--lotId") as HTMLInputElement).value = + lotId; ( - modalElement.querySelector( - "#lotCommentEdit--lotId" - ) as HTMLInputElement - ).value = lotId; - ( - modalElement.querySelector( - "#lotCommentEdit--lotCommentId" - ) as HTMLInputElement + modalElement.querySelector("#lotCommentEdit--lotCommentId") as HTMLInputElement ).value = lotCommentId.toString(); ( - modalElement.querySelector( - "#lotCommentEdit--lotComment" - ) as HTMLInputElement + modalElement.querySelector("#lotCommentEdit--lotComment") as HTMLInputElement ).value = lotComment.lotComment; ( modalElement.querySelector( @@ -140,9 +165,7 @@ declare const bulmaJS: BulmaJS; bulmaJS.toggleHtmlClipped(); ( - modalElement.querySelector( - "#lotCommentEdit--lotComment" - ) as HTMLTextAreaElement + modalElement.querySelector("#lotCommentEdit--lotComment") as HTMLTextAreaElement ).focus(); editFormElement = modalElement.querySelector("form"); @@ -158,8 +181,7 @@ declare const bulmaJS: BulmaJS; const deleteLotComment = (clickEvent: Event) => { const lotCommentId = Number.parseInt( - (clickEvent.currentTarget as HTMLElement).closest("tr").dataset - .lotCommentId, + (clickEvent.currentTarget as HTMLElement).closest("tr").dataset.lotCommentId, 10 ); @@ -201,9 +223,7 @@ declare const bulmaJS: BulmaJS; }; const renderLotComments = () => { - const containerElement = document.querySelector( - "#container--lotComments" - ) as HTMLElement; + const containerElement = document.querySelector("#container--lotComments") as HTMLElement; if (lotComments.length === 0) { containerElement.innerHTML = @@ -226,8 +246,7 @@ declare const bulmaJS: BulmaJS; for (const lotComment of lotComments) { const tableRowElement = document.createElement("tr"); - tableRowElement.dataset.lotCommentId = - lotComment.lotCommentId.toString(); + tableRowElement.dataset.lotCommentId = lotComment.lotCommentId.toString(); tableRowElement.innerHTML = "" + @@ -235,9 +254,7 @@ declare const bulmaJS: BulmaJS; "" + "" + lotComment.lotCommentDateString + - (lotComment.lotCommentTime === 0 - ? "" - : " " + lotComment.lotCommentTimeString) + + (lotComment.lotCommentTime === 0 ? "" : " " + lotComment.lotCommentTimeString) + "" + "" + cityssm.escapeHTML(lotComment.lotComment) + @@ -277,10 +294,7 @@ declare const bulmaJS: BulmaJS; cityssm.postJSON( urlPrefix + "/lots/doAddLotComment", formEvent.currentTarget, - (responseJSON: { - success: boolean; - lotComments?: recordTypes.LotComment[]; - }) => { + (responseJSON: { success: boolean; lotComments?: recordTypes.LotComment[] }) => { if (responseJSON.success) { lotComments = responseJSON.lotComments; renderLotComments(); @@ -293,39 +307,26 @@ declare const bulmaJS: BulmaJS; cityssm.openHtmlModal("lot-addComment", { onshow(modalElement) { los.populateAliases(modalElement); - ( - modalElement.querySelector( - "#lotCommentAdd--lotId" - ) as HTMLInputElement - ).value = lotId; - modalElement - .querySelector("form") - .addEventListener("submit", doAddComment); + (modalElement.querySelector("#lotCommentAdd--lotId") as HTMLInputElement).value = + lotId; + modalElement.querySelector("form").addEventListener("submit", doAddComment); }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped(); addCommentCloseModalFunction = closeModalFunction; ( - modalElement.querySelector( - "#lotCommentAdd--lotComment" - ) as HTMLTextAreaElement + modalElement.querySelector("#lotCommentAdd--lotComment") as HTMLTextAreaElement ).focus(); }, onremoved() { bulmaJS.toggleHtmlClipped(); - ( - document.querySelector( - "#lotComments--add" - ) as HTMLButtonElement - ).focus(); + (document.querySelector("#lotComments--add") as HTMLButtonElement).focus(); } }); }; if (!isCreate) { - document - .querySelector("#lotComments--add") - .addEventListener("click", openAddCommentModal); + document.querySelector("#lotComments--add").addEventListener("click", openAddCommentModal); renderLotComments(); } })(); diff --git a/public/javascripts/lotEdit.min.js b/public/javascripts/lotEdit.min.js index 1079c6f6..960b23b7 100644 --- a/public/javascripts/lotEdit.min.js +++ b/public/javascripts/lotEdit.min.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const t=exports.los,e=document.querySelector("main").dataset.urlPrefix,o=document.querySelector("#lot--lotId").value,l=""===o,s=document.querySelector("#form--lot");s.addEventListener("submit",t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/"+(l?"doCreateLot":"doUpdateLot"),s,t=>{t.success?l?window.location.href=e+"/lots/"+t.lotId+"/edit":bulmaJS.alert({message:exports.aliases.lot+" Updated Successfully",contextualColorName:"success"}):bulmaJS.alert({title:"Error Updating "+exports.aliases.lot,message:t.errorMessage,contextualColorName:"danger"})})}),t.initializeUnlockFieldButtons(s);let n=exports.lotComments;delete exports.lotComments;const m=l=>{const s=Number.parseInt(l.currentTarget.closest("tr").dataset.lotCommentId,10),m=n.find(t=>t.lotCommentId===s);let r,d;const i=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doUpdateLotComment",r,t=>{t.success?(n=t.lotComments,d(),a()):bulmaJS.alert({title:"Error Updating Comment",message:t.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("lot-editComment",{onshow:e=>{t.populateAliases(e),e.querySelector("#lotCommentEdit--lotId").value=o,e.querySelector("#lotCommentEdit--lotCommentId").value=s.toString(),e.querySelector("#lotCommentEdit--lotComment").value=m.lotComment,e.querySelector("#lotCommentEdit--lotCommentDateString").value=m.lotCommentDateString,e.querySelector("#lotCommentEdit--lotCommentTimeString").value=m.lotCommentTimeString},onshown:(t,e)=>{bulmaJS.toggleHtmlClipped(),t.querySelector("#lotCommentEdit--lotComment").focus(),(r=t.querySelector("form")).addEventListener("submit",i),d=e},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},r=t=>{const l=Number.parseInt(t.currentTarget.closest("tr").dataset.lotCommentId,10);bulmaJS.confirm({title:"Remove Comment?",message:"Are you sure you want to remove this comment?",okButton:{text:"Yes, Remove Comment",callbackFunction:()=>{cityssm.postJSON(e+"/lots/doDeleteLotComment",{lotId:o,lotCommentId:l},t=>{t.success?(n=t.lotComments,a()):bulmaJS.alert({title:"Error Removing Comment",message:t.errorMessage,contextualColorName:"danger"})})}},contextualColorName:"warning"})},a=()=>{const t=document.querySelector("#container--lotComments");if(0===n.length)return void(t.innerHTML='

There are no comments to display.

');const e=document.createElement("table");e.className="table is-fullwidth is-striped is-hoverable",e.innerHTML='CommentorComment DateCommentOptions';for(const t of n){const o=document.createElement("tr");o.dataset.lotCommentId=t.lotCommentId.toString(),o.innerHTML=""+cityssm.escapeHTML(t.recordCreate_userName)+""+t.lotCommentDateString+(0===t.lotCommentTime?"":" "+t.lotCommentTimeString)+""+cityssm.escapeHTML(t.lotComment)+'
',o.querySelector(".button--edit").addEventListener("click",m),o.querySelector(".button--delete").addEventListener("click",r),e.querySelector("tbody").append(o)}t.innerHTML="",t.append(e)},d=()=>{let l;const s=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doAddLotComment",t.currentTarget,t=>{t.success&&(n=t.lotComments,a(),l())})};cityssm.openHtmlModal("lot-addComment",{onshow(e){t.populateAliases(e),e.querySelector("#lotCommentAdd--lotId").value=o,e.querySelector("form").addEventListener("submit",s)},onshown(t,e){bulmaJS.toggleHtmlClipped(),l=e,t.querySelector("#lotCommentAdd--lotComment").focus()},onremoved(){bulmaJS.toggleHtmlClipped(),document.querySelector("#lotComments--add").focus()}})};l||(document.querySelector("#lotComments--add").addEventListener("click",d),a())})(); \ No newline at end of file +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const t=exports.los,e=document.querySelector("main").dataset.urlPrefix,o=document.querySelector("#lot--lotId").value,l=""===o,s=document.querySelector("#form--lot");s.addEventListener("submit",t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/"+(l?"doCreateLot":"doUpdateLot"),s,t=>{t.success?l?window.location.href=e+"/lots/"+t.lotId+"/edit":bulmaJS.alert({message:exports.aliases.lot+" Updated Successfully",contextualColorName:"success"}):bulmaJS.alert({title:"Error Updating "+exports.aliases.lot,message:t.errorMessage,contextualColorName:"danger"})})}),t.initializeUnlockFieldButtons(s),l||document.querySelector("#button--deleteLot").addEventListener("click",t=>{t.preventDefault();bulmaJS.confirm({title:"Delete "+exports.aliases.lot,message:"Are you sure you want to delete this "+exports.aliases.lot.toLowerCase()+"?",contextualColorName:"warning",okButton:{text:"Yes, Delete "+exports.aliases.lot,callbackFunction:()=>{cityssm.postJSON(e+"/lots/doDeleteLot",{lotId:o},t=>{t.success?(cityssm.disableNavBlocker(),window.location.href=e+"/lots/?t="+Date.now()):bulmaJS.alert({title:"Error Deleting "+exports.aliases.lot,message:t.errorMessage,contextualColorName:"danger"})})}}})});let n=exports.lotComments;delete exports.lotComments;const r=l=>{const s=Number.parseInt(l.currentTarget.closest("tr").dataset.lotCommentId,10),r=n.find(t=>t.lotCommentId===s);let a,i;const d=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doUpdateLotComment",a,t=>{t.success?(n=t.lotComments,i(),m()):bulmaJS.alert({title:"Error Updating Comment",message:t.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("lot-editComment",{onshow:e=>{t.populateAliases(e),e.querySelector("#lotCommentEdit--lotId").value=o,e.querySelector("#lotCommentEdit--lotCommentId").value=s.toString(),e.querySelector("#lotCommentEdit--lotComment").value=r.lotComment,e.querySelector("#lotCommentEdit--lotCommentDateString").value=r.lotCommentDateString,e.querySelector("#lotCommentEdit--lotCommentTimeString").value=r.lotCommentTimeString},onshown:(t,e)=>{bulmaJS.toggleHtmlClipped(),t.querySelector("#lotCommentEdit--lotComment").focus(),(a=t.querySelector("form")).addEventListener("submit",d),i=e},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},a=t=>{const l=Number.parseInt(t.currentTarget.closest("tr").dataset.lotCommentId,10);bulmaJS.confirm({title:"Remove Comment?",message:"Are you sure you want to remove this comment?",okButton:{text:"Yes, Remove Comment",callbackFunction:()=>{cityssm.postJSON(e+"/lots/doDeleteLotComment",{lotId:o,lotCommentId:l},t=>{t.success?(n=t.lotComments,m()):bulmaJS.alert({title:"Error Removing Comment",message:t.errorMessage,contextualColorName:"danger"})})}},contextualColorName:"warning"})},m=()=>{const t=document.querySelector("#container--lotComments");if(0===n.length)return void(t.innerHTML='

There are no comments to display.

');const e=document.createElement("table");e.className="table is-fullwidth is-striped is-hoverable",e.innerHTML='CommentorComment DateCommentOptions';for(const t of n){const o=document.createElement("tr");o.dataset.lotCommentId=t.lotCommentId.toString(),o.innerHTML=""+cityssm.escapeHTML(t.recordCreate_userName)+""+t.lotCommentDateString+(0===t.lotCommentTime?"":" "+t.lotCommentTimeString)+""+cityssm.escapeHTML(t.lotComment)+'
',o.querySelector(".button--edit").addEventListener("click",r),o.querySelector(".button--delete").addEventListener("click",a),e.querySelector("tbody").append(o)}t.innerHTML="",t.append(e)},i=()=>{let l;const s=t=>{t.preventDefault(),cityssm.postJSON(e+"/lots/doAddLotComment",t.currentTarget,t=>{t.success&&(n=t.lotComments,m(),l())})};cityssm.openHtmlModal("lot-addComment",{onshow(e){t.populateAliases(e),e.querySelector("#lotCommentAdd--lotId").value=o,e.querySelector("form").addEventListener("submit",s)},onshown(t,e){bulmaJS.toggleHtmlClipped(),l=e,t.querySelector("#lotCommentAdd--lotComment").focus()},onremoved(){bulmaJS.toggleHtmlClipped(),document.querySelector("#lotComments--add").focus()}})};l||(document.querySelector("#lotComments--add").addEventListener("click",i),m())})(); \ No newline at end of file diff --git a/routes/lots.js b/routes/lots.js index 683cead8..2fdd328d 100644 --- a/routes/lots.js +++ b/routes/lots.js @@ -9,6 +9,7 @@ import handler_new from "../handlers/lots-get/new.js"; import handler_edit from "../handlers/lots-get/edit.js"; import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js"; import handler_doUpdateLot from "../handlers/lots-post/doUpdateLot.js"; +import handler_doDeleteLot from "../handlers/lots-post/doDeleteLot.js"; import handler_doAddLotComment from "../handlers/lots-post/doAddLotComment.js"; import handler_doUpdateLotComment from "../handlers/lots-post/doUpdateLotComment.js"; import handler_doDeleteLotComment from "../handlers/lots-post/doDeleteLotComment.js"; @@ -22,6 +23,7 @@ router.get("/:lotId/previous", handler_previous); router.get("/:lotId/edit", permissionHandlers.updateGetHandler, handler_edit); router.post("/doCreateLot", permissionHandlers.updatePostHandler, handler_doCreateLot); router.post("/doUpdateLot", permissionHandlers.updatePostHandler, handler_doUpdateLot); +router.post("/doDeleteLot", permissionHandlers.updatePostHandler, handler_doDeleteLot); router.post("/doAddLotComment", permissionHandlers.updatePostHandler, handler_doAddLotComment); router.post("/doUpdateLotComment", permissionHandlers.updatePostHandler, handler_doUpdateLotComment); router.post("/doDeleteLotComment", permissionHandlers.updatePostHandler, handler_doDeleteLotComment); diff --git a/routes/lots.ts b/routes/lots.ts index e42ed8e7..7ff8fbee 100644 --- a/routes/lots.ts +++ b/routes/lots.ts @@ -14,6 +14,7 @@ import handler_edit from "../handlers/lots-get/edit.js"; import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js"; import handler_doUpdateLot from "../handlers/lots-post/doUpdateLot.js"; +import handler_doDeleteLot from "../handlers/lots-post/doDeleteLot.js"; import handler_doAddLotComment from "../handlers/lots-post/doAddLotComment.js"; import handler_doUpdateLotComment from "../handlers/lots-post/doUpdateLotComment.js"; @@ -43,23 +44,13 @@ router.get("/:lotId/previous", handler_previous); router.get("/:lotId/edit", permissionHandlers.updateGetHandler, handler_edit); -router.post( - "/doCreateLot", - permissionHandlers.updatePostHandler, - handler_doCreateLot -); +router.post("/doCreateLot", permissionHandlers.updatePostHandler, handler_doCreateLot); -router.post( - "/doUpdateLot", - permissionHandlers.updatePostHandler, - handler_doUpdateLot -); +router.post("/doUpdateLot", permissionHandlers.updatePostHandler, handler_doUpdateLot); -router.post( - "/doAddLotComment", - permissionHandlers.updatePostHandler, - handler_doAddLotComment -); +router.post("/doDeleteLot", permissionHandlers.updatePostHandler, handler_doDeleteLot); + +router.post("/doAddLotComment", permissionHandlers.updatePostHandler, handler_doAddLotComment); router.post( "/doUpdateLotComment", diff --git a/views/lot-edit.ejs b/views/lot-edit.ejs index 442f30a5..f59be842 100644 --- a/views/lot-edit.ejs +++ b/views/lot-edit.ejs @@ -64,7 +64,11 @@
- + class="is-readonly" + <% } %> + id="lot--lotTypeId" name="lotTypeId" required> <% if (isCreate) { %> <% } %> @@ -139,13 +143,13 @@
- +
- +
@@ -159,7 +163,11 @@
- + class="is-readonly" + <% } %> + id="lot--mapId" name="mapId"> @@ -209,12 +217,6 @@
-
-

- Additional Details -

-
-
+ <% if (!isCreate) { %> + + <% } %>