delete lot

deepsource-autofix-76c6eb20
Dan Gowans 2022-09-20 14:15:30 -04:00
parent 726aa540d2
commit 040f1bd553
12 changed files with 251 additions and 107 deletions

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
(() => { (() => {
const los = exports.los; const los = exports.los;
const urlPrefix = document.querySelector("main").dataset.urlPrefix; const urlPrefix = document.querySelector("main").dataset.urlPrefix;
const lotId = document.querySelector("#lot--lotId") const lotId = document.querySelector("#lot--lotId").value;
.value;
const isCreate = lotId === ""; const isCreate = lotId === "";
const formElement = document.querySelector("#form--lot"); const formElement = document.querySelector("#form--lot");
const updateLot = (formEvent) => { const updateLot = (formEvent) => {
@ -12,8 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
cityssm.postJSON(urlPrefix + "/lots/" + (isCreate ? "doCreateLot" : "doUpdateLot"), formElement, (responseJSON) => { cityssm.postJSON(urlPrefix + "/lots/" + (isCreate ? "doCreateLot" : "doUpdateLot"), formElement, (responseJSON) => {
if (responseJSON.success) { if (responseJSON.success) {
if (isCreate) { if (isCreate) {
window.location.href = window.location.href = urlPrefix + "/lots/" + responseJSON.lotId + "/edit";
urlPrefix + "/lots/" + responseJSON.lotId + "/edit";
} }
else { else {
bulmaJS.alert({ bulmaJS.alert({
@ -33,11 +31,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
}; };
formElement.addEventListener("submit", updateLot); formElement.addEventListener("submit", updateLot);
los.initializeUnlockFieldButtons(formElement); 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; let lotComments = exports.lotComments;
delete exports.lotComments; delete exports.lotComments;
const openEditLotComment = (clickEvent) => { const openEditLotComment = (clickEvent) => {
const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotCommentId, 10);
.lotCommentId, 10);
const lotComment = lotComments.find((currentLotComment) => { const lotComment = lotComments.find((currentLotComment) => {
return currentLotComment.lotCommentId === lotCommentId; return currentLotComment.lotCommentId === lotCommentId;
}); });
@ -63,7 +93,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
cityssm.openHtmlModal("lot-editComment", { cityssm.openHtmlModal("lot-editComment", {
onshow: (modalElement) => { onshow: (modalElement) => {
los.populateAliases(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--lotCommentId").value = lotCommentId.toString();
modalElement.querySelector("#lotCommentEdit--lotComment").value = lotComment.lotComment; modalElement.querySelector("#lotCommentEdit--lotComment").value = lotComment.lotComment;
modalElement.querySelector("#lotCommentEdit--lotCommentDateString").value = lotComment.lotCommentDateString; modalElement.querySelector("#lotCommentEdit--lotCommentDateString").value = lotComment.lotCommentDateString;
@ -82,8 +113,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
}); });
}; };
const deleteLotComment = (clickEvent) => { const deleteLotComment = (clickEvent) => {
const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset const lotCommentId = Number.parseInt(clickEvent.currentTarget.closest("tr").dataset.lotCommentId, 10);
.lotCommentId, 10);
const doDelete = () => { const doDelete = () => {
cityssm.postJSON(urlPrefix + "/lots/doDeleteLotComment", { cityssm.postJSON(urlPrefix + "/lots/doDeleteLotComment", {
lotId, lotId,
@ -133,17 +163,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
"<tbody></tbody>"; "<tbody></tbody>";
for (const lotComment of lotComments) { for (const lotComment of lotComments) {
const tableRowElement = document.createElement("tr"); const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotCommentId = tableRowElement.dataset.lotCommentId = lotComment.lotCommentId.toString();
lotComment.lotCommentId.toString();
tableRowElement.innerHTML = tableRowElement.innerHTML =
"<td>" + "<td>" +
cityssm.escapeHTML(lotComment.recordCreate_userName) + cityssm.escapeHTML(lotComment.recordCreate_userName) +
"</td>" + "</td>" +
"<td>" + "<td>" +
lotComment.lotCommentDateString + lotComment.lotCommentDateString +
(lotComment.lotCommentTime === 0 (lotComment.lotCommentTime === 0 ? "" : " " + lotComment.lotCommentTimeString) +
? ""
: " " + lotComment.lotCommentTimeString) +
"</td>" + "</td>" +
"<td>" + "<td>" +
cityssm.escapeHTML(lotComment.lotComment) + cityssm.escapeHTML(lotComment.lotComment) +
@ -185,10 +212,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
cityssm.openHtmlModal("lot-addComment", { cityssm.openHtmlModal("lot-addComment", {
onshow(modalElement) { onshow(modalElement) {
los.populateAliases(modalElement); los.populateAliases(modalElement);
modalElement.querySelector("#lotCommentAdd--lotId").value = lotId; modalElement.querySelector("#lotCommentAdd--lotId").value =
modalElement lotId;
.querySelector("form") modalElement.querySelector("form").addEventListener("submit", doAddComment);
.addEventListener("submit", doAddComment);
}, },
onshown(modalElement, closeModalFunction) { onshown(modalElement, closeModalFunction) {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
@ -202,9 +228,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
}); });
}; };
if (!isCreate) { if (!isCreate) {
document document.querySelector("#lotComments--add").addEventListener("click", openAddCommentModal);
.querySelector("#lotComments--add")
.addEventListener("click", openAddCommentModal);
renderLotComments(); renderLotComments();
} }
})(); })();

View File

@ -15,8 +15,7 @@ declare const bulmaJS: BulmaJS;
const urlPrefix = document.querySelector("main").dataset.urlPrefix; const urlPrefix = document.querySelector("main").dataset.urlPrefix;
const lotId = (document.querySelector("#lot--lotId") as HTMLInputElement) const lotId = (document.querySelector("#lot--lotId") as HTMLInputElement).value;
.value;
const isCreate = lotId === ""; const isCreate = lotId === "";
// Main form // Main form
@ -29,19 +28,13 @@ declare const bulmaJS: BulmaJS;
cityssm.postJSON( cityssm.postJSON(
urlPrefix + "/lots/" + (isCreate ? "doCreateLot" : "doUpdateLot"), urlPrefix + "/lots/" + (isCreate ? "doCreateLot" : "doUpdateLot"),
formElement, formElement,
(responseJSON: { (responseJSON: { success: boolean; lotId?: number; errorMessage?: string }) => {
success: boolean;
lotId?: number;
errorMessage?: string;
}) => {
if (responseJSON.success) { if (responseJSON.success) {
if (isCreate) { if (isCreate) {
window.location.href = window.location.href = urlPrefix + "/lots/" + responseJSON.lotId + "/edit";
urlPrefix + "/lots/" + responseJSON.lotId + "/edit";
} else { } else {
bulmaJS.alert({ bulmaJS.alert({
message: message: exports.aliases.lot + " Updated Successfully",
exports.aliases.lot + " Updated Successfully",
contextualColorName: "success" contextualColorName: "success"
}); });
} }
@ -60,6 +53,46 @@ declare const bulmaJS: BulmaJS;
los.initializeUnlockFieldButtons(formElement); 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 // Comments
let lotComments: recordTypes.LotComment[] = exports.lotComments; let lotComments: recordTypes.LotComment[] = exports.lotComments;
@ -67,8 +100,7 @@ declare const bulmaJS: BulmaJS;
const openEditLotComment = (clickEvent: Event) => { const openEditLotComment = (clickEvent: Event) => {
const lotCommentId = Number.parseInt( const lotCommentId = Number.parseInt(
(clickEvent.currentTarget as HTMLElement).closest("tr").dataset (clickEvent.currentTarget as HTMLElement).closest("tr").dataset.lotCommentId,
.lotCommentId,
10 10
); );
@ -109,21 +141,14 @@ declare const bulmaJS: BulmaJS;
onshow: (modalElement) => { onshow: (modalElement) => {
los.populateAliases(modalElement); los.populateAliases(modalElement);
(modalElement.querySelector("#lotCommentEdit--lotId") as HTMLInputElement).value =
lotId;
( (
modalElement.querySelector( modalElement.querySelector("#lotCommentEdit--lotCommentId") as HTMLInputElement
"#lotCommentEdit--lotId"
) as HTMLInputElement
).value = lotId;
(
modalElement.querySelector(
"#lotCommentEdit--lotCommentId"
) as HTMLInputElement
).value = lotCommentId.toString(); ).value = lotCommentId.toString();
( (
modalElement.querySelector( modalElement.querySelector("#lotCommentEdit--lotComment") as HTMLInputElement
"#lotCommentEdit--lotComment"
) as HTMLInputElement
).value = lotComment.lotComment; ).value = lotComment.lotComment;
( (
modalElement.querySelector( modalElement.querySelector(
@ -140,9 +165,7 @@ declare const bulmaJS: BulmaJS;
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
( (
modalElement.querySelector( modalElement.querySelector("#lotCommentEdit--lotComment") as HTMLTextAreaElement
"#lotCommentEdit--lotComment"
) as HTMLTextAreaElement
).focus(); ).focus();
editFormElement = modalElement.querySelector("form"); editFormElement = modalElement.querySelector("form");
@ -158,8 +181,7 @@ declare const bulmaJS: BulmaJS;
const deleteLotComment = (clickEvent: Event) => { const deleteLotComment = (clickEvent: Event) => {
const lotCommentId = Number.parseInt( const lotCommentId = Number.parseInt(
(clickEvent.currentTarget as HTMLElement).closest("tr").dataset (clickEvent.currentTarget as HTMLElement).closest("tr").dataset.lotCommentId,
.lotCommentId,
10 10
); );
@ -201,9 +223,7 @@ declare const bulmaJS: BulmaJS;
}; };
const renderLotComments = () => { const renderLotComments = () => {
const containerElement = document.querySelector( const containerElement = document.querySelector("#container--lotComments") as HTMLElement;
"#container--lotComments"
) as HTMLElement;
if (lotComments.length === 0) { if (lotComments.length === 0) {
containerElement.innerHTML = containerElement.innerHTML =
@ -226,8 +246,7 @@ declare const bulmaJS: BulmaJS;
for (const lotComment of lotComments) { for (const lotComment of lotComments) {
const tableRowElement = document.createElement("tr"); const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotCommentId = tableRowElement.dataset.lotCommentId = lotComment.lotCommentId.toString();
lotComment.lotCommentId.toString();
tableRowElement.innerHTML = tableRowElement.innerHTML =
"<td>" + "<td>" +
@ -235,9 +254,7 @@ declare const bulmaJS: BulmaJS;
"</td>" + "</td>" +
"<td>" + "<td>" +
lotComment.lotCommentDateString + lotComment.lotCommentDateString +
(lotComment.lotCommentTime === 0 (lotComment.lotCommentTime === 0 ? "" : " " + lotComment.lotCommentTimeString) +
? ""
: " " + lotComment.lotCommentTimeString) +
"</td>" + "</td>" +
"<td>" + "<td>" +
cityssm.escapeHTML(lotComment.lotComment) + cityssm.escapeHTML(lotComment.lotComment) +
@ -277,10 +294,7 @@ declare const bulmaJS: BulmaJS;
cityssm.postJSON( cityssm.postJSON(
urlPrefix + "/lots/doAddLotComment", urlPrefix + "/lots/doAddLotComment",
formEvent.currentTarget, formEvent.currentTarget,
(responseJSON: { (responseJSON: { success: boolean; lotComments?: recordTypes.LotComment[] }) => {
success: boolean;
lotComments?: recordTypes.LotComment[];
}) => {
if (responseJSON.success) { if (responseJSON.success) {
lotComments = responseJSON.lotComments; lotComments = responseJSON.lotComments;
renderLotComments(); renderLotComments();
@ -293,39 +307,26 @@ declare const bulmaJS: BulmaJS;
cityssm.openHtmlModal("lot-addComment", { cityssm.openHtmlModal("lot-addComment", {
onshow(modalElement) { onshow(modalElement) {
los.populateAliases(modalElement); los.populateAliases(modalElement);
( (modalElement.querySelector("#lotCommentAdd--lotId") as HTMLInputElement).value =
modalElement.querySelector( lotId;
"#lotCommentAdd--lotId" modalElement.querySelector("form").addEventListener("submit", doAddComment);
) as HTMLInputElement
).value = lotId;
modalElement
.querySelector("form")
.addEventListener("submit", doAddComment);
}, },
onshown(modalElement, closeModalFunction) { onshown(modalElement, closeModalFunction) {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
addCommentCloseModalFunction = closeModalFunction; addCommentCloseModalFunction = closeModalFunction;
( (
modalElement.querySelector( modalElement.querySelector("#lotCommentAdd--lotComment") as HTMLTextAreaElement
"#lotCommentAdd--lotComment"
) as HTMLTextAreaElement
).focus(); ).focus();
}, },
onremoved() { onremoved() {
bulmaJS.toggleHtmlClipped(); bulmaJS.toggleHtmlClipped();
( (document.querySelector("#lotComments--add") as HTMLButtonElement).focus();
document.querySelector(
"#lotComments--add"
) as HTMLButtonElement
).focus();
} }
}); });
}; };
if (!isCreate) { if (!isCreate) {
document document.querySelector("#lotComments--add").addEventListener("click", openAddCommentModal);
.querySelector("#lotComments--add")
.addEventListener("click", openAddCommentModal);
renderLotComments(); renderLotComments();
} }
})(); })();

View File

@ -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='<div class="message is-info"><p class="message-body">There are no comments to display.</p></div>');const e=document.createElement("table");e.className="table is-fullwidth is-striped is-hoverable",e.innerHTML='<thead><tr><th>Commentor</th><th>Comment Date</th><th>Comment</th><th class="is-hidden-print"><span class="is-sr-only">Options</span></th></tr></thead><tbody></tbody>';for(const t of n){const o=document.createElement("tr");o.dataset.lotCommentId=t.lotCommentId.toString(),o.innerHTML="<td>"+cityssm.escapeHTML(t.recordCreate_userName)+"</td><td>"+t.lotCommentDateString+(0===t.lotCommentTime?"":" "+t.lotCommentTimeString)+"</td><td>"+cityssm.escapeHTML(t.lotComment)+'</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 Comment" type="button" aria-label="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button></div></td>',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())})(); "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='<div class="message is-info"><p class="message-body">There are no comments to display.</p></div>');const e=document.createElement("table");e.className="table is-fullwidth is-striped is-hoverable",e.innerHTML='<thead><tr><th>Commentor</th><th>Comment Date</th><th>Comment</th><th class="is-hidden-print"><span class="is-sr-only">Options</span></th></tr></thead><tbody></tbody>';for(const t of n){const o=document.createElement("tr");o.dataset.lotCommentId=t.lotCommentId.toString(),o.innerHTML="<td>"+cityssm.escapeHTML(t.recordCreate_userName)+"</td><td>"+t.lotCommentDateString+(0===t.lotCommentTime?"":" "+t.lotCommentTimeString)+"</td><td>"+cityssm.escapeHTML(t.lotComment)+'</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 Comment" type="button" aria-label="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button></div></td>',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())})();

View File

@ -9,6 +9,7 @@ import handler_new from "../handlers/lots-get/new.js";
import handler_edit from "../handlers/lots-get/edit.js"; import handler_edit from "../handlers/lots-get/edit.js";
import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js"; import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js";
import handler_doUpdateLot from "../handlers/lots-post/doUpdateLot.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_doAddLotComment from "../handlers/lots-post/doAddLotComment.js";
import handler_doUpdateLotComment from "../handlers/lots-post/doUpdateLotComment.js"; import handler_doUpdateLotComment from "../handlers/lots-post/doUpdateLotComment.js";
import handler_doDeleteLotComment from "../handlers/lots-post/doDeleteLotComment.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.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("/doDeleteLot", permissionHandlers.updatePostHandler, handler_doDeleteLot);
router.post("/doAddLotComment", permissionHandlers.updatePostHandler, handler_doAddLotComment); router.post("/doAddLotComment", permissionHandlers.updatePostHandler, handler_doAddLotComment);
router.post("/doUpdateLotComment", permissionHandlers.updatePostHandler, handler_doUpdateLotComment); router.post("/doUpdateLotComment", permissionHandlers.updatePostHandler, handler_doUpdateLotComment);
router.post("/doDeleteLotComment", permissionHandlers.updatePostHandler, handler_doDeleteLotComment); router.post("/doDeleteLotComment", permissionHandlers.updatePostHandler, handler_doDeleteLotComment);

View File

@ -14,6 +14,7 @@ import handler_edit from "../handlers/lots-get/edit.js";
import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js"; import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js";
import handler_doUpdateLot from "../handlers/lots-post/doUpdateLot.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_doAddLotComment from "../handlers/lots-post/doAddLotComment.js";
import handler_doUpdateLotComment from "../handlers/lots-post/doUpdateLotComment.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.get("/:lotId/edit", permissionHandlers.updateGetHandler, handler_edit);
router.post( router.post("/doCreateLot", permissionHandlers.updatePostHandler, handler_doCreateLot);
"/doCreateLot",
permissionHandlers.updatePostHandler,
handler_doCreateLot
);
router.post( router.post("/doUpdateLot", permissionHandlers.updatePostHandler, handler_doUpdateLot);
"/doUpdateLot",
permissionHandlers.updatePostHandler,
handler_doUpdateLot
);
router.post( router.post("/doDeleteLot", permissionHandlers.updatePostHandler, handler_doDeleteLot);
"/doAddLotComment",
permissionHandlers.updatePostHandler, router.post("/doAddLotComment", permissionHandlers.updatePostHandler, handler_doAddLotComment);
handler_doAddLotComment
);
router.post( router.post(
"/doUpdateLotComment", "/doUpdateLotComment",

View File

@ -64,7 +64,11 @@
<div class="field has-addons"> <div class="field has-addons">
<div class="control is-expanded"> <div class="control is-expanded">
<div class="select is-fullwidth"> <div class="select is-fullwidth">
<select id="lot--lotTypeId" name="lotTypeId" required> <select
<% if (!isCreate) { %>
class="is-readonly"
<% } %>
id="lot--lotTypeId" name="lotTypeId" required>
<% if (isCreate) { %> <% if (isCreate) { %>
<option value="">(No Type)</option> <option value="">(No Type)</option>
<% } %> <% } %>
@ -139,13 +143,13 @@
<div class="field"> <div class="field">
<label class="label" for="lot--lotLatitude">Latitude</label> <label class="label" for="lot--lotLatitude">Latitude</label>
<div class="control"> <div class="control">
<input class="input" id="lot--lotLatitude" name="lotLatitude" type="number" min="-90" max="90" step="0.00000001" value="<%= lot.lotLatitude %>" /> <input class="input" id="lot--lotLatitude" name="lotLatitude" type="number" min="-90" max="90" step="0.00000001" value="<%= lot.lotLatitude %>" onwheel="return false" />
</div> </div>
</div> </div>
<div class="field"> <div class="field">
<label class="label" for="lot--lotLongitude">Longitude</label> <label class="label" for="lot--lotLongitude">Longitude</label>
<div class="control"> <div class="control">
<input class="input" id="lot--lotLongitude" name="lotLongitude" type="number" min="-180" max="180" step="0.00000001" value="<%= lot.lotLongitude %>" /> <input class="input" id="lot--lotLongitude" name="lotLongitude" type="number" min="-180" max="180" step="0.00000001" value="<%= lot.lotLongitude %>" onwheel="return false" />
</div> </div>
</div> </div>
</div> </div>
@ -159,7 +163,11 @@
<div class="field has-addons"> <div class="field has-addons">
<div class="control is-expanded"> <div class="control is-expanded">
<div class="select is-fullwidth"> <div class="select is-fullwidth">
<select id="lot--mapId" name="mapId"> <select
<% if (!isCreate) { %>
class="is-readonly"
<% } %>
id="lot--mapId" name="mapId">
<option value="" <%= (!isCreate && lot.mapId ? " disabled" : "") %>> <option value="" <%= (!isCreate && lot.mapId ? " disabled" : "") %>>
(No <%= configFunctions.getProperty("aliases.map") %> Selected) (No <%= configFunctions.getProperty("aliases.map") %> Selected)
</option> </option>
@ -209,12 +217,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="panel mb-5">
<h2 class="panel-heading">
Additional Details
</h2>
<div class="panel-block"></div>
</div>
<div class="has-text-right mb-4 is-hidden-print"> <div class="has-text-right mb-4 is-hidden-print">
<button class="button is-primary" type="submit"> <button class="button is-primary" type="submit">
@ -224,6 +226,26 @@
<%= configFunctions.getProperty("aliases.lot") %> <%= configFunctions.getProperty("aliases.lot") %>
</span> </span>
</button> </button>
<% if (!isCreate) { %>
<div class="dropdown is-right ml-2">
<div class="dropdown-trigger">
<button class="button" type="button">
<span>More Options</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu">
<div class="dropdown-content">
<a class="dropdown-item" id="button--deleteLot" href="#">
<span class="icon is-small"><i class="fas fa-trash has-text-danger" aria-hidden="true"></i></span>
<span>Delete <%= configFunctions.getProperty("aliases.lot") %></span>
</a>
</div>
</div>
</div>
<% } %>
</div> </div>
</form> </form>