date field restrictions

pull/11/head
Dan Gowans 2025-04-24 14:48:13 -04:00
parent 9a153bb238
commit 9bfed5aa4d
10 changed files with 107 additions and 28 deletions

View File

@ -20,6 +20,7 @@ export default async function handler(
const contract: Partial<Contract> = { const contract: Partial<Contract> = {
isPreneed: false, isPreneed: false,
contractStartDate: dateToInteger(startDate), contractStartDate: dateToInteger(startDate),
contractStartDateString: dateToString(startDate), contractStartDateString: dateToString(startDate),
purchaserCity: getConfigProperty('settings.cityDefault'), purchaserCity: getConfigProperty('settings.cityDefault'),

View File

@ -34,14 +34,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
else { else {
bulmaJS.alert({ bulmaJS.alert({
message: "Contract Updated Successfully", message: 'Contract Updated Successfully',
contextualColorName: 'success' contextualColorName: 'success'
}); });
} }
} }
else { else {
bulmaJS.alert({ bulmaJS.alert({
title: "Error Saving Contract", title: 'Error Saving Contract',
message: responseJSON.errorMessage ?? '', message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger' contextualColorName: 'danger'
}); });
@ -83,7 +83,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
else { else {
bulmaJS.confirm({ 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?', message: 'Are you sure you want to copy this record to a new record?',
contextualColorName: 'info', contextualColorName: 'info',
okButton: { okButton: {
@ -116,7 +116,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
}); });
} }
bulmaJS.confirm({ bulmaJS.confirm({
title: "Delete Contract Record", title: 'Delete Contract Record',
message: 'Are you sure you want to delete this record?', message: 'Are you sure you want to delete this record?',
contextualColorName: 'warning', contextualColorName: 'warning',
okButton: { okButton: {
@ -329,7 +329,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const burialSiteId = document.querySelector('#contract--burialSiteId').value; const burialSiteId = document.querySelector('#contract--burialSiteId').value;
if (burialSiteId === '') { if (burialSiteId === '') {
bulmaJS.alert({ bulmaJS.alert({
message: "No burial site selected.", message: 'No burial site selected.',
contextualColorName: 'info' contextualColorName: 'info'
}); });
} }
@ -347,7 +347,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
}); });
} }
else { else {
burialSiteNameElement.value = "(No Burial Site)"; burialSiteNameElement.value = '(No Burial Site)';
document.querySelector('#contract--burialSiteId').value = ''; document.querySelector('#contract--burialSiteId').value = '';
setUnsavedChanges(); setUnsavedChanges();
} }
@ -359,6 +359,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const endDateElement = document.querySelector('#contract--contractEndDateString'); const endDateElement = document.querySelector('#contract--contractEndDateString');
endDateElement.min = document.querySelector('#contract--contractStartDateString').value; endDateElement.min = document.querySelector('#contract--contractStartDateString').value;
}); });
sunrise.initializeMinDateUpdate(document.querySelector('#contract--contractStartDateString'), document.querySelector('#contract--contractEndDateString'));
sunrise.initializeUnlockFieldButtons(formElement); sunrise.initializeUnlockFieldButtons(formElement);
if (isCreate) { if (isCreate) {
/* /*
@ -382,5 +383,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
setUnsavedChanges(); setUnsavedChanges();
}); });
sunrise.initializeMinDateUpdate(document.querySelector('#contract--birthDateString'), document.querySelector('#contract--deathDateString'));
sunrise.initializeMinDateUpdate(document.querySelector('#contract--deathDateString'), document.querySelector('#contract--funeralDateString'));
} }
})(); })();

View File

@ -4,10 +4,7 @@
import type { BulmaJS } from '@cityssm/bulma-js/types.js' import type { BulmaJS } from '@cityssm/bulma-js/types.js'
import type { cityssmGlobal } from '@cityssm/bulma-webapp-js/src/types.js' import type { cityssmGlobal } from '@cityssm/bulma-webapp-js/src/types.js'
import type { import type { BurialSite, ContractTypeField } from '../../types/record.types.js'
BurialSite,
ContractTypeField
} from '../../types/record.types.js'
import type { Sunrise } from './types.js' import type { Sunrise } from './types.js'
@ -71,13 +68,13 @@ declare const exports: Record<string, unknown>
) )
} else { } else {
bulmaJS.alert({ bulmaJS.alert({
message: "Contract Updated Successfully", message: 'Contract Updated Successfully',
contextualColorName: 'success' contextualColorName: 'success'
}) })
} }
} else { } else {
bulmaJS.alert({ bulmaJS.alert({
title: "Error Saving Contract", title: 'Error Saving Contract',
message: responseJSON.errorMessage ?? '', message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger' contextualColorName: 'danger'
}) })
@ -136,7 +133,7 @@ declare const exports: Record<string, unknown>
}) })
} else { } else {
bulmaJS.confirm({ 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?', message: 'Are you sure you want to copy this record to a new record?',
contextualColorName: 'info', contextualColorName: 'info',
okButton: { okButton: {
@ -179,7 +176,7 @@ declare const exports: Record<string, unknown>
} }
bulmaJS.confirm({ bulmaJS.confirm({
title: "Delete Contract Record", title: 'Delete Contract Record',
message: 'Are you sure you want to delete this record?', message: 'Are you sure you want to delete this record?',
contextualColorName: 'warning', contextualColorName: 'warning',
okButton: { okButton: {
@ -384,7 +381,8 @@ declare const exports: Record<string, unknown>
function selectExistingBurialSite(selectClickEvent: Event): void { function selectExistingBurialSite(selectClickEvent: Event): void {
selectClickEvent.preventDefault() selectClickEvent.preventDefault()
const selectedBurialSiteElement = selectClickEvent.currentTarget as HTMLElement const selectedBurialSiteElement =
selectClickEvent.currentTarget as HTMLElement
renderSelectedBurialSiteAndClose( renderSelectedBurialSiteAndClose(
selectedBurialSiteElement.dataset.burialSiteId ?? '', selectedBurialSiteElement.dataset.burialSiteId ?? '',
@ -530,7 +528,7 @@ declare const exports: Record<string, unknown>
if (burialSiteId === '') { if (burialSiteId === '') {
bulmaJS.alert({ bulmaJS.alert({
message: "No burial site selected.", message: 'No burial site selected.',
contextualColorName: 'info' contextualColorName: 'info'
}) })
} else { } else {
@ -547,7 +545,7 @@ declare const exports: Record<string, unknown>
contextualColorName: 'info' contextualColorName: 'info'
}) })
} else { } else {
burialSiteNameElement.value = "(No Burial Site)" burialSiteNameElement.value = '(No Burial Site)'
;( ;(
document.querySelector('#contract--burialSiteId') as HTMLInputElement document.querySelector('#contract--burialSiteId') as HTMLInputElement
).value = '' ).value = ''
@ -572,6 +570,15 @@ declare const exports: Record<string, unknown>
).value ).value
}) })
sunrise.initializeMinDateUpdate(
document.querySelector(
'#contract--contractStartDateString'
) as HTMLInputElement,
document.querySelector(
'#contract--contractEndDateString'
) as HTMLInputElement
)
sunrise.initializeUnlockFieldButtons(formElement) sunrise.initializeUnlockFieldButtons(formElement)
if (isCreate) { if (isCreate) {
@ -605,5 +612,15 @@ declare const exports: Record<string, unknown>
setUnsavedChanges() 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
)
} }
})() })()

View File

@ -99,8 +99,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
clickEvent.preventDefault(); clickEvent.preventDefault();
if (currentMarker !== undefined) { if (currentMarker !== undefined) {
const mapCoordinates = currentMarker.getLatLng(); const mapCoordinates = currentMarker.getLatLng();
options.latitudeElement.value = mapCoordinates.lat.toFixed(coordinatePrecision); options.latitudeElement.value =
options.longitudeElement.value = mapCoordinates.lng.toFixed(coordinatePrecision); mapCoordinates.lat.toFixed(coordinatePrecision);
options.longitudeElement.value =
mapCoordinates.lng.toFixed(coordinatePrecision);
options.callbackFunction(mapCoordinates.lat, mapCoordinates.lng); options.callbackFunction(mapCoordinates.lat, mapCoordinates.lng);
} }
closeModalFunction(); closeModalFunction();
@ -267,6 +269,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
function getWorkOrderURL(workOrderId = '', edit = false, time = false) { function getWorkOrderURL(workOrderId = '', edit = false, time = false) {
return getRecordURL('workOrders', workOrderId, edit, time); return getRecordURL('workOrders', workOrderId, edit, time);
} }
/*
* Date Fields
*/
function initializeMinDateUpdate(minDateElement, valueDateElement) {
valueDateElement.min = minDateElement.value;
minDateElement.addEventListener('change', () => {
valueDateElement.min = minDateElement.value;
});
}
/* /*
* Settings * Settings
*/ */
@ -295,7 +306,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
getCemeteryURL, getCemeteryURL,
getContractURL, getContractURL,
getFuneralHomeURL, getFuneralHomeURL,
getWorkOrderURL getWorkOrderURL,
initializeMinDateUpdate
}; };
exports.sunrise = sunrise; exports.sunrise = sunrise;
})(); })();

