UNPKG

devexpress-reporting

Version:

DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.

981 lines (980 loc) 49.9 kB
/** * DevExpress HTML/JS Reporting (viewer\reportPreview.js) * Version: 20.2.13 * Build date: Apr 10, 2023 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED * License: https://www.devexpress.com/Support/EULAs/universal.xml */ "use strict"; 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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var editingField_1 = require("./editing/editingField"); var _previewRequestWrapper_1 = require("./internal/_previewRequestWrapper"); var _sortingProcessor_1 = require("./internal/_sortingProcessor"); var _page_1 = require("./internal/_page"); var settings_1 = require("./settings"); var _previewHandlersHelper_1 = require("./internal/_previewHandlersHelper"); var _utils_1 = require("../common/utils/_utils"); var exportOptionsPreview_1 = require("./exportOptions/exportOptionsPreview"); var _progressViewModel_1 = require("./internal/_progressViewModel"); var constants_1 = require("./constants"); var analytics_utils_1 = require("@devexpress/analytics-core/analytics-utils"); var ko = require("knockout"); var $ = require("jquery"); var analytics_internal_1 = require("@devexpress/analytics-core/analytics-internal"); var browser = require("devextreme/core/utils/browser"); var _previewBricksKeyboardHelper_1 = require("./accessibility/_previewBricksKeyboardHelper"); var ReportPreview = (function (_super) { __extends(ReportPreview, _super); function ReportPreview(handlerUri, previewRequestWrapper, previewHandlersHelper, callbacks, rtl, enableKeyboardSupport) { if (rtl === void 0) { rtl = false; } var _this_1 = _super.call(this) || this; _this_1.enableKeyboardSupport = enableKeyboardSupport; _this_1.predefinedZoomLevels = ko.observableArray([5, 2, 1.5, 1, 0.75, 0.5, 0.25]); _this_1._pageWidth = ko.observable(818); _this_1._pageHeight = ko.observable(1058); _this_1._pageBackColor = ko.observable(''); _this_1._currentReportId = ko.observable(null); _this_1._currentReportUrl = ko.observable(null); _this_1._currentDocumentId = ko.observable(null); _this_1._unifier = ko.observable(''); _this_1._currentOperationId = ko.observable(null); _this_1._stopBuildRequests = {}; _this_1._closeReportRequests = {}; _this_1._closeDocumentRequests = {}; _this_1._editingFields = ko.observable([]); _this_1._startBuildOperationId = ''; _this_1._editingValuesSubscriptions = []; _this_1._workerTicker = null; _this_1._workerFunctionBlobUrl = null; _this_1._workerTickerFunction = function () { var started, interval; self.onmessage = function (e) { if (e.data === 'stop') { clearInterval(interval); return; } if (started) return; interval = setInterval(function () { postMessage.apply(self, ['tick']); }, 10); started = true; }; }; _this_1._drillDownState = []; _this_1._sortingState = []; _this_1._sortingProcessor = new _sortingProcessor_1.SortingProcessor(function () { return _this_1._sortingState || []; }); _this_1._getBuildStatusDeferreds = []; _this_1._timeouts = []; _this_1._deferreds = []; _this_1._window = null; _this_1.getSelectedContent = function (punctuationMark) { if (punctuationMark === void 0) { punctuationMark = ''; } var currentPage = _this_1.pages()[_this_1.pageIndex()]; if (!currentPage || !currentPage.brickColumnWidthArray) { return ''; } var activeBricks = []; var getActiveBricks = function (currentBrick, resultArray) { if (!currentBrick) { return; } currentBrick.active() && currentBrick.genlIndex != -1 && activeBricks.push(currentBrick); currentBrick.bricks && currentBrick.bricks.length != 0 && currentBrick.bricks.forEach(function (innerBrick) { getActiveBricks(innerBrick, resultArray); }); }; getActiveBricks(currentPage.brick(), activeBricks); if (!activeBricks) { return ''; } var sortedActiveBricks = []; var extendWithSpaces = function (width, text) { text = text ? text + punctuationMark : ''; var spaceCount = width - text.length; for (var i = 0; i <= spaceCount; i++) { text += ' '; } return text; }; var firstUsedColumn = currentPage.brickColumnWidthArray.length, lastUsedColumn = -1; activeBricks.forEach(function (activeBrick) { var row = sortedActiveBricks[activeBrick.row]; if (!row) { row = []; sortedActiveBricks[activeBrick.row] = row; } row[activeBrick.col] = activeBrick.text(); if (firstUsedColumn > activeBrick.col) { firstUsedColumn = activeBrick.col; } if (lastUsedColumn < activeBrick.col) { lastUsedColumn = activeBrick.col; } }); var result = ''; sortedActiveBricks.forEach(function (row) { for (var c = firstUsedColumn; c <= lastUsedColumn; c++) { result += extendWithSpaces(currentPage.brickColumnWidthArray[c], row[c]); } result += '\r\n'; }); return result; }; _this_1.rtlReport = ko.observable(false); _this_1.currentPage = ko.observable(null); _this_1.originalParametersInfo = ko.observable(null); _this_1.pageIndex = ko.observable(-1); _this_1.showMultipagePreview = ko.observable(false); _this_1.documentMap = ko.observable(); _this_1.exportOptionsModel = ko.observable(); _this_1.pageLoading = ko.observable(false); _this_1.errorMessage = ko.observable(''); _this_1.documentBuilding = ko.observable(false); _this_1.reportOpening = ko.observable(false); _this_1.pages = ko.observableArray([]).extend({ rateLimit: { timeout: 20, method: 'notifyWhenChangesStop' } }); _this_1.isAutoFit = ko.observable(true); _this_1.autoFitBy = ko.observable(constants_1.ZoomAutoBy.WholePage); _this_1.exportDisabled = ko.pureComputed(function () { var inProgress = _this_1.progressBar.inProgress(); var documentBuilding = _this_1.documentBuilding(); return _this_1.pageIndex() === -1 || inProgress || documentBuilding; }); _this_1._zoom = ko.observable(1); _this_1.zoom = ko.pureComputed({ read: function () { var autoFitBy = _this_1.autoFitBy(); if (autoFitBy != constants_1.ZoomAutoBy.None || _this_1._zoom() === 0) { return autoFitBy; } return _this_1._zoom(); }, write: function (val) { if (val > 0) { _this_1.autoFitBy(constants_1.ZoomAutoBy.None); _this_1._zoom(val); } else { _this_1.autoFitBy(val); } } }); _this_1.editingFieldsProvider = function () { return _this_1._editingFields(); }; _this_1._currentPageText = ko.pureComputed(function () { if (_this_1.pageIndex() === -1) { return analytics_utils_1.getLocalization('0 pages', 'ASPxReportsStringId.WebDocumentViewer_0Pages'); } else { var ofText = analytics_utils_1.getLocalization('of', 'ASPxReportsStringId.ToolBarItemText_OfLabel'); return (_this_1.pageIndex() + 1) + ' ' + ofText + ' ' + _this_1.pages().length; } }); _this_1._raiseOnSizeChanged = function () { _this_1.onSizeChanged() && _this_1.onSizeChanged()(); }; _this_1.previewSize = ko.observable(0); _this_1.onSizeChanged = ko.observable(); _this_1.previewVisible = ko.observable(false); _this_1.editingFieldsHighlighted = ko.observable(false); _this_1.canSwitchToDesigner = true; _this_1.allowURLsWithJSContent = false; _this_1.zoomStep = ko.observable(0.05); _this_1._progressFirstTime = false; _this_1.emptyDocumentCaption = ko.pureComputed(function () { var parametersInfo = _this_1.originalParametersInfo(); var parametersExist = parametersInfo && parametersInfo.parameters.some(function (x) { return x.Visible; }); var newCaption = ''; if (_this_1.documentBuilding()) { if (_this_1.currentPage()) { if (!_this_1._progressFirstTime) newCaption = analytics_internal_1.formatUnicorn(analytics_utils_1.getLocalization('Progress {0}%', 'ASPxReportsStringId.WebDocumentViewer_AriaDocumentProgress'), _this_1.progressBar.progress().toString()); else newCaption = _this_1.progressBar.progress() + '%'; _this_1._progressFirstTime = true; } else { newCaption = analytics_utils_1.getLocalization('Creating the document...', 'PreviewStringId.Msg_CreatingDocument'); } } else if (parametersExist && !_this_1.documentId) { newCaption = analytics_utils_1.getLocalization('Waiting for parameter values...', 'PreviewStringId.Msg_WaitingForParameterValues'); } else if (_this_1.documentId) { _this_1._progressFirstTime = false; if (_this_1.pageIndex() !== -1 && !_this_1.progressBar.inProgress()) { newCaption = analytics_utils_1.getLocalization('Document is ready', 'ASPxReportsStringId.WebDocumentViewer_AriaDocumentReady'); } else { newCaption = analytics_utils_1.getLocalization('The document does not contain any pages.', 'PreviewStringId.Msg_EmptyDocument'); } } else if (_this_1.reportOpening()) { _this_1._progressFirstTime = false; newCaption = analytics_utils_1.getLocalization('Loading...', 'AnalyticsCoreStringId.Loading'); } else if (_this_1.errorMessage()) { newCaption = _this_1.errorMessage(); } return newCaption; }).extend({ rateLimit: { timeout: 1000 } }); _this_1.exportOptionsTabVisible = ko.observable(true); settings_1.HandlerUri(handlerUri || settings_1.HandlerUri()); _this_1.progressBar = new _progressViewModel_1.ProgressViewModel(enableKeyboardSupport); _this_1.editingFieldChanged = callbacks && callbacks.editingFieldChanged; _this_1.previewHandlersHelper = previewHandlersHelper || new _previewHandlersHelper_1.PreviewHandlersHelper(_this_1); _this_1.requestWrapper = previewRequestWrapper || new _previewRequestWrapper_1.PreviewRequestWrapper(null, callbacks); _this_1.rtlViewer = rtl; if (callbacks) { _this_1.customProcessBrickClick = callbacks.previewClick; _this_1.customizeExportOptions = callbacks.customizeExportOptions; } _this_1._disposables.push(_this_1.documentBuilding.subscribe(function (newVal) { if (!newVal) { _this_1._unifier(_utils_1.generateGuid()); var documentId = _this_1._currentDocumentId(); var pageCount = _this_1.pages().length; for (var i = 0; i < pageCount; i++) { var page = _this_1.pages()[i]; if (!page.pageLoading()) { page.clearBricks(); } page.updateSize(_this_1._zoom()); page.actualResolution = 0; page.isClientVisible() && page._setPageImgSrc(documentId, _this_1._unifier(), _this_1._zoom()); } if (callbacks && callbacks.documentReady && documentId) { var self = _this_1; setTimeout(function () { callbacks.documentReady(documentId, self._currentReportId(), pageCount); }); } } })); _this_1._disposables.push(_this_1._currentDocumentId.subscribe(function (newVal) { _this_1._unifier(newVal ? _utils_1.generateGuid() : ''); })); _this_1._disposables.push(_this_1.previewSize.subscribe(function () { return _this_1._raiseOnSizeChanged(); })); _this_1._disposables.push(_this_1.zoom); _this_1._disposables.push(_this_1.exportDisabled); _this_1._disposables.push(_this_1._currentPageText); _this_1._disposables.push(_this_1.progressBar); _this_1._disposables.push(_this_1.emptyDocumentCaption); _this_1._disposables.push(_this_1._zoom.subscribe(function () { if (_this_1.showMultipagePreview()) { _this_1.pages().forEach(function (page) { page.updateSize(page.zoom()); page.isClientVisible(false); }); _this_1._raiseOnSizeChanged(); } else { var currentPage = _this_1.pages()[_this_1.pageIndex()]; currentPage && currentPage.isClientVisible.notifySubscribers(currentPage.isClientVisible.peek()); } })); _this_1._disposables.push(ko.computed(function () { var pagesArray = _this_1.pages(); var pageIndex = _this_1.pageIndex(); if (!pagesArray || pageIndex >= pagesArray.length) return; var currentPage = null; if (pageIndex >= 0) currentPage = pagesArray[pageIndex]; if (currentPage != _this_1.currentPage.peek()) _this_1.currentPage(currentPage); })); if (enableKeyboardSupport) { _this_1.previewBrickKeyboardHelper = new _previewBricksKeyboardHelper_1.PreviewBricksKeyboardHelper(_this_1); _this_1._disposables.push(_this_1.progressBar.visible, _this_1.previewBrickKeyboardHelper); } return _this_1; } ReportPreview.prototype._getUrlObject = function () { return window.URL || window['webkitURL'] || window['mozURL'] || window['msURL'] || window['oURL']; }; ReportPreview.prototype._createWorker = function () { this._terminateWorker(); var blob = new Blob(['(' + this._workerTickerFunction.toString() + ')()'], { type: 'text/javascript' }); var _url = this._getUrlObject(); this._workerFunctionBlobUrl = _url.createObjectURL(blob); this._workerTicker = new Worker(this._workerFunctionBlobUrl); return this._workerTicker; }; ReportPreview.prototype._terminateWorker = function () { if (this._workerTicker) { this._workerTicker.terminate(); this._workerTicker = null; } if (this._workerFunctionBlobUrl) { var _url = this._getUrlObject(); _url && _url.revokeObjectURL(this._workerFunctionBlobUrl); this._workerFunctionBlobUrl = null; } }; ReportPreview.prototype._callPrint = function (_window, asyncPrint) { var _this_1 = this; if (asyncPrint === void 0) { asyncPrint = false; } var browserLocal = browser.default || browser; var browserVersion = parseInt(browserLocal.version); if (_window && (browserLocal.chrome && 76 <= browserVersion)) { var worker = this._createWorker(); var checkOnTick = function () { try { if (_window.document && _window.document.contentType === 'application/pdf') { _window.print(); worker.postMessage('stop'); _this_1._terminateWorker(); } } catch (_a) { _this_1._terminateWorker(); } }; worker.onerror = function (e) { checkOnTick(); }; worker.onmessage = function (e) { checkOnTick(); }; worker.postMessage('start'); } }; ReportPreview.prototype._doDrillDown = function (drillDownKey) { this._drillDownState.forEach(function (x) { return x.Key === drillDownKey && (x.Value = !x.Value); }); this.closeDocument(); this.progressBar.complete(); this.documentMap(null); for (var i = this.pages().length - 1; i >= 0; i--) { var page = this.pages()[i]; if (i > this.pageIndex()) { this.pages.remove(page); } else { page._clear(); } } this._startBuildRequest(); }; ReportPreview.prototype._doSorting = function (sortData, shiftKey, ctrlKey) { if (!this._sortingProcessor.doSorting(sortData, shiftKey, ctrlKey)) return; this.closeDocument(); this.progressBar.complete(); this.documentMap(null); this.pages().forEach(function (page) { return page._clear(); }); this._startBuildRequest(); }; ReportPreview.prototype.dispose = function () { _super.prototype.dispose.call(this); (this._timeouts || []).forEach(function (tic) { return clearTimeout(tic); }); this._terminateWorker(); (this._deferreds || []).forEach(function (deferred) { return deferred.reject(); }); this.removeProperties(); this._sortingProcessor = null; }; ReportPreview.prototype.removeEmptyPages = function (all) { all && this.pages.removeAll(); for (var idx = this.pages().length - 1; idx >= 0; idx--) { var tempPage = this.pages()[idx]; (tempPage.isEmpty || tempPage.pageIndex === -1) && this.pages.remove(tempPage); } }; ReportPreview.prototype._initialize = function () { this._drillDownState = []; this._sortingState = []; this.closeDocument(); this._editingFields([]); this._editingValuesSubscriptions.forEach(function (item) { return item.dispose(); }); this._editingValuesSubscriptions = []; this.documentMap(null); this.pageIndex(-1); this.pageLoading(true); this.errorMessage(''); this.progressBar.complete(); this._getBuildStatusDeferreds.forEach(function (a) { return a.reject(); }); this._getBuildStatusDeferreds = []; this.pages().forEach(function (x) { return x.dispose(); }); this.pages([this.createPage(-1, undefined, this.pageLoading)]); }; ReportPreview.prototype.createPage = function (pageIndex, processClick, loading) { return new _page_1.PreviewPage(this, pageIndex, processClick, loading); }; ReportPreview.prototype._cleanTabInfo = function () { this.exportOptionsModel(null); this.documentMap(null); }; ReportPreview.prototype._clearReportInfo = function () { this._cleanTabInfo(); this.closeReport(); this.originalParametersInfo(null); }; ReportPreview.prototype._initExportWindow = function () { var message = analytics_utils_1.getLocalization('Do not close this tab to get the resulting file.', 'ASPxReportsStringId.WebDocumentViewer_AsyncExportCloseWarning'); var div = this._window.document.createElement('div'); div.style['text-align'] = 'center'; div.innerText = message; div.style.position = 'absolute'; div.style.left = '0'; div.style.top = '0'; div.style.right = '0'; div.style.fontSize = '20px'; this._window.document.title = analytics_utils_1.getLocalization('Exporting...', 'ASPxReportsStringId.WebDocumentViewer_AsyncExportTabTitle'); this._window.document.body.appendChild(div); }; ReportPreview.prototype._export = function (args, actionUri, inlineResult, printable) { var _this_1 = this; if (printable === void 0) { printable = false; } this._terminateWorker(); var deffered = $.Deferred(); if (this._editingFields().length > 0 || settings_1.AsyncExportApproach() || this.exportOptionsModel().hasSensitiveData()) { this._window = window.open(); this._window.onunload = function () { _this_1.progressBar.stop(); _this_1._terminateWorker(); }; this._initExportWindow(); this.progressBar.text(analytics_utils_1.getLocalization('Exporting the document...', 'PreviewStringId.Msg_ExportingDocument')); this.progressBar.cancelText(analytics_utils_1.getLocalization('Cancel', 'AnalyticsCoreStringId.SearchDialog_Cancel')); this.progressBar.startProgress(function () { _this_1._currentOperationId(null); }); this.requestWrapper.getStartExportOperation(args) .done(function (response) { _this_1.previewHandlersHelper.doneStartExportHandler(deffered, inlineResult, response, printable); }) .fail(function (error) { _this_1.previewHandlersHelper.errorStartExportHandler(deffered, error); }); } else { deffered.resolve(true); var exportUrl = actionUri + '?actionKey=exportTo&arg=' + args; if (printable && this._shouldUseBlob(actionUri)) { var newWindow = this._safelyRunWindowOpen(''); this._printUsingBlob(newWindow, exportUrl); } else { var _window = this._safelyRunWindowOpen(exportUrl); printable && this._callPrint(_window); } } return deffered.promise(); }; ReportPreview.prototype._shouldUseBlob = function (actionUri) { var browserLocal = browser.default || browser; var isNewChrome = browserLocal.chrome && (parseInt(browserLocal.version) >= 76); return ((!actionUri.indexOf('http://') || !actionUri.indexOf('https://') || !actionUri.indexOf('ftp://') || !actionUri.indexOf('ftps://')) && actionUri.indexOf(location.origin) === -1) && isNewChrome; }; ReportPreview.prototype._printUsingBlob = function (_newWindow, exportedDocumentUrl, asyncPrint) { var _this = this; var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { var _url = _this._getUrlObject(); var blobUrl = _url.createObjectURL(this.response); _newWindow.location.replace(blobUrl); setTimeout(function () { _url.revokeObjectURL(blobUrl); }, 1); _this._callPrint(_newWindow, asyncPrint); } }; xhr.open('GET', exportedDocumentUrl); xhr.responseType = 'blob'; xhr.send(); }; ReportPreview.prototype._safelyRunWindowOpen = function (url, target, useIFrame, printable) { if (target === void 0) { target = '_blank'; } if (useIFrame === void 0) { useIFrame = false; } if (printable === void 0) { printable = false; } var newWindow = window.open(url, target); target === '_blank' && newWindow && (newWindow.opener = newWindow); return newWindow; }; ReportPreview.prototype.createBrickClickProcessor = function (cyclePageIndex) { var _self = this; return function (brick, e) { _self.goToPage(cyclePageIndex, true); if (!brick) return; var page = _self.pages()[cyclePageIndex]; if (!page) return; page.selectBrick(''); var shiftKey = !!(e && e.shiftKey); var ctrlKey = !!(e && e.ctrlKey); var brickNavigation = brick && brick.navigation; var defaultHandler = function () { if (brickNavigation) { if (brickNavigation.drillDownKey && _self.reportId && _self._doDrillDown && _self._drillDownState.length > 0) { if (_self._startBuildOperationId) return; _self._doDrillDown(brickNavigation.drillDownKey); } else if (brickNavigation.sortData && _self.reportId && _self._doSorting && _self._sortingState.length > 0) { if (_self._startBuildOperationId) return; _self._doSorting(brickNavigation.sortData, shiftKey, ctrlKey); } if (brickNavigation.pageIndex >= 0) { var targetPage = _self.pages().filter(function (page) { return page.pageIndex === brickNavigation.pageIndex; })[0]; if (targetPage) { _self.goToPage(brickNavigation.pageIndex); targetPage.selectBrick(brickNavigation.indexes); _self.brickClickDocumentMapHandler && _self.brickClickDocumentMapHandler(brickNavigation); } } else { var validateUrl = function (url) { var isUrlString = typeof url === 'string'; if (isUrlString) { url = url.toLocaleLowerCase(); } if (url === 'empty') { return false; } return _self.allowURLsWithJSContent || (isUrlString && (url.indexOf('javascript:') === -1)); }; if (brickNavigation.url && validateUrl(brickNavigation.url)) { _self._safelyRunWindowOpen(brickNavigation.url, brickNavigation.target || '_blank'); } } } }; if (_self.customProcessBrickClick && _self.customProcessBrickClick(cyclePageIndex, brick, defaultHandler)) return; defaultHandler(); }; }; ReportPreview.prototype.delayedInit = function () { this.previewBrickKeyboardHelper && this.previewBrickKeyboardHelper.delayedInit(); }; ReportPreview.prototype.openReport = function (reportName) { this._clearReportInfo(); var deferred = $.Deferred(); this._deferreds.push(deferred); this._openReportOperationDeferred = deferred; this.requestWrapper.openReport(reportName).done(function (response) { deferred.resolve(response); }).fail(function (error) { deferred.reject(error); }); return this.initialize(deferred.promise()); }; ReportPreview.prototype.drillThrough = function (customData, closeCurrentReport) { var _this_1 = this; if (closeCurrentReport === void 0) { closeCurrentReport = true; } var deferred = $.Deferred(); this.requestWrapper.drillThrough(customData).done(function (response) { if (closeCurrentReport) { _this_1._clearReportInfo(); _this_1.initialize(deferred.promise()); } deferred.resolve(response); }).fail(function (error) { deferred.reject(error); }); return deferred.promise(); }; ReportPreview.prototype.initialize = function (initializeDataPromise) { var _this_1 = this; this.reportOpening(true); this._currentReportId(null); this._currentReportUrl(null); this._currentDocumentId(null); this._initialize(); var _initializeDeferred = $.Deferred(); this._deferreds.push(_initializeDeferred); _initializeDeferred.done(function () { initializeDataPromise.done(function (previewInitialize) { _this_1.reportOpening(false); if (previewInitialize && !previewInitialize.error && (previewInitialize.reportId || previewInitialize.documentId)) { _this_1._currentReportId(previewInitialize.reportId); _this_1._currentReportUrl(previewInitialize.reportUrl); _this_1._currentDocumentId(previewInitialize.documentId); _this_1.rtlReport(previewInitialize.rtlReport); var pageSettings = previewInitialize.pageSettings; if (pageSettings) { if (pageSettings.height) _this_1._pageHeight(pageSettings.height); if (pageSettings.width) _this_1._pageWidth(pageSettings.width); _this_1._pageBackColor((pageSettings.color && _this_1.readerMode) ? 'rgba(' + pageSettings.color + ')' : ''); } var deserializedExportOptions = _this_1._deserializeExportOptions(previewInitialize.exportOptions, !_this_1.reportId && (!previewInitialize.documentData || !previewInitialize.documentData.canPerformContinuousExport)); var customizeExportOptionsArgs = { exportOptions: deserializedExportOptions, panelVisible: true }; _this_1.customizeExportOptions && _this_1.customizeExportOptions(customizeExportOptionsArgs); _this_1.exportOptionsTabVisible(customizeExportOptionsArgs.panelVisible); _this_1.exportOptionsModel(deserializedExportOptions); _this_1.originalParametersInfo(previewInitialize.parametersInfo); if (previewInitialize.documentId) { _this_1.progressBar.startProgress(function () { _this_1.documentBuilding(false); }, function () { _this_1.stopBuild(); }); _this_1.documentBuilding(true); var doGetBuildStatusFunc = _this_1.getDoGetBuildStatusFunc(); doGetBuildStatusFunc(previewInitialize.documentId); } } else { _this_1.pageLoading(false); _this_1._processError(analytics_utils_1.getLocalization('The report preview initialization has failed', 'ASPxReportsStringId.WebDocumentViewer_InitializationError'), previewInitialize && previewInitialize.error); } }).fail(function (error) { _this_1.reportOpening(false); _this_1.removeEmptyPages(); }); }).resolve(); return initializeDataPromise; }; ReportPreview.prototype._deserializeExportOptions = function (exportOptionsString, isMerged) { var jsonModel = exportOptionsString && JSON.parse(exportOptionsString); return isMerged ? new exportOptionsPreview_1.ExportOptionsMergedPreview(jsonModel) : new exportOptionsPreview_1.ExportOptionsPreview(jsonModel); }; ReportPreview.prototype.deactivate = function () { this._initialize(); this._cleanTabInfo(); this.closeReport(); this._currentDocumentId(null); this._currentReportId(null); this._currentReportUrl(null); this.originalParametersInfo(null); }; ReportPreview.prototype.startBuild = function () { this._initialize(); return this._startBuildRequest(); }; ReportPreview.prototype.updateExportStatus = function (progress) { this.progressBar && this.progressBar.progress(progress); if (this._window) { var div = this._window.document.getElementById('loading'); if (!div) { div = this._window.document.createElement('div'); div.id = 'loading'; div.style.position = 'absolute'; div.style.left = '0'; div.style.top = '0'; div.style.bottom = '0'; div.style.right = '0'; div.style['text-align'] = 'center'; div.style.margin = 'auto'; div.style.height = '0'; div.style.fontSize = '32px'; this._window.document.body.appendChild(div); } div.innerText = analytics_utils_1.getLocalization('Exporting the document...', 'PreviewStringId.Msg_ExportingDocument') + ' ' + progress + '%'; this._window.document.title = analytics_utils_1.getLocalization('Exporting...', 'ASPxReportsStringId.WebDocumentViewer_AsyncExportTabTitle') + progress + '%'; } }; ReportPreview.prototype.customDocumentOperation = function (customData, hideMessageFromUser) { var documentId = this._currentDocumentId(); if (this.documentBuilding() || !documentId) return; var serializedExportOptions = this.exportOptionsModel() ? JSON.stringify(new analytics_utils_1.ModelSerializer().serialize(this.exportOptionsModel())) : null; var editingFields = this._editingFields && this._editingFields().map(function (item) { return item.editValue(); }); var deferred = $.Deferred(); this.requestWrapper.customDocumentOperation(documentId, serializedExportOptions, editingFields, customData, hideMessageFromUser) .done(function (response) { try { if (response && response.message) { var handler = response.succeeded ? settings_1.MessageHandler().processMessage : settings_1.MessageHandler().processError; handler(response.message, !hideMessageFromUser); } } finally { deferred.resolve(response); } }) .fail(function (error) { var response = { message: analytics_utils_1.getLocalization('The requested document operation cannot be performed.', 'ASPxReportsStringId.WebDocumentViewer_CustomDocumentOperationsDenied_Error') }; deferred.reject(response); }); return deferred.promise(); }; ReportPreview.prototype._initializeStartBuild = function () { var _this_1 = this; if (this.documentBuilding() || this._startBuildOperationId) { return false; } this._startBuildOperationId = _utils_1.generateGuid(); this._currentDocumentId(null); this.progressBar.text(analytics_utils_1.getLocalization('Creating the document...', 'PreviewStringId.Msg_CreatingDocument')); this.progressBar.cancelText(analytics_utils_1.getLocalization('Cancel', 'AnalyticsCoreStringId.SearchDialog_Cancel')); this.progressBar.startProgress(function () { _this_1.documentBuilding(false); }, function () { _this_1.stopBuild(); }); this.documentBuilding(true); return true; }; ReportPreview.prototype._startBuildRequest = function () { var _this_1 = this; if (!this._initializeStartBuild()) { return null; } var deffered = $.Deferred(); var currentReportId = this._currentReportId(); var startBuildOperationId = this._startBuildOperationId; var shouldIgnoreError = function () { return _this_1._closeReportRequests[currentReportId]; }; this.requestWrapper.startBuildRequest(shouldIgnoreError) .done(function (response) { _this_1.previewHandlersHelper.doneStartBuildHandler(deffered, response, startBuildOperationId); }) .fail(function (error) { _this_1.previewHandlersHelper.errorStartBuildHandler(deffered, error); }); deffered.always(function () { return _this_1._startBuildOperationId = ''; }); return deffered.promise(); }; ReportPreview.prototype.getExportStatus = function (operationId) { var _this_1 = this; var deffered = $.Deferred(); this._timeouts.push(setTimeout(function () { _this_1.requestWrapper.getExportStatusRequest(operationId) .done(function (response) { _this_1.previewHandlersHelper.doneExportStatusHandler(deffered, operationId, response); }) .fail(function (error) { _this_1.previewHandlersHelper.errorExportStatusHandler(deffered, error); }); }, 250)); return deffered.promise(); }; ReportPreview.prototype.getExportResult = function (operationId, inlineDisposition, token, printable, uri) { if (printable === void 0) { printable = false; } if (uri === void 0) { uri = ''; } if (uri) { } else if (token) { var arg = analytics_internal_1.formatUnicorn('?token={0}&printable={1}', encodeURIComponent(token), printable); uri = settings_1.ReportServerDownloadUri() + arg; } else { var arg = encodeURIComponent(JSON.stringify({ id: operationId, inlineResult: !!inlineDisposition })); uri = settings_1.HandlerUri() + '?actionKey=getExportResult&arg=' + arg; } if (this._window) { this._window.onunload = null; if (printable && this._shouldUseBlob(uri)) { this._printUsingBlob(this._window, uri, true); } else { this._window.location.replace(uri); printable && this._callPrint(this._window, true); } } }; ReportPreview.prototype.getBuildStatus = function (documentId) { var _this_1 = this; var deffered = $.Deferred(); this._deferreds.push(deffered); var sessionDeffered = $.Deferred(); this._getBuildStatusDeferreds.push(sessionDeffered); this._timeouts.push(setTimeout(function () { var ignorePredicate = function () { return _this_1._closeDocumentRequests[documentId]; }; _this_1.requestWrapper.getBuildStatusRequest(documentId, ignorePredicate) .done(function (response) { sessionDeffered.resolve(response); }) .fail(function (error) { sessionDeffered.reject(error); }); sessionDeffered.done(function (responce) { _this_1.previewHandlersHelper && _this_1.previewHandlersHelper.doneGetBuildStatusHandler(deffered, documentId, responce, ignorePredicate); }).fail(function (error) { _this_1.previewHandlersHelper && _this_1.previewHandlersHelper.errorGetBuildStatusHandler(deffered, error, ignorePredicate); }); }, 250)); return deffered.promise(); }; ReportPreview.prototype.getDoGetBuildStatusFunc = function () { var _this_1 = this; var preview = this; var doGetBuildStatus = function (documentId) { var promise = preview.getBuildStatus(documentId); promise.done(function (result) { if (documentId !== preview._currentDocumentId()) return; if (result && result.requestAgain && !preview._stopBuildRequests[documentId] && !preview._closeDocumentRequests[documentId]) { var doStatusRequest = function () { if (!preview._stopBuildRequests[documentId] && !preview._closeDocumentRequests[documentId]) { doGetBuildStatus(documentId); } }; settings_1.PollingDelay() ? _this_1._timeouts.push(setTimeout(doStatusRequest, settings_1.PollingDelay())) : doStatusRequest(); } else { try { if (result.error || !result.requestAgain && !result.pageCount) { preview.pageLoading(false); preview.removeEmptyPages(!result.pageCount); if (!preview.pages().length) preview.pageIndex(-1); return; } if (!result.completed) { return; } else if (result.pageCount < preview.pages().length) { preview.pageIndex(Math.min(result.pageCount - 1, preview.pageIndex())); preview.pages.splice(result.pageCount, preview.pages().length); } preview.getDocumentData(documentId); } finally { preview.progressBar.complete(); _this_1._timeouts.push(setTimeout(preview._raiseOnSizeChanged, 1000)); } } }); }; return doGetBuildStatus; }; ReportPreview.prototype.getDocumentData = function (documentId) { var _this_1 = this; var ignoreErrorPredicate = function () { return _this_1._closeDocumentRequests[documentId]; }; this.requestWrapper.getDocumentData(documentId, ignoreErrorPredicate) .done(function (response) { if (!response) { return; } _this_1._drillDownState = response.drillDownKeys || []; _this_1._sortingState = response.sortingState || []; if (response.canPerformContinuousExport === false && _this_1.reportId) { var deserializedExportOptions = _this_1._deserializeExportOptions(response.exportOptions || {}, true); var customizeExportOptionsArgs = { exportOptions: deserializedExportOptions, panelVisible: true }; _this_1.customizeExportOptions && _this_1.customizeExportOptions(customizeExportOptionsArgs); _this_1.exportOptionsTabVisible(customizeExportOptionsArgs.panelVisible); _this_1.exportOptionsModel(deserializedExportOptions); } _this_1.documentMap(response.documentMap); _this_1._editingValuesSubscriptions.forEach(function (item) { return item.dispose(); }); _this_1._editingValuesSubscriptions = []; _this_1._editingFields((response.editingFields || []).map(function (item, index) { var field = _this_1.createEditingField(item, index); if (_this_1.editingFieldChanged) { field.editingFieldChanged = _this_1.editingFieldChanged; } _this_1._editingValuesSubscriptions.push(field.editValue); return field; })); }); }; ReportPreview.prototype.exportDocumentTo = function (format, inlineResult) { if (!this._currentDocumentId()) return; var serializedExportOptions = this.exportOptionsModel() ? JSON.stringify(new analytics_utils_1.ModelSerializer().serialize(this.exportOptionsModel())) : null; var args = encodeURIComponent(JSON.stringify({ documentId: this._currentDocumentId(), exportOptions: serializedExportOptions, format: format, inlineResult: inlineResult, editingFieldValues: this._editingFields && this._editingFields().map(function (item) { var editValue = item.editValue(); if (typeof editValue === 'string') return _utils_1.transformNewLineCharacters(editValue); return editValue; }) })); this._export(args, settings_1.HandlerUri(), inlineResult); }; ReportPreview.prototype.printDocument = function (pageIndex) { if (!this._currentDocumentId()) return; var exportOptions = new exportOptionsPreview_1.ExportOptionsPreview({}); exportOptions.pdf['showPrintDialogOnOpen'] = true; pageIndex = parseInt(pageIndex); if ((!!pageIndex && pageIndex > 0 || pageIndex === 0) && (this.pages().length > pageIndex)) { (exportOptions.pdf['pageRange'] = pageIndex + 1); } var serializedExportOptions = JSON.stringify(new analytics_utils_1.ModelSerializer().serialize(exportOptions)); var args = encodeURIComponent(JSON.stringify({ documentId: this._currentDocumentId(), exportOptions: serializedExportOptions, format: 'printpdf', inlineResult: true, editingFieldValues: this._editingFields && this._editingFields().map(function (item) { return item.editValue(); }) })); this._export(args, settings_1.HandlerUri(), true, true); }; ReportPreview.prototype.stopBuild = function (documentId) { var id = documentId || this._currentDocumentId(); if (!id) { this._startBuildOperationId && (this._stopBuildRequests[this._startBuildOperationId] = true); return; } this._stopBuildRequests[id] = true; this.progressBar.complete(); this.requestWrapper.stopBuild(id); }; ReportPreview.prototype.closeDocument = function (documentId) { var _documentId = documentId || this._currentDocumentId(); if (!_documentId) { this._startBuildOperationId && (this._closeDocumentRequests[this._startBuildOperationId] = true); return; } this._closeDocumentRequests[_documentId] = true; this.progressBar.complete(); this.requestWrapper.sendCloseRequest(_documentId); }; ReportPreview.prototype.closeReport = function () { this._openReportOperationDeferred && this._openReportOperationDeferred.reject(); var currentReportId = this._currentReportId(); if (!currentReportId) { return; } this._closeReportRequests[currentReportId] = true; this.requestWrapper.sendCloseRequest(null, currentReportId); }; ReportPreview.prototype.goToPage = function (pageIndex, forcePageChanging, throttle) { var _this_1 = this; if (!forcePageChanging && this.pageIndex.peek() === pageIndex || this.pages.peek().length === 0 || pageIndex < 0 || pageIndex >= this.pages.peek().length) { return; } if (this._goToPageTimer !== undefined) { clearTimeout(this._goToPageTimer); } var updateActivePage = function (activePageIndex) { _this_1.pages.peek().forEach(function (page) { var visible = page.pageIndex === activePageIndex; page.active(visible); page.isClientVisible(visible); }); _this_1._goToPageTimer = undefined; }; if (throttle) this._timeouts.push(this._goToPageTimer = setTimeout(function () { return updateActivePage(_this_1.pageIndex()); }, throttle)); else updateActivePage(pageIndex); this.pageIndex(pageIndex); }; ReportPreview.prototype.createEditingField = function (item, index) { return new editingField_1.EditingField(item, index, this.requestWrapper); }; ReportPreview.prototype.currentPageAriaLabelImgAlt = function (index) { return analytics_internal_1.formatUnicorn(analytics_utils_1.getLocalization('Report Preview page {0} of {1}', 'ASPxReportsStringId.WebDocumentViewer_AriaLabelPreviewPage'), index + 1, this.pages().length); }; ReportPreview.prototype._getErrorMessage = function (jqXHR) { var serverError = analytics_internal_1.getErrorMessage(jqXHR); if (!serverError) return jqXHR && jqXHR.responseJSON && jqXHR.responseJSON.result && jqXHR.responseJSON.result.faultMessage ? jqXHR.responseJSON.result.faultMessage : serverError; return serverError; }; ReportPreview.prototype._processError = function (error, jqXHR, showForUser) { if (showForUser === void 0) { showForUser = true; } var prefix = error + ': '; var serverError = this._getErrorMessage(jqXHR); serverError && (error = prefix + serverError); settings_1.MessageHandler().processError(error, showForUser, serverError && prefix); }; Object.defineProperty(ReportPreview.prototype, "reportId", { get: function () { return this._currentReportId(); }, enumerable: true, configurable: true }); Object.defineProperty(ReportPreview.prototype, "reportUrl", { get: function () { return this._currentReportUrl(); }, enumerable: true, configurable: true }); Object.defineProperty(ReportPreview.prototype, "documentId", { get: function () { return this._currentDocumentId(); }, enumerable: true, configurable: true }); return ReportPreview; }(analytics_utils_1.Disposable)); exports.ReportPreview = ReportPreview;