all files / treegrid/actions/ clipboard.js

98.36% Statements 120/122
88.14% Branches 52/59
94.12% Functions 16/17
98.32% Lines 117/119
11 statements, 6 functions, 9 branches Ignored     
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          640× 640× 640× 640× 640× 640×   15× 15× 15× 15× 15× 15× 14× 14× 14× 12×   12× 12×   12× 12× 12× 12× 12× 10×   12× 12× 12× 12× 12×         12× 25×       12×       12× 12×   11× 11× 11×         11× 11× 11×           10× 10× 10× 10× 10× 10× 10× 10× 12× 63×   12× 12× 12× 12× 12× 12×     11×   12× 12× 12×             15×       11395×   624×   24× 24× 24× 24× 24× 24× 20× 238× 20× 20× 20× 20× 20× 20× 20× 20× 20×     20×                
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../base/constant", "@syncfusion/ej2-base", "@syncfusion/ej2-grids"], function (require, exports, events, ej2_base_1, ej2_grids_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TreeClipboard = (function (_super) {
        __extends(TreeClipboard, _super);
        function TreeClipboard(parent, serviceLocator) {
            var _this = _super.call(this, parent.grid, serviceLocator) || this;
            _this.treeCopyContent = '';
            _this.copiedUniqueIdCollection = [];
            _this.treeGridParent = parent;
            _this.serviceLocator = serviceLocator;
            return _this;
        }
        TreeClipboard.prototype.setCopyData = function (withHeader) {
            var copyContent = 'copyContent';
            var getCopyData = 'getCopyData';
            var isSelect = 'isSelect';
            var uniqueID = 'uniqueID';
            var currentRecords = this.treeGridParent.getCurrentViewRecords();
            if (window.getSelection().toString() === '') {
                this.clipBoardTextArea.value = this["" + copyContent] = '';
                var rows = this.treeGridParent.grid.getRows();
                if (this.treeGridParent.selectionSettings.mode !== 'Cell') {
                    var selectedIndexes = this.treeGridParent.getSelectedRowIndexes().sort(function (a, b) {
                        return a - b;
                    });
                    for (var i = 0; i < selectedIndexes.length; i++) {
                        if (i > 0) {
                            this.treeCopyContent += '\n';
                        }
                        Eif (!rows[selectedIndexes[parseInt(i.toString(), 10)]].classList.contains('e-summaryrow')) {
                            var cells = [].slice.call(rows[selectedIndexes[parseInt(i.toString(), 10)]].querySelectorAll('.e-rowcell'));
                            var uniqueid = this.treeGridParent.getSelectedRecords()[parseInt(i.toString(), 10)]["" + uniqueID];
                            Eif (this.copiedUniqueIdCollection.indexOf(uniqueid) === -1) {
                                if (this.treeGridParent.copyHierarchyMode === 'Parent' || this.treeGridParent.copyHierarchyMode === 'Both') {
                                    this.parentContentData(currentRecords, selectedIndexes[parseInt(i.toString(), 10)], rows, withHeader, i);
                                }
                                this["" + getCopyData](cells, false, '\t', withHeader);
                                this.treeCopyContent += this["" + copyContent];
                                this.copiedUniqueIdCollection.push(uniqueid);
                                this["" + copyContent] = '';
                                if (this.treeGridParent.copyHierarchyMode === 'Child' || this.treeGridParent.copyHierarchyMode === 'Both') {
                                    this.childContentData(currentRecords, selectedIndexes[parseInt(i.toString(), 10)], rows, withHeader);
                                }
                            }
                        }
                    }
                    if (withHeader) {
                        var headerTextArray = [];
                        for (var i = 0; i < this.treeGridParent.getVisibleColumns().length; i++) {
                            headerTextArray[parseInt(i.toString(), 10)] =
                                this.treeGridParent.getVisibleColumns()[parseInt(i.toString(), 10)].headerText;
                        }
                        this["" + getCopyData](headerTextArray, false, '\t', withHeader);
                        this.treeCopyContent = this["" + copyContent] + '\n' + this.treeCopyContent;
                    }
                    var args = {
                        data: this.treeCopyContent,
                        cancel: false
                    };
                    this.treeGridParent.trigger(events.beforeCopy, args);
                    if (args.cancel) {
                        return;
                    }
                    this.clipBoardTextArea.value = this["" + copyContent] = args.data;
                    Eif (!ej2_base_1.Browser.userAgent.match(/ipad|ipod|iphone/i)) {
                        this.clipBoardTextArea.select();
                    }
                    else {
                        this.clipBoardTextArea.setSelectionRange(0, this.clipBoardTextArea.value.length);
                    }
                    this["" + isSelect] = true;
                    this.copiedUniqueIdCollection = [];
                    this.treeCopyContent = '';
                }
                else {
                    _super.prototype.setCopyData.call(this, withHeader);
                }
            }
        };
        TreeClipboard.prototype.parentContentData = function (currentRecords, selectedIndex, rows, withHeader, index) {
            var getCopyData = 'getCopyData';
            var copyContent = 'copyContent';
            var parentItem = 'parentItem';
            var uniqueID = 'uniqueID';
            var level = 'level';
            Eif (!ej2_base_1.isNullOrUndefined(currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem])) {
                var treeLevel = currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem]["" + level];
                for (var i = 0; i < treeLevel + 1; i++) {
                    for (var j = 0; j < currentRecords.length; j++) {
                        if (!ej2_base_1.isNullOrUndefined(currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem]) &&
                            currentRecords[parseInt(j.toString(), 10)]["" + uniqueID] === currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem]["" + uniqueID]) {
                            selectedIndex = j;
                            var cells = [].slice.call(rows[parseInt(selectedIndex.toString(), 10)].querySelectorAll('.e-rowcell'));
                            var uniqueid = currentRecords[parseInt(j.toString(), 10)]["" + uniqueID];
                            Eif (this.copiedUniqueIdCollection.indexOf(uniqueid) === -1) {
                                this["" + getCopyData](cells, false, '\t', withHeader);
                                if (index > 0) {
                                    this.treeCopyContent = this.treeCopyContent + this["" + copyContent] + '\n';
                                }
                                else {
                                    this.treeCopyContent = this["" + copyContent] + '\n' + this.treeCopyContent;
                                }
                                this.copiedUniqueIdCollection.push(uniqueid);
                                this["" + copyContent] = '';
                                break;
                            }
                        }
                    }
                }
            }
        };
        TreeClipboard.prototype.copy = function (withHeader) {
            _super.prototype.copy.call(this, withHeader);
        };
        TreeClipboard.prototype.paste = function (data, rowIndex, colIndex) {
            _super.prototype.paste.call(this, data, rowIndex, colIndex);
        };
        TreeClipboard.prototype.getModuleName = function () {
            return 'clipboard';
        };
        TreeClipboard.prototype.destroy = function () {
            _super.prototype.destroy.call(this);
        };
        TreeClipboard.prototype.childContentData = function (currentRecords, selectedIndex, rows, withHeader) {
            var getCopyData = 'getCopyData';
            var copyContent = 'copyContent';
            var childRecords = 'childRecords';
            var hasChildRecords = 'hasChildRecords';
            var uniqueID = 'uniqueID';
            if (currentRecords[parseInt(selectedIndex.toString(), 10)]["" + hasChildRecords]) {
                var childData = currentRecords[parseInt(selectedIndex.toString(), 10)]["" + childRecords];
                for (var i = 0; i < childData.length; i++) {
                    for (var j = 0; j < currentRecords.length; j++) {
                        if (!ej2_base_1.isNullOrUndefined(childData[parseInt(i.toString(), 10)]["" + uniqueID]) && currentRecords[parseInt(j.toString(), 10)]["" + uniqueID] === childData[parseInt(i.toString(), 10)]["" + uniqueID]) {
                            Eif ((!ej2_base_1.isNullOrUndefined(rows[parseInt(j.toString(), 10)])) && !rows[parseInt(j.toString(), 10)].classList.contains('e-summaryrow')) {
                                var cells = [].slice.call(rows[parseInt(j.toString(), 10)].querySelectorAll('.e-rowcell'));
                                var uniqueid = currentRecords[parseInt(j.toString(), 10)]["" + uniqueID];
                                Eif (this.copiedUniqueIdCollection.indexOf(uniqueid) === -1) {
                                    this["" + getCopyData](cells, false, '\t', withHeader);
                                    this.treeCopyContent += ('\n' + this["" + copyContent]);
                                    this["" + copyContent] = '';
                                    this.copiedUniqueIdCollection.push(uniqueid);
                                    this.childContentData(currentRecords, j, rows, withHeader);
                                }
                            }
                            break;
                        }
                    }
                }
            }
        };
        return TreeClipboard;
    }(ej2_grids_1.Clipboard));
    exports.TreeClipboard = TreeClipboard;
});