all files / grid/actions/ print.js

98.2% Statements 109/111
90.48% Branches 38/42
100% Functions 13/13
98.2% Lines 109/111
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   335× 335× 335× 335×     335× 335× 335× 335×     52×     673×         210× 210×   203×     196×       11780×                                               27×         12505×         7966×                      
define(["require", "exports", "@syncfusion/ej2-base", "../base/util", "../base/grid", "../base/constant"], function (require, exports, ej2_base_1, util_1, grid_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Print = (function () {
        function Print(parent, scrollModule) {
            this.isAsyncPrint = false;
            this.printing = 'isPrinting';
            this.parent = parent;
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.contentReady, this.contentReady.bind(this));
            this.parent.addEventListener(events.actionBegin, this.actionBegin.bind(this));
            this.parent.on(events.onEmpty, this.onEmpty.bind(this));
            this.scrollModule = scrollModule;
        }
        Print.prototype.print = function () {
            this.renderPrintGrid();
            this.printWind = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
            this.printWind.moveTo(0, 0);
            this.printWind.resizeTo(screen.availWidth, screen.availHeight);
        };
        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 elem = 'element';
            var printGridModel = {};
            var element = ej2_base_1.createElement('div', {
                id: this.parent.element.id + '_print', className: gObj.element.className + ' e-print-grid'
            });
            document.body.appendChild(element);
            for (var _i = 0, _a = Print.printGridProp; _i < _a.length; _i++) {
                var key = _a[_i];
                if (key === 'columns') {
                    printGridModel[key] = util_1.getActualPropFromColl(gObj[key]);
                }
                else if (key === 'allowPaging') {
                    printGridModel[key] = this.parent.printMode === 'CurrentPage';
                }
                else {
                    printGridModel[key] = util_1.getActualProperties(gObj[key]);
                }
            }
            var printGrid = new grid_1.Grid(printGridModel);
            printGrid.appendTo(element);
            printGrid[this.printing] = true;
            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
                };
                Eif (!this.isAsyncPrint) {
                    gObj.trigger(events.beforePrint, args);
                }
                if (args.cancel) {
                    ej2_base_1.detach(gObj.element);
                    return;
                }
                else if (!this.isAsyncPrint) {
                    this.printGrid();
                }
            }
        };
        Print.prototype.printGrid = function () {
            var gObj = this.parent;
            if (gObj.allowPaging && gObj.printMode === 'CurrentPage') {
                gObj.element.querySelector('.e-gridpager').style.display = 'none';
            }
            if (gObj.height !== 'auto') {
                var cssProps = this.scrollModule.getCssProperties();
                var contentDiv = gObj.element.querySelector('.e-content');
                var headerDiv = gObj.element.querySelector('.e-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.groupSettings.columns.length, gObj.element);
                    util_1.removeElement(gObj.element, '.e-grouptopleftcell');
                    util_1.removeElement(gObj.element, '.e-recordpluscollapse');
                    util_1.removeElement(gObj.element, '.e-indentcell');
                    util_1.removeElement(gObj.element, '.e-recordplusexpand');
                }
            }
            gObj.element.querySelector('.e-content').style.overflowX = 'hidden';
            if (gObj.allowFiltering && gObj.filterSettings.type === 'FilterBar') {
                gObj.element.querySelector('.e-filterbar').style.display = 'none';
            }
            var waitingPop = gObj.element.querySelectorAll('.e-spin-show');
            if (waitingPop.length > 0) {
                waitingPop[0].classList.add('e-spin-hide');
                waitingPop[0].classList.remove('e-spin-show');
            }
            Eif (gObj[this.printing]) {
                ej2_base_1.detach(gObj.element);
            }
            gObj.element.classList.remove('e-print-grid');
            this.printWind = ej2_base_1.print(gObj.element, this.printWind);
            gObj[this.printing] = false;
            var args = {
                element: gObj.element
            };
            gObj.trigger(events.printComplete, args);
        };
        Print.prototype.removeColGroup = function (depth, element) {
            var groupCaption = element.querySelectorAll('.e-groupcaption');
            var colSpan = groupCaption[depth - 1].getAttribute('colspan');
            for (var i = 0; i < groupCaption.length; i++) {
                groupCaption[i].setAttribute('colspan', colSpan);
            }
            var colGroups = element.querySelectorAll('colgroup');
            for (var i = 0; i < colGroups.length; i++) {
                for (var j = 0; j < depth; j++) {
                    colGroups[i].childNodes[j].style.display = 'none';
                }
            }
        };
        Print.prototype.isPrintGrid = function () {
            return this.parent.element.id.indexOf('_print') > 0 && this.parent[this.printing];
        };
        Print.prototype.destroy = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.contentReady, this.contentReady.bind(this));
            this.parent.removeEventListener(events.actionBegin, this.actionBegin.bind(this));
            this.parent.off(events.onEmpty, this.onEmpty.bind(this));
        };
        Print.prototype.getModuleName = function () {
            return 'print';
        };
        Print.printGridProp = [
            'aggregates', 'allowGrouping', 'allowFiltering', 'allowMultiSorting', 'allowReordering', 'allowSorting',
            'allowTextWrap', 'childGrid', 'columns', 'currentViewData', 'dataSource', 'detailTemplate', 'enableAltRow',
            'enableColumnVirtualization', 'filterSettings', 'gridLines',
            'groupSettings', 'height', 'locale', 'pageSettings', 'printMode', 'query', 'queryString',
            'rowHeight', 'rowTemplate', 'sortSettings', 'textWrapSettings', 'allowPaging',
            events.beforePrint, events.printComplete
        ];
        return Print;
    }());
    exports.Print = Print;
});