View File

@ -173,8 +173,10 @@ declare const exports: Record<string, unknown> & {
if (currentMarker !== undefined) { if (currentMarker !== undefined) {
const mapCoordinates = currentMarker.getLatLng() as Leaflet.LatLng const mapCoordinates = currentMarker.getLatLng() as Leaflet.LatLng
options.latitudeElement.value = mapCoordinates.lat.toFixed(coordinatePrecision) options.latitudeElement.value =
options.longitudeElement.value = mapCoordinates.lng.toFixed(coordinatePrecision) mapCoordinates.lat.toFixed(coordinatePrecision)
options.longitudeElement.value =
mapCoordinates.lng.toFixed(coordinatePrecision)
options.callbackFunction(mapCoordinates.lat, mapCoordinates.lng) options.callbackFunction(mapCoordinates.lat, mapCoordinates.lng)
} }
@ -440,6 +442,21 @@ declare const exports: Record<string, unknown> & {
return getRecordURL('workOrders', workOrderId, edit, time) 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 * Settings
*/ */
@ -479,7 +496,9 @@ declare const exports: Record<string, unknown> & {
getCemeteryURL, getCemeteryURL,
getContractURL, getContractURL,
getFuneralHomeURL, getFuneralHomeURL,
getWorkOrderURL getWorkOrderURL,
initializeMinDateUpdate
} }
exports.sunrise = sunrise exports.sunrise = sunrise

View File

@ -36,4 +36,5 @@ export interface Sunrise {
getContractURL: (contractId?: number | string, edit?: boolean, time?: boolean) => string; getContractURL: (contractId?: number | string, edit?: boolean, time?: boolean) => string;
getFuneralHomeURL: (funeralHomeId?: 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; getWorkOrderURL: (workOrderId?: number | string, edit?: boolean, time?: boolean) => string;
initializeMinDateUpdate: (minDateElement: HTMLInputElement, valueDateElement: HTMLInputElement) => void;
} }

View File

@ -82,4 +82,9 @@ export interface Sunrise {
edit?: boolean, edit?: boolean,
time?: boolean time?: boolean
) => string ) => string
initializeMinDateUpdate: (
minDateElement: HTMLInputElement,
valueDateElement: HTMLInputElement
) => void
} }

