all files / treegrid/actions/ pdf-export.js

83.16% Statements 79/95
71.15% Branches 37/52
93.33% Functions 14/15
83.16% Lines 79/95
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   20× 20× 20× 20×   11395×   20× 20×   19× 19×         19×   1157×                                                                       318× 59× 59× 59× 59× 59× 59×   318× 318×        
define(["require", "exports", "@syncfusion/ej2-grids", "../utils", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "../base/constant"], function (require, exports, ej2_grids_1, utils_1, ej2_base_1, ej2_data_1, event) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfExport = (function () {
        function PdfExport(parent) {
            ej2_grids_1.Grid.Inject(ej2_grids_1.PdfExport);
            this.parent = parent;
            this.dataResults = {};
            this.addEventListener();
        }
        PdfExport.prototype.getModuleName = function () {
            return 'PdfExport';
        };
        PdfExport.prototype.addEventListener = function () {
            this.parent.on('pdfCellInfo', this.pdfQueryCellInfo, this);
            this.parent.on('updateResults', this.updatePdfResultModel, this);
        };
        PdfExport.prototype.removeEventListener = function () {
            Eif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off('pdfCellInfo', this.pdfQueryCellInfo);
            this.parent.off('updateResults', this.updatePdfResultModel);
        };
        PdfExport.prototype.destroy = function () {
            this.removeEventListener();
        };
        PdfExport.prototype.updatePdfResultModel = function (returnResult) {
            this.dataResults = returnResult;
        };
        PdfExport.prototype.Map = function (pdfExportProperties, isMultipleExport, pdfDoc, isBlob) {
            var _this = this;
            var dtSrc = this.parent.dataSource;
            var prop = Object();
            var isLocal = !utils_1.isRemoteData(this.parent) && utils_1.isOffline(this.parent);
            ej2_base_1.setValue('cancel', false, prop);
            return new Promise(function (resolve) {
                var dm = isLocal && !(dtSrc instanceof ej2_data_1.DataManager) ? new ej2_data_1.DataManager(dtSrc)
                    : _this.parent.dataSource;
                var query = new ej2_data_1.Query();
                Iif (!isLocal) {
                    query = _this.generateQuery(query);
                    ej2_base_1.setValue('query', query, prop);
                }
                _this.parent.trigger(event.beforePdfExport, ej2_base_1.extend(prop, pdfExportProperties));
                Iif (ej2_grids_1.getObject('cancel', prop)) {
                    return null;
                }
                dm.executeQuery(query).then(function (e) {
                    var customsData = null;
                    if (!ej2_base_1.isNullOrUndefined(pdfExportProperties) && !ej2_base_1.isNullOrUndefined(pdfExportProperties.dataSource)) {
                        customsData = pdfExportProperties.dataSource;
                    }
                    pdfExportProperties = _this.manipulatePdfProperties(pdfExportProperties, dtSrc, e);
                    return _this.parent.grid.pdfExportModule.Map(_this.parent.grid, pdfExportProperties, isMultipleExport, pdfDoc, isBlob).then(function (document) {
                        if (customsData != null) {
                            pdfExportProperties.dataSource = customsData;
                        }
                        else {
                            delete pdfExportProperties.dataSource;
                        }
                        resolve(document);
                    });
                });
            });
        };
        PdfExport.prototype.generateQuery = function (query, prop) {
            if (!ej2_base_1.isNullOrUndefined(prop) && prop.exportType === 'CurrentPage'
                && this.parent.allowPaging) {
                prop.exportType = 'AllPages';
                query.addParams('ExportType', 'CurrentPage');
                query.where(this.parent.parentIdMapping, 'equal', null);
                query = ej2_grids_1.getObject('grid.renderModule.data.pageQuery', this.parent)(query);
            }
            return query;
        };
        PdfExport.prototype.manipulatePdfProperties = function (prop, dtSrc, queryResult) {
            var args = {};
            var isLocal = !utils_1.isRemoteData(this.parent) && utils_1.isOffline(this.parent);
            ej2_base_1.setValue('query', this.parent.grid.getDataModule().generateQuery(true), args);
            ej2_base_1.setValue('isExport', true, args);
            ej2_base_1.setValue('isPdfExport', true, args);
            if (!ej2_base_1.isNullOrUndefined(prop) && !ej2_base_1.isNullOrUndefined(prop.isCollapsedStatePersist)) {
                ej2_base_1.setValue('isCollapsedStatePersist', prop.isCollapsedStatePersist, args);
            }
            Iif (!ej2_base_1.isNullOrUndefined(prop) && !ej2_base_1.isNullOrUndefined(prop.exportType)) {
                ej2_base_1.setValue('exportType', prop.exportType, args);
            }
            Iif (!isLocal) {
                this.parent.parentData = [];
                this.parent.dataModule.convertToFlatData(ej2_base_1.getValue('result', queryResult));
                ej2_base_1.setValue('expresults', this.parent.flatData, args);
            }
            this.parent.notify('dataProcessor', args);
            args = this.dataResults;
            dtSrc = ej2_base_1.isNullOrUndefined(args.result) ? this.parent.flatData.slice(0) : args.result;
            Iif (!isLocal) {
                this.parent.flatData = [];
            }
            if (prop && prop.dataSource && isLocal) {
                var flatDatas = this.parent.flatData;
                var dataSrc = prop.dataSource instanceof ej2_data_1.DataManager ? prop.dataSource.dataSource.json : prop.dataSource;
                this.parent.dataModule.convertToFlatData(dataSrc);
                dtSrc = this.parent.flatData;
                this.parent.flatData = flatDatas;
            }
            prop = ej2_base_1.isNullOrUndefined(prop) ? {} : prop;
            prop.dataSource = new ej2_data_1.DataManager({ json: dtSrc });
            prop.query = args['query'];
            return prop;
        };
        PdfExport.prototype.pdfQueryCellInfo = function (args) {
            if (this.parent.grid.getColumnIndexByUid(args.column.uid) === this.parent.treeColumnIndex) {
                var style = {};
                var data = ej2_grids_1.getObject('data', args);
                var ispadfilter = ej2_base_1.isNullOrUndefined(data.filterLevel);
                var pad = ispadfilter ? data.level : data.filterLevel;
                style.paragraphIndent = pad * 3;
                args.style = style;
            }
            this.parent.notify('updateResults', args);
            this.parent.trigger('pdfQueryCellInfo', args);
        };
        return PdfExport;
    }());
    exports.PdfExport = PdfExport;
});