all files / grid/actions/ print.js

95.45% Statements 147/154
86.44% Branches 51/59
100% Functions 21/21
95.45% Lines 147/154
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               1195× 1195× 1195× 1195×     1195× 1195× 1195× 1195× 1195× 1195×   1195× 1195× 10×   1185× 1815×   1815×       20× 20× 20×     10×   130×     1605×     13× 13×     13× 13× 13× 13× 64× 64×       13×     13× 13× 13× 13× 13× 13× 13×     13× 13× 13× 13× 13×     13× 13× 13×     15× 14× 14×   13×             13× 13×   13×   11× 10×       11× 11×   11×         11× 54× 54×   11× 11×       11× 11× 11× 11×     11× 11× 11×   12× 12× 11×   12× 12× 12× 12× 12×     24× 24× 24× 24× 19×     47×     15× 10× 12×       4760×   1127×   1126× 1126× 1126× 1126×   20559×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/util", "../base/grid", "../base/constant", "@syncfusion/ej2-data", "../base/string-literals"], function (require, exports, ej2_base_1, util_1, grid_1, events, ej2_data_1, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function getCloneProperties() {
        return ['aggregates', 'allowGrouping', 'allowFiltering', 'allowMultiSorting', 'allowReordering', 'allowSorting',
            'allowTextWrap', 'childGrid', 'columns', 'currentViewData', 'dataSource', 'detailTemplate', 'enableAltRow',
            'enableColumnVirtualization', 'filterSettings', 'gridLines',
            'groupSettings', 'height', 'locale', 'pageSettings', 'printMode', 'query', 'queryString', 'enableRtl',
            'rowHeight', 'rowTemplate', 'sortSettings', 'textWrapSettings', 'allowPaging', 'hierarchyPrintMode', 'searchSettings',
            'queryCellInfo', 'beforeDataBound'];
    }
    exports.getCloneProperties = getCloneProperties;
    var Print = (function () {
        function Print(parent, scrollModule) {
            this.isAsyncPrint = false;
            this.defered = new ej2_data_1.Deferred();
            this.parent = parent;
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.contentReady, this.isContentReady(), this);
            this.actionBeginFunction = this.actionBegin.bind(this);
            this.parent.addEventListener(events.actionBegin, this.actionBeginFunction);
            this.parent.on(events.onEmpty, this.onEmpty.bind(this));
            this.parent.on(events.hierarchyPrint, this.hierarchyPrint, this);
            this.scrollModule = scrollModule;
        }
        Print.prototype.isContentReady = function () {
            var _this = this;
            if (this.isPrintGrid() && (this.parent.hierarchyPrintMode === 'None' || !this.parent.childGrid)) {
                return this.contentReady;
            }
            return function () {
                _this.defered.promise.then(function () {
                    _this.contentReady();
                });
                if (_this.isPrintGrid()) {
                    _this.hierarchyPrint();
                }
            };
        };
        Print.prototype.hierarchyPrint = function () {
            this.removeColGroup(this.parent);
            var printGridObj = window.printGridObj;
            if (printGridObj && !printGridObj.element.querySelector('[aria-busy=true')) {
                printGridObj.printModule.defered.resolve();
            }
        };
        Print.prototype.print = function () {
            this.renderPrintGrid();
        };
        Print.prototype.onEmpty = function () {
            if (this.isPrintGrid()) {
                this.contentReady();
            }
        };
        Print.prototype.actionBegin = function () {
            if (this.isPrintGrid()) {
                this.isAsyncPrint = true;
            }
        };
        Print.prototype.renderPrintGrid = function () {
            var gObj = this.parent;
            var element = ej2_base_1.createElement('div', {
                id: this.parent.element.id + '_print', className: gObj.element.className + ' e-print-grid'
            });
            element.classList.remove('e-gridhover');
            document.body.appendChild(element);
            var printGrid = new grid_1.Grid(util_1.getPrintGridModel(gObj, gObj.hierarchyPrintMode));
            for (var i = 0; i < printGrid.columns.length; i++) {
                printGrid.columns[parseInt(i.toString(), 10)] = ej2_base_1.extend({}, printGrid.columns[parseInt(i.toString(), 10)]);
                Iif (!gObj.getFrozenColumns() && gObj.isFrozenGrid()) {
                    printGrid.columns[parseInt(i.toString(), 10)].freeze = undefined;
                }
            }
            Iif (this.parent.isAngular) {
                printGrid.viewContainerRef = this.parent.viewContainerRef;
            }
            printGrid.load = function () { };
            printGrid.query = gObj.getQuery().clone();
            window.printGridObj = printGrid;
            printGrid.isPrinting = true;
            var modules = printGrid.getInjectedModules();
            var injectedModues = gObj.getInjectedModules();
            Iif (!modules || modules.length !== injectedModues.length) {
                printGrid.setInjectedModules(injectedModues);
            }
            gObj.notify(events.printGridInit, { element: element, printgrid: printGrid });
            this.parent.log('exporting_begin', this.getModuleName());
            printGrid.registeredTemplate = this.parent.registeredTemplate;
            printGrid.isVue = this.parent.isVue;
            Iif (this.parent.isVue) {
                printGrid.vueInstance = this.parent.vueInstance;
            }
            printGrid.appendTo(element);
            Eif (!gObj.isVue3) {
                printGrid.trigger = gObj.trigger;
            }
        };
        Print.prototype.contentReady = function () {
            if (this.isPrintGrid()) {
                var gObj = this.parent;
                if (this.isAsyncPrint) {
                    this.printGrid();
                    return;
                }
                var args = {
                    requestType: 'print',
                    element: gObj.element,
                    selectedRows: gObj.getContentTable().querySelectorAll('tr[aria-selected="true"]'),
                    cancel: false,
                    hierarchyPrintMode: gObj.hierarchyPrintMode
                };
                Eif (!this.isAsyncPrint) {
                    gObj.trigger(events.beforePrint, args);
                }
                if (args.cancel) {
                    ej2_base_1.detach(gObj.element);
                    return;
                }
                if (!this.isAsyncPrint) {
                    this.printGrid();
                }
            }
        };
        Print.prototype.printGrid = function () {
            var gObj = this.parent;
            if (gObj.height !== 'auto') {
                var cssProps = this.scrollModule.getCssProperties();
                var contentDiv = gObj.element.querySelector('.' + literals.content);
                var headerDiv = gObj.element.querySelector('.' + literals.gridHeader);
                contentDiv.style.height = 'auto';
                contentDiv.style.overflowY = 'auto';
                headerDiv.style[cssProps.padding] = '';
                headerDiv.firstElementChild.style[cssProps.border] = '';
            }
            if (gObj.allowGrouping) {
                if (!gObj.groupSettings.columns.length) {
                    gObj.element.querySelector('.e-groupdroparea').style.display = 'none';
                }
                else {
                    this.removeColGroup(gObj);
                }
            }
            for (var _i = 0, _a = [].slice.call(gObj.element.getElementsByClassName(literals.content)); _i < _a.length; _i++) {
                var element = _a[_i];
                element.style.overflowX = 'hidden';
            }
            var waitingPop = [].slice.call(gObj.element.getElementsByClassName('e-spin-show'));
            for (var _b = 0, _c = [].slice.call(waitingPop); _b < _c.length; _b++) {
                var element = _c[_b];
                ej2_base_1.classList(element, ['e-spin-hide'], ['e-spin-show']);
            }
            this.printGridElement(gObj);
            gObj.isPrinting = false;
            delete window.printGridObj;
            var args = {
                element: gObj.element
            };
            gObj.trigger(events.printComplete, args);
            gObj.destroy();
            this.parent.log('exporting_complete', this.getModuleName());
        };
        Print.prototype.printGridElement = function (gObj) {
            ej2_base_1.classList(gObj.element, ['e-print-grid-layout'], ['e-print-grid']);
            if (gObj.isPrinting) {
                ej2_base_1.detach(gObj.element);
            }
            this.printWind = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
            Eif (!ej2_base_1.isNullOrUndefined(this.printWind)) {
                this.printWind.moveTo(0, 0);
                this.printWind.resizeTo(screen.availWidth, screen.availHeight);
                this.printWind = ej2_base_1.print(gObj.element, this.printWind);
            }
        };
        Print.prototype.removeColGroup = function (gObj) {
            var depth = gObj.groupSettings.columns.length;
            var element = gObj.element;
            var id = '#' + gObj.element.id;
            if (!depth) {
                return;
            }
            var groupCaption = ej2_base_1.selectAll('.e-groupcaption', element);
            var colSpan = gObj.groupSettings.enableLazyLoading ? (parseInt(groupCaption[0].getAttribute('colspan'), 10) -
                (gObj.groupSettings.columns.length - 1)).toString() : groupCaption[depth - 1].getAttribute('colspan');
            for (var i = 0; i < groupCaption.length; i++) {
                groupCaption[parseInt(i.toString(), 10)].setAttribute('colspan', colSpan);
            }
            var colGroups = ej2_base_1.selectAll("colgroup" + id + "colgroup", element);
            var contentColGroups = ej2_base_1.selectAll('.e-content colgroup', element);
            var footerColGroups = ej2_base_1.selectAll('.e-summarycontent colgroup', element);
            this.hideColGroup(colGroups, depth);
            this.hideColGroup(contentColGroups, depth);
            this.hideColGroup(footerColGroups, depth);
        };
        Print.prototype.hideColGroup = function (colGroups, depth) {
            for (var i = 0; i < colGroups.length; i++) {
                for (var j = 0; j < depth; j++) {
                    colGroups[parseInt(i.toString(), 10)].children[parseInt(j.toString(), 10)].style.display = 'none';
                }
            }
        };
        Print.prototype.isPrintGrid = function () {
            return this.parent.element.id.indexOf('_print') > 0 && this.parent.isPrinting;
        };
        Print.prototype.destroy = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.contentReady, this.contentReady.bind(this));
            this.parent.removeEventListener(events.actionBegin, this.actionBeginFunction);
            this.parent.off(events.onEmpty, this.onEmpty.bind(this));
            this.parent.off(events.hierarchyPrint, this.hierarchyPrint);
        };
        Print.prototype.getModuleName = function () {
            return 'print';
        };
        Print.printGridProp = getCloneProperties().concat([events.beforePrint, events.printComplete, events.load]);
        return Print;
    }());
    exports.Print = Print;
});