refactor(annotation): generate deterministic annotation IDs based on envelopeId, receiverId, and element index
This commit is contained in:
parent
41738bb36c
commit
3f116ce11a
@ -1,5 +1,4 @@
|
|||||||
|
async function createAnnotations(document, envelopeId, receiverId) {
|
||||||
async function createAnnotations(document, envelopeId, receiverId) {
|
|
||||||
const signatures = [];
|
const signatures = [];
|
||||||
|
|
||||||
for (let element of document.elements) {
|
for (let element of document.elements) {
|
||||||
@ -7,12 +6,18 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
const page = element.page - 1
|
const page = element.page - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let elementIndex = 0;
|
||||||
|
|
||||||
|
function generateId(annotationType) {
|
||||||
|
return `${envelopeId}_${receiverId}_${elementIndex++}_${annotationType}`;
|
||||||
|
}
|
||||||
|
|
||||||
for (let element of document.elements) {
|
for (let element of document.elements) {
|
||||||
const annotParams = await getAnnotationParams(element.left, element.top);
|
const annotParams = await getAnnotationParams(element.left, element.top);
|
||||||
const page = element.page - 1
|
const page = element.page - 1
|
||||||
|
|
||||||
//#region signatures
|
//#region signatures
|
||||||
const id = PSPDFKit.generateInstantId()
|
const id = generateId('signature');
|
||||||
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id,
|
id: id,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -29,7 +34,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region position
|
//#region position
|
||||||
const id_position = PSPDFKit.generateInstantId()
|
const id_position = generateId('position');
|
||||||
const annotation_position = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation_position = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id_position,
|
id: id_position,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -49,7 +54,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region city
|
//#region city
|
||||||
const id_city = PSPDFKit.generateInstantId()
|
const id_city = generateId('city');
|
||||||
const annotation_city = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation_city = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id_city,
|
id: id_city,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -69,7 +74,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region date
|
//#region date
|
||||||
const id_date = PSPDFKit.generateInstantId()
|
const id_date = generateId('date');
|
||||||
const annotation_date = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation_date = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id_date,
|
id: id_date,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -97,7 +102,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
this.markFieldAsCity(formFieldCity);
|
this.markFieldAsCity(formFieldCity);
|
||||||
|
|
||||||
//#region date label
|
//#region date label
|
||||||
const id_date_label = PSPDFKit.generateInstantId()
|
const id_date_label = generateId('date_label');
|
||||||
const annotation_date_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation_date_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id_date_label,
|
id: id_date_label,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -120,7 +125,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region city label
|
//#region city label
|
||||||
const id_city_label = PSPDFKit.generateInstantId()
|
const id_city_label = generateId('city_label');
|
||||||
const annotation_city_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation_city_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id_city_label,
|
id: id_city_label,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
@ -143,7 +148,7 @@ async function createAnnotations(document, envelopeId, receiverId) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region position label
|
//#region position label
|
||||||
const id_position_label = PSPDFKit.generateInstantId()
|
const id_position_label = generateId('position_label');
|
||||||
const annotation_position_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
const annotation_position_label = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||||
id: id_position_label,
|
id: id_position_label,
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user