diff --git a/handlers/contracts-get/new.ts b/handlers/contracts-get/new.ts index 68f52f05..d6fa4216 100644 --- a/handlers/contracts-get/new.ts +++ b/handlers/contracts-get/new.ts @@ -20,6 +20,7 @@ export default async function handler( const contract: Partial = { isPreneed: false, + contractStartDate: dateToInteger(startDate), contractStartDateString: dateToString(startDate), purchaserCity: getConfigProperty('settings.cityDefault'), diff --git a/public/javascripts/contract.edit.js b/public/javascripts/contract.edit.js index 9477a32b..b4f6d74b 100644 --- a/public/javascripts/contract.edit.js +++ b/public/javascripts/contract.edit.js @@ -34,14 +34,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); } else { bulmaJS.alert({ - message: "Contract Updated Successfully", + message: 'Contract Updated Successfully', contextualColorName: 'success' }); } } else { bulmaJS.alert({ - title: "Error Saving Contract", + title: 'Error Saving Contract', message: responseJSON.errorMessage ?? '', contextualColorName: 'danger' }); @@ -83,7 +83,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); } else { bulmaJS.confirm({ - title: "Copy Contract Record as New", + title: 'Copy Contract Record as New', message: 'Are you sure you want to copy this record to a new record?', contextualColorName: 'info', okButton: { @@ -116,7 +116,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); } bulmaJS.confirm({ - title: "Delete Contract Record", + title: 'Delete Contract Record', message: 'Are you sure you want to delete this record?', contextualColorName: 'warning', okButton: { @@ -329,7 +329,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const burialSiteId = document.querySelector('#contract--burialSiteId').value; if (burialSiteId === '') { bulmaJS.alert({ - message: "No burial site selected.", + message: 'No burial site selected.', contextualColorName: 'info' }); } @@ -347,7 +347,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); } else { - burialSiteNameElement.value = "(No Burial Site)"; + burialSiteNameElement.value = '(No Burial Site)'; document.querySelector('#contract--burialSiteId').value = ''; setUnsavedChanges(); } @@ -359,6 +359,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const endDateElement = document.querySelector('#contract--contractEndDateString'); endDateElement.min = document.querySelector('#contract--contractStartDateString').value; }); + sunrise.initializeMinDateUpdate(document.querySelector('#contract--contractStartDateString'), document.querySelector('#contract--contractEndDateString')); sunrise.initializeUnlockFieldButtons(formElement); if (isCreate) { /* @@ -382,5 +383,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); } setUnsavedChanges(); }); + sunrise.initializeMinDateUpdate(document.querySelector('#contract--birthDateString'), document.querySelector('#contract--deathDateString')); + sunrise.initializeMinDateUpdate(document.querySelector('#contract--deathDateString'), document.querySelector('#contract--funeralDateString')); } })(); diff --git a/public/javascripts/contract.edit.ts b/public/javascripts/contract.edit.ts index 7b1907a0..94b0dcf5 100644 --- a/public/javascripts/contract.edit.ts +++ b/public/javascripts/contract.edit.ts @@ -4,10 +4,7 @@ import type { BulmaJS } from '@cityssm/bulma-js/types.js' import type { cityssmGlobal } from '@cityssm/bulma-webapp-js/src/types.js' -import type { - BurialSite, - ContractTypeField -} from '../../types/record.types.js' +import type { BurialSite, ContractTypeField } from '../../types/record.types.js' import type { Sunrise } from './types.js' @@ -71,13 +68,13 @@ declare const exports: Record ) } else { bulmaJS.alert({ - message: "Contract Updated Successfully", + message: 'Contract Updated Successfully', contextualColorName: 'success' }) } } else { bulmaJS.alert({ - title: "Error Saving Contract", + title: 'Error Saving Contract', message: responseJSON.errorMessage ?? '', contextualColorName: 'danger' }) @@ -136,7 +133,7 @@ declare const exports: Record }) } else { bulmaJS.confirm({ - title: "Copy Contract Record as New", + title: 'Copy Contract Record as New', message: 'Are you sure you want to copy this record to a new record?', contextualColorName: 'info', okButton: { @@ -179,7 +176,7 @@ declare const exports: Record } bulmaJS.confirm({ - title: "Delete Contract Record", + title: 'Delete Contract Record', message: 'Are you sure you want to delete this record?', contextualColorName: 'warning', okButton: { @@ -384,7 +381,8 @@ declare const exports: Record function selectExistingBurialSite(selectClickEvent: Event): void { selectClickEvent.preventDefault() - const selectedBurialSiteElement = selectClickEvent.currentTarget as HTMLElement + const selectedBurialSiteElement = + selectClickEvent.currentTarget as HTMLElement renderSelectedBurialSiteAndClose( selectedBurialSiteElement.dataset.burialSiteId ?? '', @@ -530,7 +528,7 @@ declare const exports: Record if (burialSiteId === '') { bulmaJS.alert({ - message: "No burial site selected.", + message: 'No burial site selected.', contextualColorName: 'info' }) } else { @@ -547,7 +545,7 @@ declare const exports: Record contextualColorName: 'info' }) } else { - burialSiteNameElement.value = "(No Burial Site)" + burialSiteNameElement.value = '(No Burial Site)' ;( document.querySelector('#contract--burialSiteId') as HTMLInputElement ).value = '' @@ -572,6 +570,15 @@ declare const exports: Record ).value }) + sunrise.initializeMinDateUpdate( + document.querySelector( + '#contract--contractStartDateString' + ) as HTMLInputElement, + document.querySelector( + '#contract--contractEndDateString' + ) as HTMLInputElement + ) + sunrise.initializeUnlockFieldButtons(formElement) if (isCreate) { @@ -605,5 +612,15 @@ declare const exports: Record setUnsavedChanges() }) + + sunrise.initializeMinDateUpdate( + document.querySelector('#contract--birthDateString') as HTMLInputElement, + document.querySelector('#contract--deathDateString') as HTMLInputElement + ) + + sunrise.initializeMinDateUpdate( + document.querySelector('#contract--deathDateString') as HTMLInputElement, + document.querySelector('#contract--funeralDateString') as HTMLInputElement + ) } })() diff --git a/public/javascripts/main.js b/public/javascripts/main.js index f0ec6c49..d9810a3b 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -99,8 +99,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); clickEvent.preventDefault(); if (currentMarker !== undefined) { const mapCoordinates = currentMarker.getLatLng(); - options.latitudeElement.value = mapCoordinates.lat.toFixed(coordinatePrecision); - options.longitudeElement.value = mapCoordinates.lng.toFixed(coordinatePrecision); + options.latitudeElement.value = + mapCoordinates.lat.toFixed(coordinatePrecision); + options.longitudeElement.value = + mapCoordinates.lng.toFixed(coordinatePrecision); options.callbackFunction(mapCoordinates.lat, mapCoordinates.lng); } closeModalFunction(); @@ -267,6 +269,15 @@ Object.defineProperty(exports, "__esModule", { value: true }); function getWorkOrderURL(workOrderId = '', edit = false, time = false) { return getRecordURL('workOrders', workOrderId, edit, time); } + /* + * Date Fields + */ + function initializeMinDateUpdate(minDateElement, valueDateElement) { + valueDateElement.min = minDateElement.value; + minDateElement.addEventListener('change', () => { + valueDateElement.min = minDateElement.value; + }); + } /* * Settings */ @@ -295,7 +306,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); getCemeteryURL, getContractURL, getFuneralHomeURL, - getWorkOrderURL + getWorkOrderURL, + initializeMinDateUpdate }; exports.sunrise = sunrise; })(); diff --git a/public/javascripts/main.ts b/public/javascripts/main.ts index 44476d79..53250197 100644 --- a/public/javascripts/main.ts +++ b/public/javascripts/main.ts @@ -173,8 +173,10 @@ declare const exports: Record & { if (currentMarker !== undefined) { const mapCoordinates = currentMarker.getLatLng() as Leaflet.LatLng - options.latitudeElement.value = mapCoordinates.lat.toFixed(coordinatePrecision) - options.longitudeElement.value = mapCoordinates.lng.toFixed(coordinatePrecision) + options.latitudeElement.value = + mapCoordinates.lat.toFixed(coordinatePrecision) + options.longitudeElement.value = + mapCoordinates.lng.toFixed(coordinatePrecision) options.callbackFunction(mapCoordinates.lat, mapCoordinates.lng) } @@ -440,6 +442,21 @@ declare const exports: Record & { return getRecordURL('workOrders', workOrderId, edit, time) } + /* + * Date Fields + */ + + function initializeMinDateUpdate( + minDateElement: HTMLInputElement, + valueDateElement: HTMLInputElement + ): void { + valueDateElement.min = minDateElement.value + + minDateElement.addEventListener('change', () => { + valueDateElement.min = minDateElement.value + }) + } + /* * Settings */ @@ -479,7 +496,9 @@ declare const exports: Record & { getCemeteryURL, getContractURL, getFuneralHomeURL, - getWorkOrderURL + getWorkOrderURL, + + initializeMinDateUpdate } exports.sunrise = sunrise diff --git a/public/javascripts/types.d.ts b/public/javascripts/types.d.ts index f4efbd77..eeeaf590 100644 --- a/public/javascripts/types.d.ts +++ b/public/javascripts/types.d.ts @@ -36,4 +36,5 @@ export interface Sunrise { getContractURL: (contractId?: number | string, edit?: boolean, time?: boolean) => string; getFuneralHomeURL: (funeralHomeId?: number | string, edit?: boolean, time?: boolean) => string; getWorkOrderURL: (workOrderId?: number | string, edit?: boolean, time?: boolean) => string; + initializeMinDateUpdate: (minDateElement: HTMLInputElement, valueDateElement: HTMLInputElement) => void; } diff --git a/public/javascripts/types.ts b/public/javascripts/types.ts index 9e7b87cb..d2df1d10 100644 --- a/public/javascripts/types.ts +++ b/public/javascripts/types.ts @@ -82,4 +82,9 @@ export interface Sunrise { edit?: boolean, time?: boolean ) => string + + initializeMinDateUpdate: ( + minDateElement: HTMLInputElement, + valueDateElement: HTMLInputElement + ) => void } diff --git a/public/javascripts/workOrder.edit.js b/public/javascripts/workOrder.edit.js index 6aaa32c3..f16d8962 100644 --- a/public/javascripts/workOrder.edit.js +++ b/public/javascripts/workOrder.edit.js @@ -271,6 +271,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); } }); } + const workOrderOpenDateStringElement = document.querySelector('#workOrderEdit--workOrderOpenDateString'); function editMilestone(clickEvent) { clickEvent.preventDefault(); const workOrderMilestoneId = Number.parseInt(clickEvent.currentTarget.closest('.container--milestone').dataset.workOrderMilestoneId ?? '', 10); @@ -319,6 +320,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); workOrderMilestoneDateStringElement = modalElement.querySelector('#milestoneEdit--workOrderMilestoneDateString'); workOrderMilestoneDateStringElement.value = workOrderMilestone.workOrderMilestoneDateString ?? ''; + workOrderMilestoneDateStringElement.min = + workOrderOpenDateStringElement.value; if (workOrderMilestone.workOrderMilestoneTime) { ; modalElement.querySelector('#milestoneEdit--workOrderMilestoneTimeString').value = workOrderMilestone.workOrderMilestoneTimeString ?? ''; @@ -484,6 +487,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); } workOrderMilestoneDateStringElement = modalElement.querySelector('#milestoneAdd--workOrderMilestoneDateString'); workOrderMilestoneDateStringElement.valueAsDate = new Date(); + workOrderMilestoneDateStringElement.min = + workOrderOpenDateStringElement.value; }, onshown(modalElement, closeModalFunction) { addCloseModalFunction = closeModalFunction; diff --git a/public/javascripts/workOrder.edit.ts b/public/javascripts/workOrder.edit.ts index 21e809b6..7493b906 100644 --- a/public/javascripts/workOrder.edit.ts +++ b/public/javascripts/workOrder.edit.ts @@ -420,6 +420,10 @@ declare const exports: Record }) } + const workOrderOpenDateStringElement = document.querySelector( + '#workOrderEdit--workOrderOpenDateString' + ) as HTMLInputElement + function editMilestone(clickEvent: Event): void { clickEvent.preventDefault() @@ -522,6 +526,9 @@ declare const exports: Record workOrderMilestoneDateStringElement.value = workOrderMilestone.workOrderMilestoneDateString ?? '' + workOrderMilestoneDateStringElement.min = + workOrderOpenDateStringElement.value + if (workOrderMilestone.workOrderMilestoneTime) { ;( modalElement.querySelector( @@ -559,7 +566,7 @@ declare const exports: Record conflictingMilestonePanelElement ) }, - + onremoved() { bulmaJS.toggleHtmlClipped() } @@ -770,6 +777,9 @@ declare const exports: Record ) as HTMLInputElement workOrderMilestoneDateStringElement.valueAsDate = new Date() + + workOrderMilestoneDateStringElement.min = + workOrderOpenDateStringElement.value }, onshown(modalElement, closeModalFunction) { addCloseModalFunction = closeModalFunction @@ -800,7 +810,7 @@ declare const exports: Record conflictingMilestonePanelElement ) }, - + onremoved() { bulmaJS.toggleHtmlClipped() ;( diff --git a/views/contract-edit.ejs b/views/contract-edit.ejs index 355a1f71..d832f559 100644 --- a/views/contract-edit.ejs +++ b/views/contract-edit.ejs @@ -382,10 +382,11 @@
- + +

15 minute intervals

@@ -623,6 +624,9 @@ + <% + const todayDateString = dateTimeFunctions.dateToString(new Date()); + %>
@@ -631,7 +635,8 @@
+ value="<%= contract.birthDateString %>" + max="<%= todayDateString %>" /> @@ -659,7 +664,8 @@
+ value="<%= contract.deathDateString %>" + max="<%= todayDateString %>" />