@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
783 lines • 204 kB
JavaScript
import { PdfViewerBase, AjaxHandler } from '../index';
import { createElement, Browser, Internationalization, isBlazor, isNullOrUndefined, SanitizeHtmlHelper } from '@syncfusion/ej2-base';
import { Accordion, ContextMenu as Context } from '@syncfusion/ej2-navigations';
import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor';
import { cloneObject } from '../drawing/drawing-util';
/**
* StickyNotes module
*/
var StickyNotesAnnotation = /** @class */ (function () {
/**
* @param {PdfViewer} pdfViewer - It describes about the pdfviewer
* @param {PdfViewerBase} pdfViewerBase - It describes about the pdfviewer base
* @private
*/
function StickyNotesAnnotation(pdfViewer, pdfViewerBase) {
this.moreButtonId = '';
this.commentsCount = 0;
this.commentsreplyCount = 0;
this.commentContextMenu = [];
this.isAccordionContainer = true;
this.isCreateContextMenu = false;
this.isCommentsSelected = false;
/**
* @private
*/
this.isAddAnnotationProgramatically = false;
/**
* @private
*/
this.isEditableElement = false;
this.isPageCommentsRendered = false;
this.isCommentsRendered = false;
/**
* @private
*/
this.isAnnotationRendered = false;
/**
* @private
*/
this.textFromCommentPanel = false;
this.pdfViewer = pdfViewer;
this.pdfViewerBase = pdfViewerBase;
this.opacity = this.pdfViewer.stickyNotesSettings.opacity ? this.pdfViewer.stickyNotesSettings.opacity : 1;
}
/**
* @param {any} stickyAnnotations - It describes about the sticky annotations
* @param {number} pageNumber - It describes about the page number
* @param {any} canvas - It describes about the canvas
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.renderStickyNotesAnnotations = function (stickyAnnotations, pageNumber, canvas) {
if (stickyAnnotations) {
if (stickyAnnotations.length > 0) {
for (var i = 0; i < stickyAnnotations.length; i++) {
var annotation = stickyAnnotations[parseInt(i.toString(), 10)];
var isAdded = false;
var pageAnnotations = this.getAnnotations(pageNumber, null, 'sticky');
if (pageAnnotations !== null) {
for (var k = 0; k < pageAnnotations.length; k++) {
var annotationName = annotation.annotName ? annotation.annotName : annotation.AnnotName;
var pageAnnotationName = pageAnnotations[parseInt(k.toString(), 10)].annotName ?
pageAnnotations[parseInt(k.toString(), 10)].annotName :
pageAnnotations[parseInt(k.toString(), 10)].AnnotName;
if (pageAnnotationName && annotationName && pageAnnotationName === annotationName) {
isAdded = true;
break;
}
}
}
if (!isAdded) {
annotation.annotationAddMode =
this.pdfViewer.annotationModule.findAnnotationMode(annotation, pageNumber, annotation.AnnotType);
var annotationObject = null;
var position = annotation.Bounds;
var author = annotation.Author;
annotation.AnnotationSettings = annotation.AnnotationSettings ?
annotation.AnnotationSettings : this.pdfViewer.annotationModule.updateAnnotationSettings(annotation);
annotation.allowedInteractions = annotation.AllowedInteraction ?
annotation.AllowedInteraction : this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
var isPrint = true;
if (annotation.annotationAddMode === 'Imported Annotation') {
isPrint = annotation.IsPrint;
}
else {
isPrint = annotation.AnnotationSettings.isPrint;
}
if (annotation.IsLock || annotation.IsLocked) {
annotation.AnnotationSettings.isLock = annotation.IsLock ? annotation.IsLock : annotation.IsLocked;
}
annotationObject = {
shapeAnnotationType: 'sticky', author: author, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject, note: annotation.Note, opacity: annotation.Opacity, state: annotation.State, stateModel: annotation.StateModel,
pathData: '', comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, author), review: { state: annotation.State, stateModel: annotation.StateModel, modifiedDate: annotation.ModifiedDate, author: author }, pageNumber: pageNumber,
bounds: { left: annotation.Bounds.X, top: annotation.Bounds.Y, width: annotation.Bounds.Width,
height: annotation.Bounds.Height, right: annotation.Bounds.Right, bottom: annotation.Bounds.Bottom },
annotName: annotation.AnnotName, color: annotation.color,
annotationSelectorSettings: this.getSettings(annotation),
customData: this.pdfViewer.annotation.getCustomData(annotation),
annotationSettings: annotation.AnnotationSettings, allowedInteractions: annotation.allowedInteractions,
isPrint: isPrint, isCommentLock: annotation.IsCommentLock
};
annotation.AnnotationSelectorSettings = annotation.AnnotationSelectorSettings ?
annotation.AnnotationSelectorSettings : this.pdfViewer.annotationSelectorSettings;
var annot = {
author: author, modifiedDate: annotationObject.modifiedDate, annotName: annotationObject.annotName, pageIndex: pageNumber, bounds: { x: position.Left, y: position.Top, width: position.Width, height: position.Height }, strokeColor: 'transparent', stampStrokeColor: '', data: this.setImageSource(), shapeAnnotationType: 'StickyNotes',
subject: annotationObject.subject, notes: annotationObject.note, opacity: annotationObject.opacity,
id: annotationObject.annotName, fillColor: annotationObject.color,
annotationSelectorSettings: annotation.AnnotationSelectorSettings,
annotationSettings: annotationObject.annotationSettings,
annotationAddMode: annotation.annotationAddMode, isPrint: isPrint, isCommentLock: annotationObject.isCommentLock
};
if (canvas) {
this.drawStickyNotes(position.Left, position.Top, position.Width, position.Height, pageNumber, annot, canvas);
}
else {
this.pdfViewer.add(annot);
this.drawStickyNotes(position.Left, position.Top, position.Width, position.Height, pageNumber, annot);
this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotationObject, '_annotations_sticky');
}
if (this.isAddAnnotationProgramatically) {
var settings = {
opacity: annot.opacity, borderColor: annot.strokeColor, borderWidth: annot.thickness,
author: annotation.author, subject: annotation.subject, modifiedDate: annotation.modifiedDate,
fillColor: annot.fillColor, fontSize: annot.fontSize, width: annot.bounds.width,
height: annot.bounds.height, fontColor: annot.fontColor, fontFamily: annot.fontFamily,
defaultText: annot.dynamicText, fontStyle: annot.font, textAlignment: annot.textAlign
};
this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, 'StickyNotes', annot.bounds, settings);
}
}
}
}
}
};
/**
* @param {any} annotation - It describes about the annotation
* @private
* @returns {any} - any
*/
StickyNotesAnnotation.prototype.getSettings = function (annotation) {
var selector = this.pdfViewer.annotationSelectorSettings;
if (annotation.AnnotationSelectorSettings) {
selector = typeof (annotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(annotation.AnnotationSelectorSettings) : annotation.AnnotationSelectorSettings;
}
else if (this.pdfViewer.stickyNotesSettings.annotationSelectorSettings) {
selector = this.pdfViewer.stickyNotesSettings.annotationSelectorSettings;
}
return selector;
};
/**
* @param {number} X - It describes about the X
* @param {number} Y - It describes about the Y
* @param {number} width - It describes about the width
* @param {number} height - It describes about the height
* @param {number} pageIndex - It describes about the page index
* @param {any} annotation - It describes about the annotation
* @param {any} canvas - It describes about the canvas
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.drawStickyNotes = function (X, Y, width, height, pageIndex, annotation, canvas) {
var _this = this;
var annot;
var annotationObject = null;
var image = new Image();
// eslint-disable-next-line
var proxy = this;
image.onload = function () {
var commentsDivid;
var annotationName;
var author = (_this.pdfViewer.annotationSettings.author !== 'Guest') ? _this.pdfViewer.annotationSettings.author : _this.pdfViewer.stickyNotesSettings.author;
var subject = (_this.pdfViewer.annotationSettings.subject !== '' && !isNullOrUndefined(_this.pdfViewer.annotationSettings.subject)) ? _this.pdfViewer.annotationSettings.subject : _this.pdfViewer.stickyNotesSettings.subject ? _this.pdfViewer.stickyNotesSettings.subject : 'Sticky Note';
var annotationSettings = _this.pdfViewer.annotationModule.updateSettings(_this.pdfViewer.stickyNotesSettings);
if (annotation) {
annot = {
author: annotation.author, modifiedDate: annotation.modifiedDate, annotName: annotation.annotName, annotationSettings: annotation.annotationSettings && annotation.annotationSettings !== '' ? annotation.annotationSettings : annotationSettings,
data: image.src, bounds: { x: X, y: Y, width: width, height: height }, subject: annotation.subject,
notes: annotation.notes, opacity: annotation.opacity, id: annotation.annotName, shapeAnnotationType: 'StickyNotes', strokeColor: 'transparent', stampStrokeColor: '', pageIndex: annotation.pageIndex, isPrint: annotation.isPrint
};
}
else {
annotationName = _this.pdfViewer.annotation.createGUID();
commentsDivid = proxy.addComments('sticky', pageIndex + 1);
if (commentsDivid) {
document.getElementById(commentsDivid).id = annotationName;
}
var annotationSelectorSettings = _this.pdfViewer.stickyNotesSettings.annotationSelectorSettings ?
_this.pdfViewer.stickyNotesSettings.annotationSelectorSettings : _this.pdfViewer.annotationSelectorSettings;
var isPrint = _this.pdfViewer.stickyNotesSettings.isPrint;
annot = {
bounds: { x: X, y: Y, width: width, height: height }, pageIndex: pageIndex, data: image.src,
modifiedDate: _this.getDateAndTime(), annotationSettings: annotationSettings,
shapeAnnotationType: 'StickyNotes', strokeColor: 'transparent', stampStrokeColor: '', annotName: annotationName, id: annotationName, opacity: _this.opacity, isPrint: isPrint
};
var isLock = _this.pdfViewer.stickyNotesSettings.isLock ?
_this.pdfViewer.stickyNotesSettings.isLock : _this.pdfViewer.annotationSettings.isLock;
var allowedInteractions = _this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
annotationObject = {
author: author, allowedInteractions: allowedInteractions, modifiedDate: _this.getDateAndTime(), subject: subject, shapeAnnotationType: 'sticky', pageNumber: pageIndex,
note: '', opacity: _this.opacity, pathData: '', state: '', stateModel: '', color: 'rgba(255,255,0)', comments: [], annotName: annotationName,
bounds: { left: X, top: Y, width: width, height: height }, review: { state: '', stateModel: '', modifiedDate: '', author: author },
annotationSelectorSettings: annotationSelectorSettings,
customData: _this.pdfViewer.annotationModule.getData('sticky'), annotationSettings: { isLock: isLock }, isPrint: isPrint, isCommentLock: false
};
}
if (!annotation) {
proxy.pdfViewer.annotation.addAction(pageIndex, null, annot, 'Addition', '', annot, annot);
proxy.pdfViewer.add(annot);
proxy.pdfViewer.annotationModule.storeAnnotations(pageIndex, annotationObject, '_annotations_sticky');
}
if (proxy.pdfViewerBase.isAddComment) {
var bounds = { left: annot.bounds.x, top: annot.bounds.y, width: annot.bounds.width, height: annot.bounds.height };
_this.pdfViewerBase.updateDocumentEditedProperty(true);
var settings = { opacity: annot.opacity, author: author, modifiedDate: annot.modifiedDate, subject: subject };
_this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, 'StickyNotes', bounds, settings);
}
if (canvas) {
proxy.pdfViewer.renderDrawing(canvas, pageIndex);
}
else {
var canvass = _this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex);
proxy.pdfViewer.renderDrawing(canvass, pageIndex);
}
if (Browser.isDevice) {
proxy.pdfViewer.select([annot.id], annot.annotationSelectorSettings);
}
proxy.pdfViewerBase.isAddComment = false;
};
image.src = this.setImageSource();
};
StickyNotesAnnotation.prototype.setImageSource = function () {
var imageSource = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgd2lkdGg9IjE2IgogICBoZWlnaHQ9IjE1IgogICB2aWV3Qm94PSIwIDAgNC4yMzMzMzMxIDMuOTY4NzQ5NyIKICAgdmVyc2lvbj0iMS4xIj4KICA8ZyBpZD0ibGF5ZXIxIj4KICAgIDxwYXRoCiAgICAgICBkPSJNIDMuODM4OSwwLjk0MTY3IEMgMy42NTM5LDAuNzAzNjcgMy40MTU5LDAuNTE3NjcgMy4xMjQ5LDAuMzg1NjcgMi44MDc5LDAuMjUzNjcgMi40ODk5LDAuMTczNjcgMi4xMTk5LDAuMTczNjcgMS43NDg5LDAuMTczNjcgMS40MzE5LDAuMjUzNjcgMS4xMTQyLDAuMzg1NjcgMC44MjMxNiwwLjUxNzY3IDAuNTg1MTYsMC43MDM2NyAwLjQwMDE2LDAuOTQxNjcgMC4yMTUxNiwxLjE3OTcgMC4xMzUxNiwxLjQxNzcgMC4xMzUxNiwxLjcwODcgMC4xMzUxNiwxLjk0NjcgMC4xODgxNiwyLjE1ODcgMC4zMjAxNiwyLjM0MzcgMC40NTMxNiwyLjU1NTcgMC42MTExNiwyLjcxMzcgMC44MjMxNiwyLjg0NjcgMC43OTIxNiwzLjE1NDcgMC42NTAxNiwzLjM4MjcgMC40NzkxNiwzLjU4NzcgMC40MjgxNiwzLjY2NzcgMC41MTcxNiwzLjc0MTcgMC42OTExNiwzLjcxOTcgMS4wODgyLDMuNjM5NyAxLjQwNDksMy40NTQ3IDEuNjQyOSwzLjE2MzcgMS44MDE5LDMuMTkwNyAxLjk2MDksMy4yMTY3IDIuMTE5OSwzLjIxNjcgMi40ODk5LDMuMjE2NyAyLjgwNzksMy4xMzc3IDMuMTI0OSwzLjAwNTcgMy40MTU5LDIuODcyNyAzLjY4MDksMi42ODc3IDMuODM4OSwyLjQ0OTcgNC4wMjQ5LDIuMjExNyA0LjEwMzksMS45NzM3IDQuMTAzOSwxLjY4MjcgNC4xMDM5LDEuNDE3NyA0LjAyNDksMS4xNTI3IDMuODM4OSwwLjk0MTY3IFoiCiAgICAgICBpZD0icGF0aDE1MjQiCiAgICAgICBzdHlsZT0iZmlsbDojZmZmNzAwO2ZpbGwtb3BhY2l0eToxO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDowLjI2NDU4MztzdHJva2Utb3BhY2l0eToxIiAvPgogICAgPHBhdGgKICAgICAgIGQ9Ik0gMy4wNDI5LDEuNDE2NyBIIDEuMTkxMiBDIDEuMTExMiwxLjQxNjcgMS4wNTkyLDEuMzYzNyAxLjA1OTIsMS4yODM3IDEuMDU5MiwxLjIwNDcgMS4xMTEyLDEuMTUxNyAxLjE5MTIsMS4xNTE3IEggMy4wNDI5IEMgMy4xMjE5LDEuMTUxNyAzLjE3NDksMS4yMDQ3IDMuMTc0OSwxLjI4MzcgMy4xNzQ5LDEuMzYzNyAzLjEyMTksMS40MTY3IDMuMDQyOSwxLjQxNjcgWiIKICAgICAgIGlkPSJwYXRoMTUzNiIKICAgICAgIHN0eWxlPSJzdHJva2Utd2lkdGg6MC4yNjQ1ODMiIC8+CiAgICA8cGF0aAogICAgICAgZD0iTSAzLjA0MjksMS45NDU3IEggMS4xOTEyIEMgMS4xMTEyLDEuOTQ1NyAxLjA1OTIsMS44OTI3IDEuMDU5MiwxLjgxMjcgMS4wNTkyLDEuNzMzNyAxLjExMTIsMS42ODA3IDEuMTkxMiwxLjY4MDcgSCAzLjA0MjkgQyAzLjEyMTksMS42ODA3IDMuMTc0OSwxLjczMzcgMy4xNzQ5LDEuODEyNyAzLjE3NDksMS44OTI3IDMuMTIxOSwxLjk0NTcgMy4wNDI5LDEuOTQ1NyBaIgogICAgICAgaWQ9InBhdGgxNTQwIgogICAgICAgc3R5bGU9InN0cm9rZS13aWR0aDowLjI2NDU4MyIgLz4KICA8L2c+Cjwvc3ZnPgo=';
return imageSource;
};
/**
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.createRequestForComments = function () {
var jsonObject;
// eslint-disable-next-line
var proxy = this;
var startIndex = 0;
var pageLimit = 20;
var pageCount = proxy.pdfViewerBase.pageCount;
if (!proxy.isCommentsRendered) {
if (pageLimit < pageCount) {
pageCount = pageLimit;
}
else {
proxy.isPageCommentsRendered = true;
}
}
if (!this.isCommentsRendered) {
jsonObject = { pageStartIndex: startIndex.toString(), pageEndIndex: pageCount.toString(), hashId: this.pdfViewerBase.hashId, action: 'RenderAnnotationComments', elementId: this.pdfViewer.element.id, uniqueId: proxy.pdfViewerBase.documentId };
proxy.isCommentsRendered = true;
}
else {
jsonObject = { pageStartIndex: pageLimit.toString(), pageEndIndex: pageCount.toString(), hashId: this.pdfViewerBase.hashId, action: 'RenderAnnotationComments', elementId: this.pdfViewer.element.id, uniqueId: proxy.pdfViewerBase.documentId };
}
if (this.pdfViewerBase.jsonDocumentId) {
jsonObject.documentId = this.pdfViewerBase.jsonDocumentId;
}
var url = this.pdfViewer.serviceUrl + '/' + this.pdfViewer.serverActionSettings.renderComments;
proxy.commentsRequestHandler = new AjaxHandler(proxy.pdfViewer);
proxy.commentsRequestHandler.url = url;
proxy.commentsRequestHandler.mode = true;
proxy.commentsRequestHandler.responseType = 'text';
if (this.pdfViewerBase.clientSideRendering) {
var data = this.pdfViewer.pdfRendererModule.getAnnotationComments(jsonObject);
this.renderCommentsOnSuccess(data, proxy);
}
else {
this.pdfViewerBase.requestCollection.push(this.commentsRequestHandler);
proxy.commentsRequestHandler.send(jsonObject);
proxy.commentsRequestHandler.onSuccess = function (result) {
var data = result.data;
var redirect = proxy.pdfViewerBase.checkRedirection(data);
if (!redirect) {
if (data) {
if (typeof data !== 'object') {
try {
data = JSON.parse(data);
if (typeof data !== 'object') {
data = JSON.parse(data);
}
if (typeof data !== 'object') {
proxy.pdfViewerBase.onControlError(500, data, this.pdfViewer.serverActionSettings.renderComments);
data = null;
}
}
catch (error) {
proxy.pdfViewerBase.onControlError(500, data, this.pdfViewer.serverActionSettings.renderComments);
data = null;
}
}
proxy.renderCommentsOnSuccess(data, proxy);
}
}
};
proxy.commentsRequestHandler.onFailure = function (result) {
this.pdfViewer.fireAjaxRequestFailed(result.status, result.statusText);
};
proxy.commentsRequestHandler.onError = function (result) {
proxy.pdfViewer.fireAjaxRequestFailed(result.status, result.statusText, proxy.pdfViewer.serverActionSettings.renderComments);
};
}
};
StickyNotesAnnotation.prototype.renderCommentsOnSuccess = function (data, proxy) {
if (data) {
var isInitialRender = false;
if (proxy.pdfViewerBase.annotationComments) {
proxy.pdfViewerBase.annotationComments = data.annotationDetails;
}
else {
proxy.pdfViewerBase.annotationComments = data.annotationDetails;
isInitialRender = true;
}
if (data.annotationDetails && data.uniqueId === proxy.pdfViewerBase.documentId) {
proxy.pdfViewer.fireAjaxRequestSuccess(this.pdfViewer.serverActionSettings.renderComments, data);
proxy.isAnnotationRendered = true;
var annotationCollections = void 0;
if (proxy.pdfViewerBase.documentAnnotationCollections) {
annotationCollections = proxy.updateAnnotationsInDocumentCollections(proxy.pdfViewerBase.annotationComments, proxy.pdfViewerBase.documentAnnotationCollections);
}
else {
var newCollection = proxy.pdfViewerBase.createAnnotationsCollection();
annotationCollections = proxy.updateAnnotationsInDocumentCollections(proxy.pdfViewerBase.annotationComments, newCollection);
}
proxy.pdfViewerBase.annotationComments = annotationCollections;
proxy.pdfViewerBase.documentAnnotationCollections = annotationCollections;
for (var i = data.startPageIndex; i < data.endPageIndex; i++) {
var newData = data.annotationDetails[parseInt(i.toString(), 10)];
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'annotationOrder');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'freeTextAnnotation');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'measureShapeAnnotation');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'shapeAnnotation');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'signatureAnnotation');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'signatureInkAnnotation');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'stampAnnotations');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'stickyNotesAnnotation');
proxy.pdfViewerBase.updateModifiedDateToLocalDate(newData, 'textMarkupAnnotation');
}
for (var j = data.startPageIndex; j < data.endPageIndex; j++) {
if (data.annotationDetails[parseInt(j.toString(), 10)]) {
proxy.renderAnnotationCollections(data.annotationDetails[parseInt(j.toString(), 10)], j, isInitialRender);
}
}
if (!proxy.isPageCommentsRendered) {
proxy.isPageCommentsRendered = true;
proxy.createRequestForComments();
}
}
}
};
/**
* @param {any} excistingAnnotation - It describes about the existing annotation
* @param {any} newAnnotation - It describes about the new annotation
* @private
* @returns {any} - any
*/
StickyNotesAnnotation.prototype.updateAnnotationsInDocumentCollections = function (excistingAnnotation, newAnnotation) {
for (var i = 0; i < this.pdfViewerBase.pageCount; i++) {
if (excistingAnnotation[parseInt(i.toString(), 10)] && newAnnotation[parseInt(i.toString(), 10)]) {
if (excistingAnnotation[parseInt(i.toString(), 10)].textMarkupAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].textMarkupAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].textMarkupAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].textMarkupAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
textMarkupAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].textMarkupAnnotation);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].shapeAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].shapeAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].shapeAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].shapeAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
shapeAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].shapeAnnotation);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].measureShapeAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].measureShapeAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].measureShapeAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].measureShapeAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
measureShapeAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].
measureShapeAnnotation);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].stampAnnotations &&
excistingAnnotation[parseInt(i.toString(), 10)].stampAnnotations.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].stampAnnotations) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].stampAnnotations.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
stampAnnotations[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].stampAnnotations);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].stickyNotesAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].stickyNotesAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].stickyNotesAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].stickyNotesAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
stickyNotesAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].
stickyNotesAnnotation);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].freeTextAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].freeTextAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].freeTextAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].freeTextAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
freeTextAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].
freeTextAnnotation);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].signatureAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].signatureAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].signatureAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].signatureAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
signatureAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].
signatureAnnotation);
}
}
if (excistingAnnotation[parseInt(i.toString(), 10)].signatureInkAnnotation &&
excistingAnnotation[parseInt(i.toString(), 10)].signatureInkAnnotation.length !== 0 &&
newAnnotation[parseInt(i.toString(), 10)].signatureInkAnnotation) {
for (var j = 0; j < excistingAnnotation[parseInt(i.toString(), 10)].signatureInkAnnotation.length; j++) {
this.updateDocumentAnnotationCollections(excistingAnnotation[parseInt(i.toString(), 10)].
signatureInkAnnotation[parseInt(j.toString(), 10)], newAnnotation[parseInt(i.toString(), 10)].signatureInkAnnotation);
}
}
}
}
return newAnnotation;
};
StickyNotesAnnotation.prototype.updateDocumentAnnotationCollections = function (excistingAnnotation, newAnnotation) {
if (newAnnotation.length === 0) {
newAnnotation.push(excistingAnnotation);
}
else {
var isAdded = false;
for (var i = 0; i < newAnnotation.length; i++) {
if ((excistingAnnotation.AnnotName && newAnnotation[parseInt(i.toString(), 10)].AnnotName) &&
(excistingAnnotation.AnnotName === newAnnotation[parseInt(i.toString(), 10)].AnnotName)) {
isAdded = true;
break;
}
}
if (!isAdded) {
newAnnotation.push(excistingAnnotation);
}
}
};
StickyNotesAnnotation.prototype.renderAnnotationCollections = function (pageAnnotations, pageNumber, isInitialRender) {
var pageCollections = [];
var collection = pageAnnotations.annotationOrder;
if (!isNullOrUndefined(collection)) {
for (var l = 0; l < collection.length; l++) {
var annotation = collection[parseInt(l.toString(), 10)];
var type = annotation.AnnotType ? annotation.AnnotType : annotation.AnnotationType;
if (this.pdfViewer.dateTimeFormat) {
annotation.ModifiedDate =
this.pdfViewer.annotationModule.stickyNotesAnnotationModule.getDateAndTime(annotation.ModifiedDate);
}
pageCollections.push(annotation);
switch (type) {
case 'textMarkup':
if (!isNullOrUndefined(this.pdfViewer.annotationModule) &&
(!isNullOrUndefined(this.pdfViewer.annotationModule.textMarkupAnnotationModule))) {
this.updateCollections(this.pdfViewer.annotationModule.textMarkupAnnotationModule.
updateTextMarkupAnnotationCollections(annotation, pageNumber));
}
break;
case 'shape_measure':
if (!isNullOrUndefined(this.pdfViewer.annotationModule) &&
(!isNullOrUndefined(this.pdfViewer.annotationModule.measureAnnotationModule))) {
this.updateCollections(this.pdfViewer.annotationModule.measureAnnotationModule.
updateMeasureAnnotationCollections(annotation, pageNumber));
}
break;
case 'shape':
if (!isNullOrUndefined(this.pdfViewer.annotationModule) &&
(!isNullOrUndefined(this.pdfViewer.annotationModule.shapeAnnotationModule))) {
this.updateCollections(this.pdfViewer.annotationModule.shapeAnnotationModule.
updateShapeAnnotationCollections(annotation, pageNumber));
}
break;
case 'sticky':
this.updateCollections(this.updateStickyNotesAnnotationCollections(annotation, pageNumber));
break;
case 'stamp':
if (!isNullOrUndefined(this.pdfViewer.annotationModule) &&
(!isNullOrUndefined(this.pdfViewer.annotationModule.stampAnnotationModule))) {
this.updateCollections(this.pdfViewer.annotationModule.stampAnnotationModule.
updateStampAnnotationCollections(annotation, pageNumber));
}
break;
case 'Ink':
if (!isNullOrUndefined(this.pdfViewer.annotationModule) &&
(!isNullOrUndefined(this.pdfViewer.annotationModule.inkAnnotationModule))) {
this.updateCollections(this.pdfViewer.annotationModule.inkAnnotationModule.
updateInkCollections(annotation, pageNumber));
}
break;
case 'Text Box':
if (!isNullOrUndefined(this.pdfViewer.annotationModule) &&
(!isNullOrUndefined(this.pdfViewer.annotationModule.freeTextAnnotationModule))) {
this.updateCollections(this.pdfViewer.annotationModule.freeTextAnnotationModule.
updateFreeTextAnnotationCollections(annotation, pageNumber));
}
break;
default:
break;
}
}
}
if (pageAnnotations.signatureAnnotation && pageAnnotations.signatureAnnotation.length !== 0) {
for (var i = 0; i < pageAnnotations.signatureAnnotation.length; i++) {
if (this.pdfViewer.dateTimeFormat) {
pageAnnotations.signatureAnnotation[parseInt(i.toString(), 10)].ModifiedDate =
this.pdfViewer.annotationModule.stickyNotesAnnotationModule.
getDateAndTime(pageAnnotations.signatureAnnotation[parseInt(i.toString(), 10)].ModifiedDate);
}
this.updateCollections(this.pdfViewerBase.signatureModule.
updateSignatureCollections(pageAnnotations.signatureAnnotation[parseInt(i.toString(), 10)], pageNumber), true);
}
}
if (this.pdfViewer.toolbarModule) {
this.renderAnnotationComments(pageCollections, pageNumber);
}
if (isInitialRender) {
for (var i = 0; i < this.pdfViewerBase.renderedPagesList.length; i++) {
if (this.pdfViewerBase.renderedPagesList[parseInt(i.toString(), 10)] === pageNumber) {
this.pdfViewerBase.renderAnnotations(pageNumber, pageAnnotations, false);
}
}
}
};
/**
* @param {any} annotation - It describes about the annotation
* @param {boolean} isSignature - It describes about the issignature
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.updateCollections = function (annotation, isSignature) {
var isAdded = false;
var collections;
if (isSignature) {
collections = this.pdfViewer.signatureCollection;
}
else {
collections = this.pdfViewer.annotationCollection;
}
if (collections && annotation) {
for (var i = 0; i < collections.length; i++) {
if (isSignature) {
if (collections[parseInt(i.toString(), 10)].signatureName === annotation.signatureName) {
isAdded = true;
break;
}
}
else {
if (collections[parseInt(i.toString(), 10)].annotationId === annotation.annotationId) {
isAdded = true;
break;
}
}
}
}
if (!isAdded && annotation) {
if (isSignature) {
this.pdfViewer.signatureCollection.push(annotation);
}
else {
this.pdfViewer.annotationCollection.push(annotation);
}
}
};
/**
* @param {any} data - It describes about the data
* @param {number} pageIndex - It describes about the page index
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.renderAnnotationComments = function (data, pageIndex) {
pageIndex = pageIndex + 1;
if (data) {
if (data.length !== 0) {
if (!(data.length === 1 && (data[0].AnnotationType === 'Signature' || data[0].AnnotationType === 'signature'))) {
this.createPageAccordion(pageIndex);
}
for (var i = 0; i < data.length; i++) {
if (data[parseInt(i.toString(), 10)].AnnotName && (data[parseInt(i.toString(), 10)].AnnotName.split('freeText').length === 1)) {
this.createCommentControlPanel(data[parseInt(i.toString(), 10)], pageIndex);
}
}
var newCommentsDiv = document.querySelectorAll('.e-pv-new-comments-div');
if (newCommentsDiv) {
for (var j = 0; j < newCommentsDiv.length; j++) {
newCommentsDiv[parseInt(j.toString(), 10)].style.display = 'none';
}
}
}
}
};
/**
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.initializeAcccordionContainer = function () {
var commentPanelText = createElement('div', { id: this.pdfViewer.element.id + '_commentsPanelText', className: 'e-pv-comments-panel-text' });
if (isBlazor()) {
var promise = this.pdfViewer._dotnetInstance.invokeMethodAsync('GetLocaleText', 'PdfViewer_NoCommentsYet');
promise.then(function (value) {
commentPanelText.textContent = value;
});
}
else {
commentPanelText.textContent = this.pdfViewer.localeObj.getConstant('No Comments Yet');
}
this.updateCommentPanelTextTop();
this.pdfViewerBase.navigationPane.commentsContentContainer.appendChild(commentPanelText);
this.accordionContentContainer = createElement('div', { id: this.pdfViewer.element.id + '_accordionContentContainer', className: 'e-pv-accordion-content-container' });
this.pdfViewerBase.navigationPane.commentsContentContainer.appendChild(this.accordionContentContainer);
this.pdfViewerBase.navigationPane.annotationMenuObj.enableItems([this.pdfViewer.localeObj.getConstant('Export Annotations')], false);
this.pdfViewerBase.navigationPane.annotationMenuObj.enableItems([this.pdfViewer.localeObj.getConstant('Export XFDF')], false);
};
/**
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.updateCommentPanelTextTop = function () {
var commentPanelText = document.getElementById(this.pdfViewer.element.id + '_commentsPanelText');
if (this.pdfViewerBase.navigationPane.commentPanelContainer && this.pdfViewerBase.navigationPane.commentPanelContainer.clientHeight && commentPanelText.style.display !== 'none') {
commentPanelText.style.paddingTop = (this.pdfViewerBase.navigationPane.commentPanelContainer.clientHeight / 2) - 47 + 'px';
commentPanelText.style.paddingLeft = (this.pdfViewerBase.navigationPane.commentPanelContainer.clientWidth) / 3 + 'px';
}
};
/**
* @param {number} pageIndex - It describes about the page index
* @private
* @returns {any} - any
*/
StickyNotesAnnotation.prototype.createPageAccordion = function (pageIndex) {
var pageAccordionContainer = document.getElementById(this.pdfViewer.element.id + '_accordionContainer' + pageIndex);
if (pageAccordionContainer === null) {
this.accordionContent = createElement('div', { id: this.pdfViewer.element.id + '_accordioncontent' + pageIndex });
this.accordionContent.style.zIndex = '1000';
this.accordionPageContainer = createElement('div', { id: this.pdfViewer.element.id + '_accordionPageContainer' + pageIndex, className: 'e-pv-accordion-page-container' });
this.accordionPageContainer.appendChild(this.accordionContent);
this.pdfViewerBase.viewerMainContainer.appendChild(this.accordionPageContainer);
this.accordionContainer = createElement('div', { id: this.pdfViewer.element.id + '_accordionContainer' + pageIndex, className: 'e-pv-accordion-container' });
var pageAccordion = new Accordion({
items: [
{ header: this.pdfViewer.localeObj.getConstant('Page') + ' ' + (pageIndex), expanded: true, content: '#' + this.pdfViewer.element.id + '_accordioncontent' + pageIndex + '' }
]
});
pageAccordion.appendTo(this.accordionContainer);
this.accordionContainer.style.order = 'pageIndex';
this.alignAccordionContainer(this.accordionContainer, pageIndex);
if (document.getElementById(this.pdfViewer.element.id + '_commentsPanelText')) {
this.pdfViewerBase.navigationPane.annotationMenuObj.enableItems([this.pdfViewer.localeObj.getConstant('Export Annotations')], true);
this.pdfViewerBase.navigationPane.annotationMenuObj.enableItems([this.pdfViewer.localeObj.getConstant('Export XFDF')], true);
document.getElementById(this.pdfViewer.element.id + '_commentsPanelText').style.display = 'none';
}
if (document.getElementById(this.pdfViewer.element.id + '_accordionContentContainer')) {
document.getElementById(this.pdfViewer.element.id + '_accordionContentContainer').style.display = 'block';
}
return this.accordionContainer;
}
};
StickyNotesAnnotation.prototype.alignAccordionContainer = function (accordionDiv, pageIndex) {
var isAdded = true;
if (this.accordionContentContainer) {
if (this.isAccordionContainer) {
this.accordionContentContainer.appendChild(accordionDiv);
isAdded = false;
}
else {
for (var i = 1; i <= this.pdfViewerBase.pageCount; i++) {
var nextElement = document.getElementById(this.pdfViewer.element.id + '_accordionContainer' + i);
if (nextElement) {
if (pageIndex < i) {
this.accordionContentContainer.insertBefore(accordionDiv, nextElement);
isAdded = false;
break;
}
}
}
}
if (isAdded) {
this.accordionContentContainer.appendChild(accordionDiv);
isAdded = false;
}
this.isAccordionContainer = false;
}
};
/**
* @param {number} pageNumber - It describes about the page number
* @private
* @returns {void}
*/
StickyNotesAnnotation.prototype.updateCommentPanelScrollTop = function (pageNumber) {
var accordionDiv = document.getElementById(this.pdfViewer.element.id + '_accordionContainer' + pageNumber);
if (accordionDiv) {
var scrollValue = accordionDiv.offsetTop + accordionDiv.clientTop - 35;
this.pdfViewerBase.navigationPane.commentsContentContainer.scrollTop = scrollValue;
}
};
StickyNotesAnnotation.prototype.getButtonState = function (editObj, commentTextBox) {
commentTextBox.addEventListener('keyup', function (event) {
if (editObj.element.querySelector('.e-btn-save')) {
if ((event.srcElement.value !== '' || event.srcElement.defaultValue !== '') && event.srcElement.defaultValue !== event.srcElement.value) {
editObj.element.querySelector('.e-btn-save').ej2_instances[0].disabled = false;
}
}
});
};
/**
* @param {any} data - It describes about the data
* @param {number} pageIndex - It describes about the page index
* @param {string} type - It describes about the type
* @param {string} annotationSubType - It describes about the annotation sub type
* @param {boolean} isReRender - It describes about the isRenderer
* @private
* @returns {string} - string
*/
StickyNotesAnnotation.prototype.createCommentControlPanel = function (data, pageIndex, type, annotationSubType, isReRender) {
var accordionContent = document.getElementById(this.pdfViewer.element.id + '_accordioncontent' + pageIndex);
if (accordionContent) {
var accordionExpand = document.getElementById(this.pdfViewer.element.id + '_accordionContainer' + pageIndex);
if (accordionExpand) {
accordionExpand.ej2_instances[0].expandItem(true);
}
this.commentsContainer = createElement('div', { id: this.pdfViewer.element.id + 'commentscontainer_' + pageIndex + '_' + this.commentsCount, className: 'e-pv-comments-container' });
this.commentsContainer.accessKey = pageIndex.toString() + '_' + this.commentsCount;
var isCommentsAdded = false;
if (data) {
this.commentsContainer.id = data.AnnotName;
if (data.AnnotName) {
for (var j = 0; j < accordionContent.childElementCount; j++) {
if (accordionContent.children[parseInt(j.toString(), 10)].id === data.AnnotName) {
isCommentsAdded = true;
if (isReRender) {
// To remove the existing div element in the comment panel while importing the annotation with the same name. (EJ2-62092)
var id = document.getElementById(accordionContent.children[parseInt(j.toString(), 10)].id);
id.remove();
isCommentsAdded = false;
}
break;
}
}
}
if (data.Name && data.Name === 'freeText') {
this.commentsContainer.setAttribute('name', 'freeText');
}
else {
this.commentsContainer.setAttribute('name', data.AnnotType);
}
}
if (type) {
this.commentsContainer.setAttribute('name', type);
}
this.commentsContainer.addEventListener('mousedown', this.commentsAnnotationSelect.bind(this));
var commentDiv = createElement('div', { id: this.pdfViewer.element.id + '_commentdiv_' + pageIndex + '_' + this.commentsCount, className: 'e-pv-comments-div' });
this.commentsCount = this.commentsCount + 1;
this.commentsContainer.appendChild(commentDiv);
this.updateCommentPanelScrollTop(pageIndex);
if (!isCommentsAdded) {
accordionContent.appendChild(this.commentsContainer);
}
var title = void 0;
if (data) {
title = this.commentsContainer.getAttribute('name');
if (title === 'null') {
title = data.AnnotationType;
}
this.createTitleContainer(commentDiv, title, pageIndex, data.Subject, data.ModifiedDate, data.Author);
}
else {
title = this.commentsContainer.getAttribute('name');
this.createTitleContainer(commentDiv, title, pageIndex, an