refactor(annotations): replace global element index with element.id in generateId
- Removed global __elementIndex counter and updated generateId() to use element.id for unique annotation IDs. - Updated createAnnotations() and createImageAnnotation() to pass element.id to generateId(). - Simplified ID generation logic for better consistency and traceability across annotations.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
let __elementIndex = 0;
|
||||
|
||||
function generateId(envelopeId, receiverId, annotationType) {
|
||||
return `${envelopeId}#${receiverId}#${__elementIndex++}#${annotationType}`;
|
||||
function generateId(envelopeId, receiverId, elementId, annotationType) {
|
||||
return `${envelopeId}#${receiverId}#${elementId}#${annotationType}`;
|
||||
}
|
||||
|
||||
async function createAnnotations(document, envelopeId, receiverId) {
|
||||
@@ -12,7 +10,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
const page = element.page - 1
|
||||
|
||||
//#region signatures
|
||||
const id = generateId(envelopeId, receiverId, 'signature');
|
||||
const id = generateId(envelopeId, receiverId, element.id, 'signature');
|
||||
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id,
|
||||
pageIndex: page,
|
||||
@@ -29,7 +27,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
//#endregion
|
||||
|
||||
//#region position
|
||||
const id_position = generateId(envelopeId, receiverId, 'position');
|
||||
const id_position = generateId(envelopeId, receiverId, element.id, 'position');
|
||||
const annotation_position = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_position,
|
||||
pageIndex: page,
|
||||
@@ -49,7 +47,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
//#endregion
|
||||
|
||||
//#region city
|
||||
const id_city = generateId(envelopeId, receiverId, 'city');
|
||||
const id_city = generateId(envelopeId, receiverId, element.id, 'city');
|
||||
const annotation_city = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_city,
|
||||
pageIndex: page,
|
||||
@@ -69,7 +67,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
//#endregion
|
||||
|
||||
//#region date
|
||||
const id_date = generateId(envelopeId, receiverId, 'date');
|
||||
const id_date = generateId(envelopeId, receiverId, element.id, 'date');
|
||||
const annotation_date = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_date,
|
||||
pageIndex: page,
|
||||
@@ -97,7 +95,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
this.markFieldAsCity(formFieldCity);
|
||||
|
||||
//#region date label
|
||||
const id_date_label = generateId(envelopeId, receiverId, 'date_label');
|
||||
const id_date_label = generateId(envelopeId, receiverId, element.id, 'date_label');
|
||||
const annotation_date_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_date_label,
|
||||
pageIndex: page,
|
||||
@@ -120,7 +118,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
//#endregion
|
||||
|
||||
//#region city label
|
||||
const id_city_label = generateId(envelopeId, receiverId, 'city_label');
|
||||
const id_city_label = generateId(envelopeId, receiverId, element.id, 'city_label');
|
||||
const annotation_city_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_city_label,
|
||||
pageIndex: page,
|
||||
@@ -143,7 +141,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
||||
//#endregion
|
||||
|
||||
//#region position label
|
||||
const id_position_label = generateId(envelopeId, receiverId, 'position_label');
|
||||
const id_position_label = generateId(envelopeId, receiverId, element.id, 'position_label');
|
||||
const annotation_position_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id_position_label,
|
||||
pageIndex: page,
|
||||
@@ -219,9 +217,9 @@ function isSignature(annotation) {
|
||||
return !!annotation.isSignature || annotation.description == 'FRAME'
|
||||
}
|
||||
|
||||
function createImageAnnotation(boundingBox, pageIndex, imageAttachmentId, envelopeId, receiverId, annotationType) {
|
||||
function createImageAnnotation(boundingBox, pageIndex, imageAttachmentId, envelopeId, receiverId, elementId, annotationType) {
|
||||
const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({
|
||||
id: generateId(envelopeId, receiverId, annotationType),
|
||||
id: generateId(envelopeId, receiverId, elementId, annotationType),
|
||||
pageIndex: pageIndex,
|
||||
isSignature: false,
|
||||
readOnly: true,
|
||||
|
||||
Reference in New Issue
Block a user