UNPKG

@progress/telerik-jquery-report-viewer

Version:

Progress® Telerik® Report Viewer for jQuery

164 lines (161 loc) 5.08 kB
import { ScaleModes, PageModes, ViewModes } from './enums.js'; import { Command } from './command.js'; var scaleTransitionMap = {}; scaleTransitionMap[ScaleModes.FIT_PAGE] = { scaleMode: ScaleModes.FIT_PAGE_WIDTH }; scaleTransitionMap[ScaleModes.FIT_PAGE_WIDTH] = { scaleMode: ScaleModes.SPECIFIC, scale: 1 }; scaleTransitionMap[ScaleModes.SPECIFIC] = { scaleMode: ScaleModes.FIT_PAGE }; var scaleValues = [0.1, 0.25, 0.5, 0.75, 1, 1.5, 2, 4, 8]; function CommandSet(options) { var controller = options.controller; if (!controller) { throw "No options.controller."; } var historyManager = options.history; if (!historyManager) { throw "No options.history."; } function getDocumentMapVisible() { var args = {}; controller.getDocumentMapState(args); return Boolean(args.visible); } function getParametersAreaVisible() { var args = {}; controller.getParametersAreaState(args); return Boolean(args.visible); } function getSideMenuVisible() { var args = {}; controller.getSideMenuVisible(args); return Boolean(args.visible); } function getSearchDialogVisible() { var args = {}; controller.getSearchDialogState(args); return Boolean(args.visible); } function getSendEmailDialogVisible() { var args = {}; controller.getSendEmailDialogState(args); return Boolean(args.visible); } return { "historyBack": new Command(function() { historyManager.back(); }), "historyForward": new Command(function() { historyManager.forward(); }), "stopRendering": new Command(function() { controller.stopRendering(); }), "goToPrevPage": new Command(function() { controller.navigateToPage(controller.getCurrentPageNumber() - 1); }), "goToNextPage": new Command(function() { controller.navigateToPage(controller.getCurrentPageNumber() + 1); }), "goToFirstPage": new Command(function() { controller.navigateToPage(1); }), "goToLastPage": new Command(function() { controller.navigateToPage(controller.getPageCount()); }), "goToPage": new Command(function(pageNumber) { if (!isNaN(pageNumber)) { var pageCount = controller.getPageCount(); if (pageNumber > pageCount) { pageNumber = pageCount; } else if (pageNumber < 1) { pageNumber = 1; } controller.navigateToPage(pageNumber); return pageNumber; } }), "refresh": new Command( function() { controller.refreshReport(true); } ), "export": new Command(function(format) { if (format) { controller.exportReport(format); } }), "print": new Command(function() { controller.printReport(); }), "pageMode": new Command(function() { controller.setPageMode( controller.getPageMode() === PageModes.SINGLE_PAGE ? PageModes.CONTINUOUS_SCROLL : PageModes.SINGLE_PAGE ); }), "togglePrintPreview": new Command(function() { controller.setViewMode( controller.getViewMode() === ViewModes.PRINT_PREVIEW ? ViewModes.INTERACTIVE : ViewModes.PRINT_PREVIEW ); }), "toggleDocumentMap": new Command(function() { controller.setDocumentMapVisible({ visible: !getDocumentMapVisible() }); }), "toggleParametersArea": new Command(function() { controller.setParametersAreaVisible({ visible: !getParametersAreaVisible() }); }), "zoom": new Command(function(scale) { controller.setScale(scale); }), "zoomIn": new Command(function() { zoom(1); }), "zoomOut": new Command(function() { zoom(-1); }), "toggleSideMenu": new Command(function() { controller.setSideMenuVisible({ visible: !getSideMenuVisible() }); }), "toggleZoomMode": new Command(function(e) { var scale = controller.getScale(); var scaleMode = controller.getScaleMode(); controller.setScale(scaleTransitionMap[scaleMode].scale || scale); controller.setScaleMode(scaleTransitionMap[scaleMode].scaleMode); }), "toggleSearchDialog": new Command(function() { controller.setSearchDialogVisible({ visible: !getSearchDialogVisible() }); }), "toggleSendEmailDialog": new Command(function() { controller.setSendEmailDialogVisible({ visible: !getSendEmailDialogVisible() }); }) }; function zoom(step) { controller.setScale(getZoomScale(controller.getScale(), step)); } function getZoomScale(scale, steps) { var pos = -1; var length = scaleValues.length; for (var i = 0; i < length; i++) { var value = scaleValues[i]; if (scale < value) { pos = i - 0.5; break; } if (scale === value) { pos = i; break; } } pos = pos + steps; if (steps >= 0) { pos = Math.round(pos - 0.49); } else { pos = Math.round(pos + 0.49); } if (pos < 0) { pos = 0; } else if (pos > length - 1) { pos = length - 1; } return scaleValues[pos]; } } export { CommandSet };