all files / pdfviewer/organize-pdf/organize-core/ organize-undoredoutils.js

12.99% Statements 10/77
0% Branches 0/49
7.14% Functions 1/14
13.33% Lines 10/75
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                                                                                                                                                                                                                
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function deleteTempPage(currentPageIndex, tileDiv) {
        if (this.pdfViewer.pageOrganizerSettings.canDelete &&
            (this.tempOrganizePagesCollection.filter(function (item) { return item.isDeleted === false; }).length > 0)) {
            var index = this.tempOrganizePagesCollection.findIndex(function (item) { return item.currentPageIndex === currentPageIndex; });
            var delCurrentIndex_1 = this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].currentPageIndex;
            if (index !== -1 && !this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isInserted &&
                !this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isCopied &&
                !this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isImportedDoc) {
                this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isDeleted = true;
                this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].currentPageIndex = null;
            }
            else {
                this.tempOrganizePagesCollection.splice(index, 1);
            }
            this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.map(function (item) {
                if (delCurrentIndex_1 < item.currentPageIndex && !item.isDeleted) {
                    item.currentPageIndex = item.currentPageIndex - 1;
                }
                return item;
            });
            while (!ej2_base_1.isNullOrUndefined(tileDiv.nextElementSibling)) {
                var nextTileDiv = tileDiv.nextElementSibling;
                var nextTileIndex = parseInt(nextTileDiv.getAttribute('data-page-order'), 10);
                nextTileIndex = nextTileIndex - 1;
                nextTileDiv.setAttribute('data-page-order', nextTileIndex.toString());
                tileDiv = nextTileDiv;
            }
        }
    }
    exports.deleteTempPage = deleteTempPage;
    function undoDeletedPage(deletedPageIndex, pageIndex, rotateAngle, tileDiv) {
        if (this.tempOrganizePagesCollection.some(function (item) { return item.isDeleted; })) {
            var deletedItem = this.tempOrganizePagesCollection.find(function (item) {
                return item.currentPageIndex === null && item.isDeleted && item.pageIndex !== -1 && item.pageIndex === pageIndex &&
                    item.copiedPageIndex === null;
            });
            if (deletedItem) {
                deletedItem.currentPageIndex = deletedPageIndex;
                deletedItem.rotateAngle = rotateAngle;
            }
        }
        this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.map(function (item) {
            if (item.currentPageIndex >= deletedPageIndex && !item.isDeleted) {
                item.currentPageIndex += 1;
            }
            else if (item.currentPageIndex === deletedPageIndex && item.isDeleted) {
                item.isDeleted = false;
            }
            return item;
        });
        this.tempOrganizePagesCollection.sort(function (a, b) {
            return a.currentPageIndex - b.currentPageIndex;
        });
        if (tileDiv) {
            tileDiv.setAttribute('data-page-order', (deletedPageIndex + 1).toString());
        }
        while (tileDiv && !ej2_base_1.isNullOrUndefined(tileDiv.nextElementSibling)) {
            var nextTileDiv = tileDiv.nextElementSibling;
            var nextTileIndex = parseInt(nextTileDiv.getAttribute('data-page-order'), 10);
            nextTileIndex += 1;
            nextTileDiv.setAttribute('data-page-order', nextTileIndex.toString());
            tileDiv = nextTileDiv;
        }
    }
    exports.undoDeletedPage = undoDeletedPage;
    function insertRemovedPages(toolbarActions, currentPageIndex, tileDiv) {
        var deleteCount = 0;
        var index = this.tempOrganizePagesCollection.findIndex(function (item) {
            return item.currentPageIndex === currentPageIndex;
        });
        if (index !== -1) {
            for (var i = 0; i < index; i++) {
                if (this.tempOrganizePagesCollection[parseInt(i.toString(), 10)].isDeleted) {
                    deleteCount++;
                }
            }
        }
        else {
            for (var i = 0; i < currentPageIndex; i++) {
                if (this.tempOrganizePagesCollection[parseInt(i.toString(), 10)].isDeleted) {
                    deleteCount++;
                }
            }
        }
        this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.slice(0, currentPageIndex + deleteCount).
            concat(toolbarActions, this.tempOrganizePagesCollection.slice(currentPageIndex + deleteCount));
        this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.map(function (item, mapIndex) {
            if (mapIndex > currentPageIndex + deleteCount && !item.isDeleted) {
                item.currentPageIndex += 1;
            }
            return item;
        });
        if (tileDiv) {
            tileDiv.setAttribute('data-page-order', (currentPageIndex + 1).toString());
        }
        while (tileDiv && !ej2_base_1.isNullOrUndefined(tileDiv.nextElementSibling)) {
            var nextTileDiv = tileDiv.nextElementSibling;
            var nextTileIndex = parseInt(nextTileDiv.getAttribute('data-page-order'), 10);
            nextTileIndex = nextTileIndex + 1;
            nextTileDiv.setAttribute('data-page-order', nextTileIndex.toString());
            tileDiv = nextTileDiv;
        }
    }
    exports.insertRemovedPages = insertRemovedPages;
    function clonedCollection(tempCollecion) {
        var clonedCollection = JSON.parse(JSON.stringify(tempCollecion));
        return clonedCollection;
    }
    exports.clonedCollection = clonedCollection;
});