all files / pdfviewer/organize-pdf/organize-core/ tile-interaction.js

14.95% Statements 32/214
0% Branches 0/139
4.55% Functions 1/22
15.09% Lines 32/212
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
define(["require", "exports", "@syncfusion/ej2-base", "./organize-toolbar", "./organize-thumbnail", "./organize-undoredoutils", "./organize-initialization", "./organize-extract"], function (require, exports, ej2_base_1, organize_toolbar_1, organize_thumbnail_1, organize_undoredoutils_1, organize_initialization_1, organize_extract_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function selectRange(startIndex, endIndex) {
        var minIndex = Math.min(startIndex, endIndex);
        var maxIndex = Math.max(startIndex, endIndex);
        for (var i = minIndex; i <= maxIndex; i++) {
            var tile = this.tileAreaDiv.children[parseInt(i.toString(), 10)];
            selectTile.call(this, tile);
        }
    }
    exports.selectRange = selectRange;
    function selectTile(tile) {
        if (!ej2_base_1.isNullOrUndefined(tile)) {
            var checkbox = tile.closest('.e-pv-organize-anchor-node').querySelector('.e-pv-organize-tile-checkbox');
            if (checkbox) {
                checkbox.checked = true;
                setSelectionRingStyle.call(this, checkbox, tile);
            }
        }
    }
    exports.selectTile = selectTile;
    function deselectTile(tile) {
        if (!ej2_base_1.isNullOrUndefined(tile)) {
            var checkbox = tile.closest('.e-pv-organize-anchor-node').querySelector('.e-pv-organize-tile-checkbox');
            if (checkbox) {
                checkbox.checked = false;
                setSelectionRingStyle.call(this, checkbox, tile);
            }
        }
    }
    exports.deselectTile = deselectTile;
    function clearSelection() {
        var _this = this;
        var selectedTiles = document.querySelectorAll('.e-pv-organize-node-selection-ring');
        selectedTiles.forEach(function (tile) {
            var checkbox = tile.closest('.e-pv-organize-anchor-node').querySelector('.e-pv-organize-tile-checkbox');
            checkbox.checked = false;
            setSelectionRingStyle.call(_this, checkbox, tile);
        });
        organize_toolbar_1.updateSelectAllCheckbox.call(this);
        organize_toolbar_1.enableDisableToolbarItems.call(this);
    }
    exports.clearSelection = clearSelection;
    function selectAllTiles() {
        var _this = this;
        Array.from(this.tileAreaDiv.children).forEach(function (tile) {
            selectTile.call(_this, tile);
        });
        organize_toolbar_1.updateSelectAllCheckbox.call(this);
        organize_toolbar_1.enableDisableToolbarItems.call(this);
    }
    exports.selectAllTiles = selectAllTiles;
    function disableTileDeleteButton() {
        if (this.tileAreaDiv.childElementCount === 1) {
            var mainTileElement = this.tileAreaDiv.querySelector('.e-pv-organize-anchor-node');
            var deleteButton = mainTileElement.querySelector('.e-pv-delete-button');
            if (!ej2_base_1.isNullOrUndefined(deleteButton)) {
                deleteButton.setAttribute('disabled', 'disabled');
                deleteButton.firstElementChild.classList.add('e-disabled');
            }
        }
        else {
            for (var i = 0; i < this.tileAreaDiv.childElementCount; i++) {
                var mainTileElement = void 0;
                if (this.tileAreaDiv.childNodes[parseInt(i.toString(), 10)].classList.contains('e-pv-organize-anchor-node')) {
                    mainTileElement = this.tileAreaDiv.childNodes[parseInt(i.toString(), 10)];
                }
                else {
                    mainTileElement = this.tileAreaDiv.childNodes[parseInt(i.toString(), 10)].querySelector('.e-pv-organize-anchor-node');
                }
                var deleteButton = mainTileElement.querySelector('.e-pv-delete-button');
                if (!ej2_base_1.isNullOrUndefined(deleteButton) && this.pdfViewer.pageOrganizerSettings.canDelete) {
                    deleteButton.removeAttribute('disabled');
                    deleteButton.firstElementChild.classList.remove('e-disabled');
                }
            }
        }
    }
    exports.disableTileDeleteButton = disableTileDeleteButton;
    function disableTileCopyRotateButton() {
        for (var i = 0; i < this.tempOrganizePagesCollection.length; i++) {
            var pageInfo = this.tempOrganizePagesCollection[parseInt(i.toString(), 10)];
            if (pageInfo.isImportedDoc && !pageInfo.isDeleted && !pageInfo.currentPageIndex != null) {
                var mainTileElement = this.tileAreaDiv.querySelector("[data-page-order=\"" + pageInfo.currentPageIndex.toString() + "\"]");
                var rotateLeftButton = mainTileElement.querySelector('.e-pv-rotate-left-button');
                var rotateRightButton = mainTileElement.querySelector('.e-pv-rotate-right-button');
                var copyButton = mainTileElement.querySelector('.e-pv-copy-button');
                if (!ej2_base_1.isNullOrUndefined(rotateLeftButton)) {
                    rotateLeftButton.setAttribute('disabled', 'disabled');
                    rotateLeftButton.firstElementChild.classList.add('e-disabled');
                }
                if (!ej2_base_1.isNullOrUndefined(rotateRightButton)) {
                    rotateRightButton.setAttribute('disabled', 'disabled');
                    rotateRightButton.firstElementChild.classList.add('e-disabled');
                }
                if (!ej2_base_1.isNullOrUndefined(copyButton)) {
                    copyButton.setAttribute('disabled', 'disabled');
                    copyButton.firstElementChild.classList.add('e-disabled');
                }
            }
        }
    }
    exports.disableTileCopyRotateButton = disableTileCopyRotateButton;
    function disableTileCopyButton() {
        for (var i = 0; i < this.tempOrganizePagesCollection.length; i++) {
            var pageInfo = this.tempOrganizePagesCollection[parseInt(i.toString(), 10)];
            if (pageInfo.isInserted && !pageInfo.isDeleted && !pageInfo.currentPageIndex != null) {
                var mainTileElement = this.tileAreaDiv.querySelector("[data-page-order=\"" + pageInfo.currentPageIndex.toString() + "\"]");
                var copyButton = mainTileElement.querySelector('.e-pv-copy-button');
                if (!ej2_base_1.isNullOrUndefined(copyButton)) {
                    copyButton.setAttribute('disabled', 'disabled');
                    copyButton.firstElementChild.classList.add('e-disabled');
                }
            }
        }
    }
    exports.disableTileCopyButton = disableTileCopyButton;
    function onSelectClick(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 && !(ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode))) {
            if (this.isClickedOnCheckBox && !ej2_base_1.isNullOrUndefined(checkboxElement) && !ej2_base_1.isNullOrUndefined(pageElement)) {
                if (pageElement) {
                    setSelectionRingStyle.call(this, checkboxElement, pageElement);
                }
            }
            else if (!ej2_base_1.isNullOrUndefined(checkboxElement) && !ej2_base_1.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;
                            setSelectionRingStyle.call(this, previousCheckbox, previouslySelectedTiles[parseInt(i.toString(), 10)]);
                        }
                    }
                    if (!this.isClickedOnCheckBox) {
                        checkboxElement.checked = true;
                    }
                }
                if (this.shiftKey) {
                    checkboxElement.checked = true;
                }
                setSelectionRingStyle.call(this, checkboxElement, pageElement);
            }
        }
        else if (args.event.pointerType === 'touch' || this.isTouchEvent || (ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode)) {
            if (!ej2_base_1.isNullOrUndefined(checkboxElement) && !ej2_base_1.isNullOrUndefined(pageElement)) {
                if (pageElement) {
                    setSelectionRingStyle.call(this, checkboxElement, pageElement);
                }
                var buttonDiv = pageElement.querySelector('.e-pv-organize-buttondiv');
                if (!ej2_base_1.isNullOrUndefined(buttonDiv) && buttonDiv.childElementCount > 1) {
                    if (checkboxElement.checked) {
                        buttonDiv.style.display = 'flex';
                    }
                    else {
                        buttonDiv.style.display = 'none';
                    }
                    for (var _i = 0, _a = Array.from(buttonDiv.children); _i < _a.length; _i++) {
                        var button = _a[_i];
                        organize_thumbnail_1.setTileButtonEnableState.call(this, button);
                    }
                }
            }
        }
        organize_toolbar_1.updateSelectAllCheckbox.call(this);
        organize_toolbar_1.enableDisableToolbarItems.call(this);
        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';
                }
            }
        }
    }
    exports.onSelectClick = onSelectClick;
    function setSelectionRingStyle(checkbox, anchornode) {
        if (!checkbox.checked) {
            anchornode.classList.remove('e-pv-organize-node-selection-ring');
        }
        else {
            anchornode.classList.add('e-pv-organize-node-selection-ring');
        }
        var childrenArray = Array.from(anchornode.children);
        for (var _i = 0, childrenArray_1 = childrenArray; _i < childrenArray_1.length; _i++) {
            var child = childrenArray_1[_i];
            var childArray = Array.from(child.children);
            for (var _a = 0, childArray_1 = childArray; _a < childArray_1.length; _a++) {
                var subchild = childArray_1[_a];
                if (subchild.classList.contains('e-checkbox-wrapper')) {
                    var id = (subchild.getElementsByClassName('e-control e-checkbox e-lib')[0]).id;
                    var cbObj = ej2_base_1.getComponent(document.getElementById(id), 'checkbox');
                    if (checkbox.checked) {
                        subchild.style.display = 'block';
                        subchild.children[0].style.display = 'block';
                        cbObj.checked = true;
                    }
                    else {
                        subchild.style.display = 'none';
                        subchild.children[0].style.display = 'none';
                        cbObj.checked = false;
                        if (!ej2_base_1.isNullOrUndefined(subchild.parentElement) && !ej2_base_1.isNullOrUndefined(subchild.parentElement.lastElementChild) && subchild.parentElement.lastElementChild.classList.contains('e-pv-organize-buttondiv')) {
                            subchild.parentElement.lastElementChild.style.display = 'none';
                        }
                    }
                }
            }
        }
        if (this.pdfViewerBase && this.pdfViewerBase.clientSideRendering && this.isExtractToolbarVisible && this.extractPagesInput &&
            this.tileAreaDiv) {
            var selectedNodes = this.tileAreaDiv.querySelectorAll('.e-pv-organize-node-selection-ring');
            var selectedPages_1 = [];
            selectedNodes.forEach(function (selectedElement) {
                var mainTileElement = selectedElement.closest('.e-pv-organize-anchor-node');
                if (mainTileElement) {
                    var pageOrderAttr = mainTileElement.getAttribute('data-page-order');
                    if (pageOrderAttr !== null) {
                        selectedPages_1.push(parseInt(pageOrderAttr, 10) + 1);
                    }
                }
            });
            var formatted = organize_extract_1.formatPageRanges(selectedPages_1.join(','), this.tileAreaDiv.childElementCount);
            this.extractPagesInput.value = formatted;
            if (this.extractPagesInput.element) {
                this.extractPagesInput.element.value = formatted;
            }
            var createBtn = document.getElementsByClassName('e-pv-extractbtn')[0];
            if (createBtn) {
                createBtn.disabled = (formatted.trim() === '');
            }
        }
    }
    exports.setSelectionRingStyle = setSelectionRingStyle;
    function updateTempRotationDetail(currentPageIndex, currentRotation) {
        if (this.pdfViewer.pageOrganizerSettings.canRotate) {
            var tempIndex = this.tempOrganizePagesCollection.findIndex(function (item) { return item.currentPageIndex === currentPageIndex; });
            if (tempIndex !== -1) {
                var rotateAngle = this.tempOrganizePagesCollection[parseInt(tempIndex.toString(), 10)].rotateAngle +
                    currentRotation;
                if (rotateAngle === -90) {
                    rotateAngle = 0;
                }
                this.tempOrganizePagesCollection[parseInt(tempIndex.toString(), 10)].rotateAngle =
                    Math.abs((this.tempOrganizePagesCollection[parseInt(tempIndex.toString(), 10)].rotateAngle +
                        currentRotation + 360) % 360);
            }
        }
        organizeWindowFocus.call(this);
    }
    exports.updateTempRotationDetail = updateTempRotationDetail;
    function organizeWindowFocus() {
        var elementID = this.pdfViewer.element.id;
        document.getElementById(elementID + '_organize_window').focus();
    }
    exports.organizeWindowFocus = organizeWindowFocus;
    function isHoveredOnSelectedPages(selectedPageIndexes, hoveredIndex) {
        var isHoveredOnSelectedPageIndex = false;
        for (var i = 0; i < selectedPageIndexes.length; i++) {
            if (selectedPageIndexes[parseInt(i.toString(), 10)] === hoveredIndex) {
                isHoveredOnSelectedPageIndex = true;
                break;
            }
        }
        return isHoveredOnSelectedPageIndex;
    }
    exports.isHoveredOnSelectedPages = isHoveredOnSelectedPages;
    function deletePageElement(mainTileElement) {
        if (this.pdfViewer.pageOrganizerSettings.canDelete && this.tileAreaDiv.childElementCount > 1) {
            var pageOrder = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
            organize_undoredoutils_1.deleteTempPage.call(this, pageOrder, mainTileElement);
            var deleteButton = mainTileElement.querySelector('.e-pv-delete-button');
            if (!ej2_base_1.isNullOrUndefined(deleteButton) && !ej2_base_1.isNullOrUndefined(deleteButton.ej2_instances) &&
                deleteButton.ej2_instances.length > 0) {
                deleteButton.ej2_instances[0].destroy();
            }
            this.tileAreaDiv.removeChild(mainTileElement);
            organize_initialization_1.updateTotalPageCount.call(this);
            organize_initialization_1.updatePageNumber.call(this);
            organize_toolbar_1.updateSelectAllCheckbox.call(this);
            disableTileDeleteButton.call(this);
        }
    }
    exports.deletePageElement = deletePageElement;
    function updateTileButtons() {
        var _this = this;
        if (!ej2_base_1.isNullOrUndefined(this.organizeDialog) && this.organizeDialog.visible) {
            var selectedTiles = Array.from(this.organizeDialog.element.querySelectorAll('.e-pv-organize-node-selection-ring'));
            if (selectedTiles.length >= 1) {
                selectedTiles.forEach(function (tile) {
                    var anchor = tile;
                    var buttonDiv = anchor.querySelector('.e-pv-organize-buttondiv');
                    if (buttonDiv && (buttonDiv.style.display !== 'none')) {
                        var buttons = Array.from(buttonDiv.children);
                        buttons.forEach(function (button) { return organize_thumbnail_1.setTileButtonEnableState.call(_this, button); });
                    }
                });
            }
        }
    }
    exports.updateTileButtons = updateTileButtons;
});