diff --git a/EnvelopeGenerator.Web/wwwroot/js/annotation.js b/EnvelopeGenerator.Web/wwwroot/js/annotation.js index f10cfa81..c932d247 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/annotation.js +++ b/EnvelopeGenerator.Web/wwwroot/js/annotation.js @@ -3,11 +3,15 @@ const signatures = [] for(var element of document.elements){ - const [annotation, formField, annotation2, formFieldDate] = await Annotation.createSignature(element) + const [annotation, formField, annotation_date, formFieldDate, annotation_postcode, formFieldPostcode, annotation_city, formFieldCity] = await Annotation.createSignature(element) signatures.push(annotation) signatures.push(formField) - signatures.push(annotation2) + signatures.push(annotation_date) signatures.push(formFieldDate) + signatures.push(annotation_postcode) + signatures.push(formFieldPostcode) + signatures.push(annotation_city) + signatures.push(formFieldCity) } return [...signatures ] @@ -42,7 +46,6 @@ }) //date - var city = await getCity(); const id_date = PSPDFKit.generateInstantId() const annotation_date = new PSPDFKit.Annotations.WidgetAnnotation({ id: id_date, @@ -51,21 +54,74 @@ backgroundColor: PSPDFKit.Color.DarkBlue, blendMode: 'multiply', boundingBox: new PSPDFKit.Geometry.Rect({ - width: width * 1.5, + width: width * 0.75, height: height / 2, top: top + height + 25, left: left - width * .25, }), - fontSize:8 + fontSize:8, + additionalActions: { + onFormat: new PSPDFKit.Actions.JavaScriptAction({ + script: `AFDate_FormatEx("dd/mm/yyyy")`, + }), + } }) - + const formFieldDate = new PSPDFKit.FormFields.TextFormField({ name: id_date, annotationIds: PSPDFKit.Immutable.List([annotation_date.id]), - value: getLocaleDateString() + ", " + city + value: locale_date_dd_mm_yyyy() }) - return [annotation, formField, annotation_date, formFieldDate] + //post_code + var location = await getLocation(); + const id_postcode = PSPDFKit.generateInstantId() + const annotation_postcode = new PSPDFKit.Annotations.WidgetAnnotation({ + id: id_postcode, + pageIndex: page, + formFieldName: id_postcode, + backgroundColor: PSPDFKit.Color.DarkBlue, + blendMode: 'multiply', + boundingBox: new PSPDFKit.Geometry.Rect({ + width: width * 0.45, + height: height / 2, + top: top + height + 25, + left: left - width * .25 + width * 0.80, + }), + fontSize:8 + }) + + const formFieldPostcode = new PSPDFKit.FormFields.TextFormField({ + name: id_postcode, + annotationIds: PSPDFKit.Immutable.List([annotation_postcode.id]), + value: location.postalCode + }) + + //city + var location = await getLocation(); + const id_city = PSPDFKit.generateInstantId() + const annotation_city = new PSPDFKit.Annotations.WidgetAnnotation({ + id: id_city, + pageIndex: page, + formFieldName: id_city, + backgroundColor: PSPDFKit.Color.DarkBlue, + blendMode: 'multiply', + boundingBox: new PSPDFKit.Geometry.Rect({ + width: width * 0.75, + height: height / 2, + top: top + height + 25, + left: left - width * .25 + width * 1.30, + }), + fontSize:8 + }) + + const formFieldCity = new PSPDFKit.FormFields.TextFormField({ + name: id_city, + annotationIds: PSPDFKit.Immutable.List([annotation_city.id]), + value: location.city + }) + + return [annotation, formField, annotation_date, formFieldDate, annotation_postcode, formFieldPostcode, annotation_city, formFieldCity] } static createTextBox(element) { diff --git a/EnvelopeGenerator.Web/wwwroot/js/util.js b/EnvelopeGenerator.Web/wwwroot/js/util.js index b54353ec..86719f1c 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/util.js +++ b/EnvelopeGenerator.Web/wwwroot/js/util.js @@ -29,4 +29,29 @@ async function getCity() { } } -const getLocaleDateString = _ => new Date().toLocaleDateString('de-DE') \ No newline at end of file +async function getLocation() { + try { + const coords = await getCoordinates(); + const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`); + const data = await response.json(); + + if (data && data.address) { + const city = data.address.city || data.address.town || data.address.village || data.address.hamlet; + const postalCode = data.address.postcode; + return { postalCode: postalCode, city: city }; + } + } catch { + return { postalCode: '', city: '' }; + } +} + +const getLocaleDateString = _ => new Date().toLocaleDateString('de-DE') + +function locale_date_dd_mm_yyyy() { + const today = new Date(); + const day = String(today.getDate()).padStart(2, '0'); + const month = String(today.getMonth() + 1).padStart(2, '0'); + const year = String(today.getFullYear()).slice(-4); + console.log(`${day}/${month}/${year}`) + return `${day}/${month}/${year}`; +} \ No newline at end of file