View File

@ -271,6 +271,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
}); });
} }
const workOrderOpenDateStringElement = document.querySelector('#workOrderEdit--workOrderOpenDateString');
function editMilestone(clickEvent) { function editMilestone(clickEvent) {
clickEvent.preventDefault(); clickEvent.preventDefault();
const workOrderMilestoneId = Number.parseInt(clickEvent.currentTarget.closest('.container--milestone').dataset.workOrderMilestoneId ?? '', 10); 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 = modalElement.querySelector('#milestoneEdit--workOrderMilestoneDateString');
workOrderMilestoneDateStringElement.value = workOrderMilestoneDateStringElement.value =
workOrderMilestone.workOrderMilestoneDateString ?? ''; workOrderMilestone.workOrderMilestoneDateString ?? '';
workOrderMilestoneDateStringElement.min =
workOrderOpenDateStringElement.value;
if (workOrderMilestone.workOrderMilestoneTime) { if (workOrderMilestone.workOrderMilestoneTime) {
; ;
modalElement.querySelector('#milestoneEdit--workOrderMilestoneTimeString').value = workOrderMilestone.workOrderMilestoneTimeString ?? ''; modalElement.querySelector('#milestoneEdit--workOrderMilestoneTimeString').value = workOrderMilestone.workOrderMilestoneTimeString ?? '';
@ -484,6 +487,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
workOrderMilestoneDateStringElement = modalElement.querySelector('#milestoneAdd--workOrderMilestoneDateString'); workOrderMilestoneDateStringElement = modalElement.querySelector('#milestoneAdd--workOrderMilestoneDateString');
workOrderMilestoneDateStringElement.valueAsDate = new Date(); workOrderMilestoneDateStringElement.valueAsDate = new Date();
workOrderMilestoneDateStringElement.min =
workOrderOpenDateStringElement.value;
}, },
onshown(modalElement, closeModalFunction) { onshown(modalElement, closeModalFunction) {
addCloseModalFunction = closeModalFunction; addCloseModalFunction = closeModalFunction;

View File

@ -420,6 +420,10 @@ declare const exports: Record<string, unknown>
}) })
} }
const workOrderOpenDateStringElement = document.querySelector(
'#workOrderEdit--workOrderOpenDateString'
) as HTMLInputElement
function editMilestone(clickEvent: Event): void { function editMilestone(clickEvent: Event): void {
clickEvent.preventDefault() clickEvent.preventDefault()
@ -522,6 +526,9 @@ declare const exports: Record<string, unknown>
workOrderMilestoneDateStringElement.value = workOrderMilestoneDateStringElement.value =
workOrderMilestone.workOrderMilestoneDateString ?? '' workOrderMilestone.workOrderMilestoneDateString ?? ''
workOrderMilestoneDateStringElement.min =
workOrderOpenDateStringElement.value
if (workOrderMilestone.workOrderMilestoneTime) { if (workOrderMilestone.workOrderMilestoneTime) {
;( ;(
modalElement.querySelector( modalElement.querySelector(
@ -559,7 +566,7 @@ declare const exports: Record<string, unknown>
conflictingMilestonePanelElement conflictingMilestonePanelElement
) )
}, },
onremoved() { onremoved() {
bulmaJS.toggleHtmlClipped() bulmaJS.toggleHtmlClipped()
} }
@ -770,6 +777,9 @@ declare const exports: Record<string, unknown>
) as HTMLInputElement ) as HTMLInputElement
workOrderMilestoneDateStringElement.valueAsDate = new Date() workOrderMilestoneDateStringElement.valueAsDate = new Date()
workOrderMilestoneDateStringElement.min =
workOrderOpenDateStringElement.value
}, },
onshown(modalElement, closeModalFunction) { onshown(modalElement, closeModalFunction) {
addCloseModalFunction = closeModalFunction addCloseModalFunction = closeModalFunction
@ -800,7 +810,7 @@ declare const exports: Record<string, unknown>
conflictingMilestonePanelElement conflictingMilestonePanelElement
) )
}, },
onremoved() { onremoved() {
bulmaJS.toggleHtmlClipped() bulmaJS.toggleHtmlClipped()
;( ;(

View File

@ -382,10 +382,11 @@
<div class="field"> <div class="field">
<label class="label" for="contract--funeralTimeString">Time</label> <label class="label" for="contract--funeralTimeString">Time</label>
<div class="control has-icons-left"> <div class="control has-icons-left">
<input class="input" id="contract--funeralTimeString" name="funeralTimeString" type="time" value="<%= contract.funeralTimeString %>" /> <input class="input" id="contract--funeralTimeString" name="funeralTimeString" type="time" value="<%= contract.funeralTimeString %>" step="900" />
<span class="icon is-left"> <span class="icon is-left">
<i class="fas fa-clock" aria-hidden="true"></i> <i class="fas fa-clock" aria-hidden="true"></i>
</span> </span>
<p class="help">15 minute intervals</p>
</div> </div>
</div> </div>
</div> </div>
@ -623,6 +624,9 @@
</div> </div>
</div> </div>
</div> </div>
<%
const todayDateString = dateTimeFunctions.dateToString(new Date());
%>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<div class="field"> <div class="field">
@ -631,7 +635,8 @@
</label> </label>
<div class="control has-icons-left"> <div class="control has-icons-left">
<input class="input" id="contract--birthDateString" name="birthDateString" type="date" <input class="input" id="contract--birthDateString" name="birthDateString" type="date"
value="<%= contract.birthDateString %>" /> value="<%= contract.birthDateString %>"
max="<%= todayDateString %>" />
<span class="icon is-left"> <span class="icon is-left">
<i class="fas fa-calendar" aria-hidden="true"></i> <i class="fas fa-calendar" aria-hidden="true"></i>
</span> </span>
@ -659,7 +664,8 @@
</label> </label>
<div class="control has-icons-left"> <div class="control has-icons-left">
<input class="input" id="contract--deathDateString" name="deathDateString" type="date" <input class="input" id="contract--deathDateString" name="deathDateString" type="date"
value="<%= contract.deathDateString %>" /> value="<%= contract.deathDateString %>"
max="<%= todayDateString %>" />
<span class="icon is-left"> <span class="icon is-left">
<i class="fas fa-calendar" aria-hidden="true"></i> <i class="fas fa-calendar" aria-hidden="true"></i>
</span> </span>