UNPKG

@syncfusion/ej2-pdfviewer

Version:
770 lines 200 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { AjaxHandler } from '../index'; import { createElement, Browser, initializeCSPTemplate, isNullOrUndefined, getComponent, Draggable, Droppable } from '@syncfusion/ej2-base'; import { Tooltip, Dialog } from '@syncfusion/ej2-popups'; import { CheckBox } from '@syncfusion/ej2-buttons'; import { Toolbar, ContextMenu } from '@syncfusion/ej2-navigations'; import { createSpinner, showSpinner, hideSpinner } from '../base/spinner'; import { TaskPriorityLevel } from '../base/pdfviewer-utlis'; /** * The `PageOrganizer` module is used to handle page organize operations of PDF viewer. * * @param {Event} event - The event triggering the page organization. * @param {Object} args - Additional arguments for the page organization. * @returns {void} */ var PageOrganizer = /** @class */ (function () { /** * @param {PdfViewer} pdfViewer - It describes about the pdfviewer * @param {PdfViewerBase} pdfViewerBase - It describes about the pdfviewer base * @private */ function PageOrganizer(pdfViewer, pdfViewerBase) { var _this = this; /** * @private */ this.dataDetails = []; this.mobileContextMenu = []; /** * @private */ this.organizePagesCollection = []; this.tempOrganizePagesCollection = []; this.isSkipRevert = false; this.isAllImagesReceived = false; this.selectedPageIndexes = []; this.autoScrollInterval = null; this.gapBetweenDivs = 48; /** * @private */ this.isDocumentModified = false; /** * @private */ this.undoOrganizeCollection = []; /** * @private */ this.redoOrganizeCollection = []; /** * @private */ this.toolbarUndoRedoCollection = []; this.isTouchEvent = false; /** * @private */ this.isOrganizeWindowOpen = false; this.pageDragDrop = function (event) { var mainTileElement = event.target.closest('.e-pv-organize-anchor-node'); var pageOrder = parseInt(mainTileElement.getAttribute('data-page-order'), 10); _this.dragEndIndex = pageOrder; _this.movePDFpages(_this.selectedPageIndexes, _this.dragEndIndex, _this.isRightInsertion); }; /** * @param {MouseEvent} event - It describes about the event * @private * @returns {void} */ this.thumbnailMouseOver = function (event) { // eslint-disable-next-line var proxy = _this; if (event.currentTarget instanceof HTMLElement) { // Convert HTMLCollection to an array var childrenArray = Array.from(event.currentTarget.children); // Iterate over the array for (var _i = 0, childrenArray_1 = childrenArray; _i < childrenArray_1.length; _i++) { var subchild = childrenArray_1[_i]; var childArray = Array.from(subchild.children); for (var _a = 0, childArray_1 = childArray; _a < childArray_1.length; _a++) { var child = childArray_1[_a]; // Exclude the image by checking its type if (!(child.classList.contains('e-pv-image-container'))) { // Set the display style property to "none" for other children child.style.display = 'flex'; if (child.classList.contains('e-checkbox-wrapper')) { child.children[0].style.display = 'block'; } else if (child.classList.contains('e-pv-organize-buttondiv') && child.childElementCount > 0) { var childelementArray = Array.from(child.children); for (var _b = 0, childelementArray_1 = childelementArray; _b < childelementArray_1.length; _b++) { var childelement = childelementArray_1[_b]; if (proxy.totalCheckedCount > 1) { if (childelement.id.split('_')[1] === 'insert') { childelement.style.display = 'flex'; } else { childelement.style.display = 'none'; } } else { childelement.style.display = 'flex'; } } } } } } } }; /** * @param {MouseEvent} event - It describes about the event * @private * @returns {void} */ this.thumbnailMouseLeave = function (event) { if (event.currentTarget instanceof HTMLElement) { // Convert HTMLCollection to an array var childrenArray = Array.from(event.currentTarget.children); // Iterate over the array for (var _i = 0, childrenArray_2 = childrenArray; _i < childrenArray_2.length; _i++) { var subchild = childrenArray_2[_i]; var childArray = Array.from(subchild.children); for (var _a = 0, childArray_2 = childArray; _a < childArray_2.length; _a++) { var child = childArray_2[_a]; // Exclude the image by checking its type if (!(child.classList.contains('e-pv-image-container'))) { if (event.currentTarget.classList.contains('e-pv-organize-node-selection-ring')) { if (child.classList.contains('e-checkbox-wrapper')) { child.style.display = 'block'; } else { child.style.display = 'none'; } } else { // Set the display style property to "none" for other children child.style.display = 'none'; } } } } } }; this.onSelectClick = function (args) { var checkboxElement = event.currentTarget.querySelector('.e-pv-organize-tile-checkbox'); var pageElement = checkboxElement.closest('.e-pv-organize-anchor-node'); if (args.event.pointerType === 'mouse' || (!_this.isTouchEvent && !(Browser.isDevice && !_this.pdfViewer.enableDesktopMode))) { if (_this.isClickedOnCheckBox && !isNullOrUndefined(checkboxElement) && !isNullOrUndefined(pageElement)) { if (pageElement) { _this.setSelectionRingStyle(checkboxElement, pageElement); } } else if (!isNullOrUndefined(checkboxElement) && !isNullOrUndefined(pageElement)) { if (!(_this.ctrlKey || _this.shiftKey)) { var previouslySelectedTiles = document.querySelectorAll('.e-pv-organize-node-selection-ring'); if (previouslySelectedTiles.length > 0) { for (var i = 0; i < previouslySelectedTiles.length; i++) { var previousCheckbox = previouslySelectedTiles[parseInt(i.toString(), 10)].closest('.e-pv-organize-anchor-node').querySelector('.e-pv-organize-tile-checkbox'); previousCheckbox.checked = false; _this.setSelectionRingStyle(previousCheckbox, previouslySelectedTiles[parseInt(i.toString(), 10)]); } } if (!_this.isClickedOnCheckBox) { checkboxElement.checked = true; } } if (_this.shiftKey) { checkboxElement.checked = true; } _this.setSelectionRingStyle(checkboxElement, pageElement); } } else if (args.event.pointerType === 'touch' || _this.isTouchEvent || (Browser.isDevice && !_this.pdfViewer.enableDesktopMode)) { if (!isNullOrUndefined(checkboxElement) && !isNullOrUndefined(pageElement)) { if (pageElement) { _this.setSelectionRingStyle(checkboxElement, pageElement); } } } _this.updateSelectAllCheckbox(); _this.enableDisableToolbarItems(); if (_this.totalCheckedCount > 1) { for (var i = 0; i < pageElement.querySelector('.e-pv-organize-buttondiv').childElementCount; i++) { var id = pageElement.querySelector('.e-pv-organize-buttondiv').children[parseInt(i.toString(), 10)].id; if (id.split('_')[1] === 'insert') { pageElement.querySelector('.e-pv-organize-buttondiv').children[parseInt(i.toString(), 10)].style.display = 'flex'; } else { pageElement.querySelector('.e-pv-organize-buttondiv').children[parseInt(i.toString(), 10)].style.display = 'none'; } } } }; this.rotateButtonClick = function (event) { if (_this.pdfViewer.pageOrganizerSettings.canRotate) { var rotateButton = event.currentTarget; var mainTileElement = rotateButton.closest('.e-pv-organize-anchor-node'); var imageContainer = mainTileElement.querySelector('.e-pv-organize-image'); var pageOrder_1 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); if (imageContainer) { // Get the current rotation angle of the image container (if any) var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0; // Calculate the new rotation angle (add 90 degrees) currentRotation += 90; // Ensure that the rotation stays within the desired range (0, 90, 180, 270, 360) if (currentRotation >= 360) { currentRotation = 0; } // Apply the rotation to the image container imageContainer.style.transform = "rotate(" + currentRotation + "deg)"; // Update the rotation value in the pageDetails collection _this.updateTempRotationDetail(pageOrder_1, 90); var clonedCollection = []; clonedCollection.push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder_1; }))); _this.addOrganizeAction(clonedCollection, 'Rotate Right', [], [], null, false); } } }; this.rotateLeftButtonClick = function (event) { if (_this.pdfViewer.pageOrganizerSettings.canRotate) { var rotateButton = event.currentTarget; var mainTileElement = rotateButton.closest('.e-pv-organize-anchor-node'); var imageContainer = mainTileElement.querySelector('.e-pv-organize-image'); var pageOrder_2 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); if (imageContainer) { // Get the current rotation angle of the image container (if any) var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0; // Calculate the new rotation angle (add 90 degrees) currentRotation -= 90; // Ensure that the rotation stays within the desired range (0, 90, 180, 270, 360) if (currentRotation >= 360) { currentRotation = 0; } if (currentRotation === -90) { currentRotation = 270; } // Apply the rotation to the image container imageContainer.style.transform = "rotate(" + currentRotation + "deg)"; // Update the rotation value in the pageDetails collection _this.updateTempRotationDetail(pageOrder_2, -90); var clonedCollection = []; clonedCollection.push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder_2; }))); _this.addOrganizeAction(clonedCollection, 'Rotate Left', [], [], null, false); } } }; this.onToolbarRightButtonClick = function () { if (_this.pdfViewer.pageOrganizerSettings.canRotate) { // eslint-disable-next-line var proxy = _this; var _loop_1 = function (i) { var mainTileElement = proxy.tileAreaDiv.childNodes[parseInt(i.toString(), 10)]; // Type assertion to HTMLElement if (mainTileElement instanceof HTMLElement && mainTileElement.classList.contains('e-pv-organize-node-selection-ring')) { var imageContainer = mainTileElement.querySelector('.e-pv-organize-image'); var pageOrder_3 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); if (imageContainer) { // Get the current rotation angle of the image container (if any) var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0; // Calculate the new rotation angle (add 90 degrees) currentRotation += 90; // Ensure that the rotation stays within the desired range (0, 90, 180, 270, 360) if (currentRotation >= 360) { currentRotation = 0; } // Apply the rotation to the image container imageContainer.style.transform = "rotate(" + currentRotation + "deg)"; // Update the rotation value in the pageDetails collection _this.updateTempRotationDetail(pageOrder_3, 90); _this.toolbarUndoRedoCollection. push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder_3; }))); } } }; for (var i = 0; i < proxy.tileAreaDiv.childElementCount; i++) { _loop_1(i); } _this.addOrganizeAction(null, 'Toolbar Rotate Right', _this.toolbarUndoRedoCollection, [], null, false); _this.toolbarUndoRedoCollection = []; } }; this.onToolbarLeftButtonClick = function () { // eslint-disable-next-line var proxy = _this; var _loop_2 = function (i) { var mainTileElement = proxy.tileAreaDiv.childNodes[parseInt(i.toString(), 10)]; // Type assertion to HTMLElement if (mainTileElement instanceof HTMLElement && mainTileElement.classList.contains('e-pv-organize-node-selection-ring')) { var imageContainer = mainTileElement.querySelector('.e-pv-organize-image'); var pageOrder_4 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); if (imageContainer) { // Get the current rotation angle of the image container (if any) var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0; // Calculate the new rotation angle (add 90 degrees) currentRotation -= 90; // Ensure that the rotation stays within the desired range (0, 90, 180, 270, 360) if (currentRotation >= 360) { currentRotation = 0; } if (currentRotation === -90) { currentRotation = 270; } // Apply the rotation to the image container imageContainer.style.transform = "rotate(" + currentRotation + "deg)"; // Update the rotation value in the pageDetails collection _this.updateTempRotationDetail(pageOrder_4, -90); _this.toolbarUndoRedoCollection. push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder_4; }))); } } }; for (var i = 0; i < proxy.tileAreaDiv.childElementCount; i++) { _loop_2(i); } _this.addOrganizeAction(null, 'Toolbar Rotate Left', _this.toolbarUndoRedoCollection, [], null, false); _this.toolbarUndoRedoCollection = []; }; this.onToolbarCopyButtonClick = function () { if (_this.pdfViewer.pageOrganizerSettings.canCopy) { // eslint-disable-next-line var proxy = _this; var _loop_3 = function (i) { var mainTileElement = proxy.tileAreaDiv.childNodes[parseInt(i.toString(), 10)]; if (mainTileElement instanceof HTMLElement && mainTileElement.classList.contains('e-pv-organize-node-selection-ring')) { var pageId = mainTileElement.id.split('anchor_page_')[mainTileElement.id.split('anchor_page_').length - 1]; var pageOrder_5 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); var pageIdlist = pageId.split('_'); var subIndex = 0; var pageIndex = parseInt(pageIdlist[parseInt((pageIdlist.length - 1).toString(), 10)], 10); if (pageIdlist.length > 1) { pageIndex = parseInt(pageIdlist[parseInt((pageIdlist.length - 2).toString(), 10)], 10); } subIndex = _this.getNextSubIndex(mainTileElement.parentElement, pageIndex); _this.copyPage(pageOrder_5, mainTileElement); _this.tileImageRender(pageIndex, subIndex, pageOrder_5 + 1, mainTileElement, true, false, false); _this.updatePageNumber(); _this.toolbarUndoRedoCollection. push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === (pageOrder_5 + 1); }))); } }; for (var i = 0; i < proxy.tileAreaDiv.childElementCount; i++) { _loop_3(i); } _this.updateTotalPageCount(); _this.disableTileDeleteButton(); _this.addOrganizeAction(null, 'Toolbar Copy', _this.toolbarUndoRedoCollection, [], null, false); _this.toolbarUndoRedoCollection = []; } }; this.onToolbarDeleteButtonClick = function () { if (_this.pdfViewer.pageOrganizerSettings.canDelete) { // eslint-disable-next-line var proxy_1 = _this; var selectedNodes = proxy_1.tileAreaDiv.querySelectorAll('.e-pv-organize-node-selection-ring'); selectedNodes.forEach(function (selectedElements) { var mainTileElement = selectedElements.closest('.e-pv-organize-anchor-node'); var pageOrder = parseInt(mainTileElement.getAttribute('data-page-order'), 10); _this.toolbarUndoRedoCollection. push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder; }))); }); selectedNodes.forEach(function (selectedElement) { var mainTileElement = selectedElement.closest('.e-pv-organize-anchor-node'); proxy_1.deletePageElement(mainTileElement); }); } _this.enableDisableToolbarItems(); _this.addOrganizeAction(null, 'Toolbar Delete', _this.toolbarUndoRedoCollection, [], null, false); _this.toolbarUndoRedoCollection = []; }; /** * @private * @returns {void} */ this.undo = function () { var undoActionObject = _this.undoOrganizeCollection.pop(); if (undoActionObject) { var actionObject_1 = JSON.parse(JSON.stringify(undoActionObject)); switch (actionObject_1.action) { case 'Insert Right': case 'Insert Left': case 'Import Pages': case 'Copy': _this.removePage(actionObject_1.UndoRedoTileActions[0].currentPageIndex); break; case 'Rotate Right': _this.rotateImage(actionObject_1.UndoRedoTileActions[0].currentPageIndex, -90); break; case 'Rotate Left': _this.rotateImage(actionObject_1.UndoRedoTileActions[0].currentPageIndex, 90); break; case 'Delete': { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject_1.UndoRedoTileActions[0]. currentPageIndex.toString(), 10)]; if (actionObject_1.UndoRedoTileActions[0].isCopied) { _this.insertRemovedPages(actionObject_1.UndoRedoTileActions[0], actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject_1.UndoRedoTileActions[0].copiedPageIndex, 0, actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, false); } else if (actionObject_1.UndoRedoTileActions[0].isInserted) { _this.insertRemovedPages(actionObject_1.UndoRedoTileActions[0], actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject_1.UndoRedoTileActions[0].copiedPageIndex, 0, actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, true); } else if (actionObject_1.UndoRedoTileActions[0].isImportedDoc) { _this.insertRemovedPages(actionObject_1.UndoRedoTileActions[0], actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject_1.UndoRedoTileActions[0].copiedPageIndex, 0, actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, false, true, actionObject_1.UndoRedoTileActions[0].documentName); } else if (!actionObject_1.UndoRedoTileActions[0].isCopied && !actionObject_1.UndoRedoTileActions[0].isInserted && !actionObject_1.UndoRedoTileActions[0].isImportedDoc) { _this.undoDeletedPage(actionObject_1.UndoRedoTileActions[0].currentPageIndex, actionObject_1.UndoRedoTileActions[0].pageIndex, actionObject_1.UndoRedoTileActions[0].rotateAngle, mainTileElement); _this.tileImageRender(actionObject_1.UndoRedoTileActions[0].pageIndex, 0, actionObject_1.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, false); } _this.updatePageDetail(); } break; case 'Move Pages': { var dropIndex_1 = actionObject_1.dropIndex; var beforeDropIndex = []; var afterDropIndex = []; var processedIndexes_1 = new Set(); // Helper function to check if index is in range var isInRange_1 = function (start, end, value) { return value >= start && value <= end; }; var _loop_4 = function (i) { var action = actionObject_1.UndoRedoTileActions[parseInt(i.toString(), 10)]; var selectedItem = _this.tempOrganizePagesCollection .find(function (item) { if (action.isCopied) { return item.copiedPageIndex === action.copiedPageIndex && isInRange_1(dropIndex_1 - actionObject_1.selectedPagesIndexes.length, dropIndex_1 + actionObject_1.selectedPagesIndexes.length, item.currentPageIndex) && !processedIndexes_1.has(item.currentPageIndex); } else if (action.isInserted) { return item.copiedPageIndex === action.copiedPageIndex && item.isInserted && isInRange_1(dropIndex_1 - actionObject_1.selectedPagesIndexes.length, dropIndex_1 + actionObject_1.selectedPagesIndexes.length, item.currentPageIndex) && !processedIndexes_1.has(item.currentPageIndex); } else if (action.isImportedDoc) { return item.copiedPageIndex === action.copiedPageIndex && item.isImportedDoc && isInRange_1(dropIndex_1 - actionObject_1.selectedPagesIndexes.length, dropIndex_1 + actionObject_1.selectedPagesIndexes.length, item.currentPageIndex) && !processedIndexes_1.has(item.currentPageIndex); } else { return item.pageIndex === action.pageIndex; } }); if (selectedItem) { var selectedIndexes = [selectedItem.currentPageIndex]; processedIndexes_1.add(selectedItem.currentPageIndex); if (dropIndex_1 < action.currentPageIndex) { afterDropIndex.push({ currentPageIndex: action.currentPageIndex, selectedIndexes: selectedIndexes }); } else { beforeDropIndex.push({ currentPageIndex: action.currentPageIndex, selectedIndexes: selectedIndexes }); } } }; // Collect all selected indexes for (var i = 0; i < actionObject_1.UndoRedoTileActions.length; i++) { _loop_4(i); } // Sort and rearrange for beforeDropIndex if (beforeDropIndex.length > 0) { // Sort in descending order based on selectedIndexes and rearrange beforeDropIndex.sort(function (a, b) { return a.currentPageIndex - b.currentPageIndex; }); for (var j = 0; j < beforeDropIndex.length; j++) { // eslint-disable-next-line max-len _this.rearrangePages(beforeDropIndex[parseInt(j.toString(), 10)].selectedIndexes, beforeDropIndex[parseInt(j.toString(), 10)].currentPageIndex, beforeDropIndex[parseInt(j.toString(), 10)].currentPageIndex > beforeDropIndex[parseInt(j.toString(), 10)].selectedIndexes[0]); } } // Sort and rearrange for afterDropIndex if (afterDropIndex.length > 0) { // Sort in ascending order based on currentPageIndex and rearrange afterDropIndex.sort(function (a, b) { return b.currentPageIndex - a.currentPageIndex; }); for (var j = 0; j < afterDropIndex.length; j++) { _this.rearrangePages(afterDropIndex[parseInt(j.toString(), 10)].selectedIndexes, afterDropIndex[parseInt(j.toString(), 10)].currentPageIndex, afterDropIndex[parseInt(j.toString(), 10)].currentPageIndex > afterDropIndex[parseInt(j.toString(), 10)].selectedIndexes[0]); } } break; } case 'Toolbar Rotate Right': _this.rotateImages(actionObject_1, -90); break; case 'Toolbar Rotate Left': _this.rotateImages(actionObject_1, 90); break; case 'Toolbar Copy': if (actionObject_1.toolbarActions.length > 0) { for (var i = actionObject_1.toolbarActions.length - 1; i >= 0; i--) { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject_1.toolbarActions[parseInt(i.toString(), 10)]. currentPageIndex.toString(), 10)]; _this.deleteTempPage(actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement); _this.tileAreaDiv.removeChild(mainTileElement); _this.updatePageDetail(); } } _this.disableTileDeleteButton(); break; case 'Toolbar Delete': { if (actionObject_1.toolbarActions.length > 0) { for (var i = 0; i < actionObject_1.toolbarActions.length; i++) { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject_1.toolbarActions[parseInt(i.toString(), 10)]. currentPageIndex.toString(), 10)]; if (actionObject_1.toolbarActions[parseInt(i.toString(), 10)].isCopied) { _this.insertRemovedPages(actionObject_1.toolbarActions[parseInt(i.toString(), 10)], actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject_1.toolbarActions[parseInt(i.toString(), 10)].copiedPageIndex, 0, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement, true, true, false); } else if (actionObject_1.toolbarActions[parseInt(i.toString(), 10)].isInserted) { _this.insertRemovedPages(actionObject_1.toolbarActions[parseInt(i.toString(), 10)], actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject_1.toolbarActions[parseInt(i.toString(), 10)].copiedPageIndex, 0, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement, true, true, true); } else if (actionObject_1.toolbarActions[parseInt(i.toString(), 10)].isImportedDoc) { _this.insertRemovedPages(actionObject_1.toolbarActions[parseInt(i.toString(), 10)], actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject_1.toolbarActions[parseInt(i.toString(), 10)].copiedPageIndex, 0, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement, true, true, false, true, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].documentName); } else if (!actionObject_1.toolbarActions[parseInt(i.toString(), 10)].isCopied && !actionObject_1.toolbarActions[parseInt(i.toString(), 10)].isInserted && !actionObject_1.toolbarActions[parseInt(i.toString(), 10)].isImportedDoc) { _this.undoDeletedPage(actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].pageIndex, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].rotateAngle, mainTileElement); _this.tileImageRender(actionObject_1.toolbarActions[parseInt(i.toString(), 10)].pageIndex, 0, actionObject_1.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement, true, true, false); } _this.updatePageDetail(); } } _this.disableTileDeleteButton(); } break; } } _this.redoOrganizeCollection.push(undoActionObject); _this.enableDisableToolbarItems(); _this.updateUndoRedoButtons(); }; /** * @private * @returns {void} */ this.redo = function () { var redoActionObject = _this.redoOrganizeCollection.pop(); if (redoActionObject) { var actionObject = JSON.parse(JSON.stringify(redoActionObject)); switch (actionObject.action) { case 'Insert Right': case 'Insert Left': { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject.UndoRedoTileActions[0]. currentPageIndex.toString(), 10)]; _this.insertRemovedPages(actionObject.UndoRedoTileActions[0], actionObject.UndoRedoTileActions[0].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject.UndoRedoTileActions[0].copiedPageIndex, 0, actionObject.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, true); _this.disableTileCopyButton(); _this.updatePageDetail(); } break; case 'Rotate Right': _this.rotateImage(actionObject.UndoRedoTileActions[0].currentPageIndex, 90); break; case 'Rotate Left': _this.rotateImage(actionObject.UndoRedoTileActions[0].currentPageIndex, -90); break; case 'Copy': { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject.UndoRedoTileActions[0]. currentPageIndex.toString(), 10)]; _this.insertRemovedPages(actionObject.UndoRedoTileActions[0], actionObject.UndoRedoTileActions[0].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject.UndoRedoTileActions[0].copiedPageIndex, 0, actionObject.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, false); _this.updatePageDetail(); } break; case 'Import Pages': { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject.UndoRedoTileActions[0]. currentPageIndex.toString(), 10)]; _this.insertRemovedPages(actionObject.UndoRedoTileActions[0], actionObject.UndoRedoTileActions[0].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject.UndoRedoTileActions[0].copiedPageIndex, 0, actionObject.UndoRedoTileActions[0].currentPageIndex, mainTileElement, true, true, false, true, actionObject.UndoRedoTileActions[0].documentName); _this.disableTileCopyRotateButton(); } break; case 'Delete': _this.removePage(actionObject.UndoRedoTileActions[0].currentPageIndex); break; case 'Move Pages': _this.rearrangePages(actionObject.selectedPagesIndexes, actionObject.dropIndex, actionObject.isRightInsertion); break; case 'Toolbar Rotate Right': _this.rotateImages(actionObject, 90); break; case 'Toolbar Rotate Left': _this.rotateImages(actionObject, -90); break; case 'Toolbar Copy': { if (actionObject.toolbarActions.length > 0) { for (var i = 0; i < actionObject.toolbarActions.length; i++) { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject.toolbarActions[parseInt(i.toString(), 10)]. currentPageIndex.toString(), 10)]; _this.insertRemovedPages(actionObject.toolbarActions[parseInt(i.toString(), 10)], actionObject.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement); _this.tileImageRender(actionObject.toolbarActions[parseInt(i.toString(), 10)].copiedPageIndex, 0, actionObject.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement, true, true, false); _this.updatePageDetail(); } } _this.disableTileDeleteButton(); } break; case 'Toolbar Delete': if (actionObject.toolbarActions.length > 0) { for (var i = actionObject.toolbarActions.length - 1; i >= 0; i--) { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject.toolbarActions[parseInt(i.toString(), 10)]. currentPageIndex.toString(), 10)]; _this.deleteTempPage(actionObject.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, mainTileElement); _this.tileAreaDiv.removeChild(mainTileElement); _this.updatePageDetail(); } } _this.disableTileDeleteButton(); break; } } _this.undoOrganizeCollection.push(redoActionObject); _this.enableDisableToolbarItems(); _this.updateUndoRedoButtons(); }; this.rotateImages = function (actionObject, rotationAngle) { if (actionObject.toolbarActions.length > 0) { for (var i = 0; i < actionObject.toolbarActions.length; i++) { var mainTileElement = _this.tileAreaDiv.childNodes[parseInt(actionObject.toolbarActions[parseInt(i.toString(), 10)]. currentPageIndex.toString(), 10)]; var imageContainer = mainTileElement.querySelector('.e-pv-organize-image'); if (imageContainer) { var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0; currentRotation = (currentRotation + rotationAngle + 360) % 360; imageContainer.style.transform = "rotate(" + currentRotation + "deg)"; _this.updateTempRotationDetail(actionObject.toolbarActions[parseInt(i.toString(), 10)].currentPageIndex, rotationAngle); } } } }; this.insertRightButtonClick = function (event) { if (_this.pdfViewer.pageOrganizerSettings.canInsert) { var insertRightButton = event.currentTarget; var buttonId = insertRightButton.id.split('_insert_page_')[insertRightButton.id.split('_insert_page_').length - 1]; var mainTileElement = insertRightButton.closest('.e-pv-organize-anchor-node'); var pageOrder_6 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); var buttonIdlist = buttonId.split('_'); var subIndex = 0; var buttonIndex = parseInt(buttonIdlist[parseInt((buttonIdlist.length - 1).toString(), 10)], 10); if (buttonIdlist.length > 1) { buttonIndex = parseInt(buttonIdlist[parseInt((buttonIdlist.length - 2).toString(), 10)], 10); } subIndex = _this.getNextSubIndex(mainTileElement.parentElement, buttonIndex); _this.insertTempPage(pageOrder_6, false, mainTileElement); _this.tileImageRender(buttonIndex, subIndex, pageOrder_6 + 1, mainTileElement, true, false, true); _this.updateTotalPageCount(); _this.updatePageNumber(); _this.disableTileDeleteButton(); _this.disableTileCopyButton(); _this.updateSelectAllCheckbox(); _this.enableDisableToolbarItems(); var clonedCollection = []; clonedCollection.push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === (pageOrder_6 + 1); }))); _this.addOrganizeAction(clonedCollection, 'Insert Right', [], [], null, false); } }; this.insertLeftButtonClick = function (event) { if (_this.pdfViewer.pageOrganizerSettings.canInsert) { var insetLeftButton = event.currentTarget; var buttonId = insetLeftButton.id.split('_insert_page_')[insetLeftButton.id.split('_insert_page_').length - 1]; var mainTileElement = insetLeftButton.closest('.e-pv-organize-anchor-node'); var pageOrder_7 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); var buttonIdlist = buttonId.split('_'); var subIndex = 0; var buttonIndex = parseInt(buttonIdlist[parseInt((buttonIdlist.length - 1).toString(), 10)], 10); if (buttonIdlist.length > 1) { buttonIndex = parseInt(buttonIdlist[parseInt((buttonIdlist.length - 2).toString(), 10)], 10); } subIndex = _this.getNextSubIndex(mainTileElement.parentElement, buttonIndex); _this.insertTempPage(pageOrder_7, true, mainTileElement); _this.tileImageRender(buttonIndex, subIndex, pageOrder_7, mainTileElement, true, true, true); _this.updateTotalPageCount(); _this.updatePageNumber(); _this.disableTileDeleteButton(); _this.disableTileCopyButton(); _this.updateSelectAllCheckbox(); _this.enableDisableToolbarItems(); var clonedCollection = []; clonedCollection.push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder_7; }))); _this.addOrganizeAction(clonedCollection, 'Insert Left', [], [], null, false); } }; this.copyButtonClick = function (event) { if (_this.pdfViewer.pageOrganizerSettings.canCopy) { var copyButton = event.currentTarget; var buttonId = copyButton.id.split('_copy_page_')[copyButton.id.split('_copy_page_').length - 1]; var mainTileElement = copyButton.closest('.e-pv-organize-anchor-node'); var pageOrder_8 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); var buttonIdlist = buttonId.split('_'); var subIndex = 0; var buttonIndex = parseInt(buttonIdlist[parseInt((buttonIdlist.length - 1).toString(), 10)], 10); if (buttonIdlist.length > 1) { buttonIndex = parseInt(buttonIdlist[parseInt((buttonIdlist.length - 2).toString(), 10)], 10); } subIndex = _this.getNextSubIndex(mainTileElement.parentElement, buttonIndex); _this.copyPage(pageOrder_8, mainTileElement); _this.tileImageRender(buttonIndex, subIndex, pageOrder_8 + 1, mainTileElement, true, false, false); _this.updateTotalPageCount(); _this.updatePageNumber(); _this.disableTileDeleteButton(); var clonedCollection = []; clonedCollection.push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === (pageOrder_8 + 1); }))); _this.addOrganizeAction(clonedCollection, 'Copy', [], [], null, false); } }; this.deleteButtonClick = function (event) { if (_this.pdfViewer.pageOrganizerSettings.canDelete) { var deleteButton = event.currentTarget; var mainTileElement = deleteButton.closest('.e-pv-organize-anchor-node'); var pageOrder_9 = parseInt(mainTileElement.getAttribute('data-page-order'), 10); var clonedCollection = []; clonedCollection.push(_this.clonedCollection(_this.tempOrganizePagesCollection. find(function (item) { return item.currentPageIndex === pageOrder_9; }))); _this.addOrganizeAction(clonedCollection, 'Delete', [], [], null, false); _this.deletePageElement(mainTileElement); } _this.updateSelectAllCheckbox(); _this.enableDisableToolbarItems(); }; this.pdfViewer = pdfViewer; this.pdfViewerBase = pdfViewerBase; } /** * @param {boolean} isReConstruct - It describes about the isReConstruct * @private * @returns {void} */ PageOrganizer.prototype.createOrganizeWindow = function (isReConstruct) { var _this = this; var elementID = this.pdfViewer.element.id; if (!isNullOrUndefined(document.getElementById(elementID + '_organize_window')) && !isNullOrUndefined(this.organizeDialog)) { this.organizeDialog.show(true); this.isOrganizeWindowOpen = true; return; } this.dialogDivElement = createElement('div', { id: elementID + '_organize_window', className: 'e-pv-organize-window' }); var dialogDiv = this.dialogDivElement; var contentRegion = this.createContentArea(); this.pdfViewerBase.mainContainer.appendChild(dialogDiv); this.organizeDialog = new Dialog({ showCloseIcon: true, closeOnEscape: true, isModal: true, header: this.pdfViewer.localeObj.getConstant('Organize Pages'), target: this.pdfViewerBase.mainContainer, content: contentRegion, visible: false, open: function