diff --git a/src/dbp-official-signature-pdf-upload.js b/src/dbp-official-signature-pdf-upload.js index 538499c71024cb567dbbfac05bfb6ea7e3cbafbe..2d112379411d59f01d7f29f342ac7421e1963c3a 100644 --- a/src/dbp-official-signature-pdf-upload.js +++ b/src/dbp-official-signature-pdf-upload.js @@ -52,6 +52,7 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem this.currentPreviewQueueKey = ''; this.allowAnnotating = false; this.queuedFilesAnnotations = []; + this.queuedFilesEnabledAnnotations = []; this.queuedFilesAnnotationsCount = 0; this.isAnnotationViewVisible = false; this.activity = new Activity(metadata); @@ -176,8 +177,9 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem fileSize: humanFileSize(file.size, false), }); + const annotationsEnabled = this.isAnnotationsEnabledForKey(key); const annotations = this.takeAnnotationsFromQueue(key); - await this.uploadFile(file, params, annotations); + await this.uploadFile(file, params, annotationsEnabled ? annotations : []); this.uploadInProgress = false; } diff --git a/src/dbp-signature-lit-element.js b/src/dbp-signature-lit-element.js index 649f4d9837473652d7585f5a037b84102edafbfa..a0028381507b6ea4be40818ee501043e326726a4 100644 --- a/src/dbp-signature-lit-element.js +++ b/src/dbp-signature-lit-element.js @@ -134,9 +134,13 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { this._(viewTag).setAnnotationRows(this.queuedFilesAnnotations[key]); this.isAnnotationViewVisible = true; + this.enableAnnotationsForKey(key); + } else { + this.disableAnnotationsForKey(key); - } else if (this.currentPreviewQueueKey === key) { - this.isAnnotationViewVisible = false; + if (this.currentPreviewQueueKey === key) { + this.isAnnotationViewVisible = false; + } } } @@ -219,10 +223,50 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { takeAnnotationsFromQueue(key) { const annotations = this.queuedFilesAnnotations[key]; delete this.queuedFilesAnnotations[key]; + this.disableAnnotationsForKey(key); return annotations; } + /** + * Checks if annotations are enabled for an annotation key + * + * @param key + * @returns {boolean} + */ + isAnnotationsEnabledForKey(key) { + return this.queuedFilesEnabledAnnotations.includes(key); + } + + /** + * Enables annotations for an annotation key + * + * @param key + */ + enableAnnotationsForKey(key) { + if (!this.isAnnotationsEnabledForKey(key)) { + this.queuedFilesEnabledAnnotations.push(key); + } + } + + /** + * Disables annotations for an annotation key + * + * @param key + */ + disableAnnotationsForKey(key) { + let i = 0; + + // remove all occurrences of the value "key" in array this.queuedFilesEnabledAnnotations + while (i < this.queuedFilesEnabledAnnotations.length) { + if (this.queuedFilesEnabledAnnotations[i] === key) { + this.queuedFilesEnabledAnnotations.splice(i, 1); + } else { + ++i; + } + } + } + /** * Update an annotation of a file on the queue *