'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Storytelling *| (C) Copyright IBM Corp. 2019 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['jquery', 'gemini/features/dashboard/dashboardPrint/api/AssetPrintAPI', 'gemini/lib/@waca/dashboard-common/dist/core/APIFactory'], function ($, AssetPrintAPI, APIFactory) { var StoryPrint = function () { function StoryPrint() { _classCallCheck(this, StoryPrint); this.style = {}; this.containerClass = '.tabCntr'; } /** * Creates the api to be used by the Print feature * @returns {Object} returns the api */ StoryPrint.prototype.getAPI = function getAPI() { return APIFactory.createAPI(this, [AssetPrintAPI]); }; /** * Shows all the scenes and appends/removes styles as necessary for printing * @param content.context the printing context * @param {array} content.modelIds id's of the different page contents of the asset * @param {string} content.layoutType type of the layout * @param {object} content.printPageSize the size of the pdf paper that the user chose * @param {object} content.pageElement node referring to the root page element of the current view * @returns {Promise} returns the promise of moving all the scenes to the end state */ StoryPrint.prototype.showContentsForPrint = function showContentsForPrint(content) { var _this = this; this.storyAPI = content.context.getCurrentContentView().getStoryAPI(); this.initCursorTime = this.storyAPI.getCurrentTime(); var $pageElement = $(content.pageElement); this._addBlocker($pageElement); return this.storyAPI.enterPrintMode().then(function () { var modelIds = content.modelIds; _this.$timelinePlayer = $pageElement.find('.timelinePlayer'); var $holdDiv = $pageElement.find(_this.containerClass); $holdDiv.css('display', 'block'); _this.layoutType = content.layoutType; _this.isSlideShow = _this._getStoryType(content.layoutType) === 'slideshow'; var pageSize = content.printPageSize; if (_this.isSlideShow) { _this._showContentsForSlideShow(modelIds, $pageElement, $holdDiv, pageSize); } else { _this._showContentsForGuidedJourney(modelIds, $pageElement, $holdDiv, pageSize); } _this.$timelinePlayer.hide(); }); }; /** * Hides the previously shows scenes and adds/removes the styles after printing * @param {array} modelIds id's of the different page contents of the asset * @param {object} pageElement node referring to the root page element of the current view * @returns {Promise} */ StoryPrint.prototype.hideContentsAfterPrint = function hideContentsAfterPrint(modelIds, pageElement) { var _this2 = this; var $pageElement = $(pageElement); $pageElement.find(this.containerClass).css('display', ''); $pageElement.find('.page').first().css('display', 'flex'); return this.storyAPI.leavePrintMode(this.initCursorTime).then(function () { modelIds.forEach(function (modelId) { var $page = $pageElement.find('#' + modelId + '_tab'); var style = _this2.style[modelId]; if (_this2.isSlideShow) { if (!$page.hasClass('selected')) { $page.toggleClass('hiddenScene', true); } $page[0].style.width = style.width; $page[0].style.height = style.height; $page.find('.page.pagecontainer')[0].style.width = style.childWidth; $page.find('.page.pagecontainer')[0].style.height = style.childHeight; } else { $page.css('transform-style', style.transformStyle); $page.toggleClass('step', true); $page.toggleClass('hiddenScene', false); $page.find('.sceneInfo').show(); if (_this2.layoutType === 'panAndZoom6') { $page.find('.sceneConnector').show(); $page.find('.sequenceTimeline').show(); $page.find('.sequenceSceneTitle').show(); } _this2.$startOverview.after($page); _this2.$startOverview = $page; $page.css('width', style.width); $page.css('height', style.height); $page.find('.page.pagecontainer').css('width', style.childWidth); $page.find('.page.pagecontainer').css('height', style.childHeight); } $page.css('transform', style.transform); }); _this2.$timelinePlayer.show(); }).then(this._removeBlocker.bind(this)); }; /** * Dummy function * @returns {boolean} returns false as offscreen page size not needed for stories */ StoryPrint.prototype.getOffScreenPageSize = function getOffScreenPageSize() { return false; }; /** * Determines if the story is slideshow or guided journey * @param {stirng} layoutType an array of model objects * @returns {boolean} returns true if the story is of type slideshow else false referring to guided journey */ StoryPrint.prototype._getStoryType = function _getStoryType(layoutType) { return layoutType === 'slideshow' ? 'slideshow' : 'panAndZoom'; }; /** * Shows all the scenes and appends/removes styles for slideshow stories as necessary for printing * @param {array} modelIds id's of the different page contents of the asset * @param {object} $pageElement node referring to the root page element of the current view * @param {object} $holdDiv node referring to the parent element containing all the nodes for the scenes */ StoryPrint.prototype._showContentsForSlideShow = function _showContentsForSlideShow(modelIds, $pageElement, $holdDiv, pageSize) { var _this3 = this; this.originalParentMap = {}; var conversionFactor = 0.75; var $selectedScene = $pageElement.find('.pageTabContent.selected'); var scaleFactor = $selectedScene.width() / $selectedScene.height(); //Needed for firefox as display: flex produces inconsistent behaviour with page-breaks $pageElement.find('.page').first().css('display', 'block'); modelIds.forEach(function (modelId) { var $page = $pageElement.find('#' + modelId + '_tab'); var $pageContainer = $page.find('.page.pagecontainer'); _this3.style[modelId] = { width: $page[0].style.width, height: $page[0].style.height, childWidth: $pageContainer[0].style.width, childHeight: $pageContainer[0].style.height, transform: $page[0].style.transform }; if (!$page.hasClass('selected')) { $page.css('transform', ''); $page.toggleClass('hiddenScene', false); } // Printing page size width and height in px var pdfSizeWidth = pageSize.width / conversionFactor; var pdfSizeHeight = pageSize.height / conversionFactor; var scaledWidth = pdfSizeWidth * 1.5; var scaledHeight = scaledWidth / scaleFactor; $page[0].style.width = scaledWidth + 'px'; $page[0].style.height = Math.min(scaledHeight, pdfSizeHeight) + 'px'; $pageContainer[0].style.width = scaledWidth + 'px'; $pageContainer[0].style.height = Math.min(scaledHeight, pdfSizeHeight) + 'px'; _this3.originalParentMap[modelId] = $page.parent(); $holdDiv.append($page); }); }; /** * Shows all the scenes and appends/removes styles for guided journey stories as necessary for printing * @param {array} modelIds id's of the different page contents of the asset * @param {object} $pageElement node referring to the root page element of the current view * @param {object} $holdDiv node referring to the parent element containing all the nodes for the scenes * @param {object} content current content of the story */ StoryPrint.prototype._showContentsForGuidedJourney = function _showContentsForGuidedJourney(modelIds, $pageElement, $holdDiv, pageSize) { var _this4 = this; this.$startOverview = $pageElement.find('[id^="start_overview_"]'); var converstionFactor = 0.75; // Printing page size width and height in px var pdfSizeWidth = pageSize.width / converstionFactor; var pdfSizeHeight = pageSize.height / converstionFactor; //Needed for firefox as display: flex produces inconsistent behaviour with page-breaks $pageElement.find('.page').first().css('display', 'block'); modelIds.forEach(function (modelId) { var $page = $pageElement.find('#' + modelId + '_tab'); var $pageContainer = $page.find('.page.pagecontainer'); var scaleFactor = $pageContainer.width() / $pageContainer.height(); _this4.style[modelId] = { width: $page.width(), height: $page.height(), childWidth: $pageContainer.width(), childHeight: $pageContainer.height(), transformStyle: $page.css('transform-style'), transform: $page.css('transform') }; var scaledWidth = pdfSizeWidth * 1.5; var scaledHeight = scaledWidth / scaleFactor; //making sure the height is proportionate to the width $page.width(scaledWidth); $page.height(Math.min(scaledHeight, pdfSizeHeight)); $pageContainer.width(scaledWidth); $pageContainer.height(Math.min(scaledHeight, pdfSizeHeight)); $page.find('.sceneInfo').hide(); if (_this4.layoutType === 'panAndZoom6') { $page.find('.sceneConnector').hide(); $page.find('.sequenceTimeline').hide(); $page.find('.sequenceSceneTitle').hide(); } $page.css('transform-style', ''); $page.removeClass('step'); $page.css('transform', ''); $holdDiv.append($page); }); }; /** * Adds a blocker while building the pdf to prevent user from seeing the works in the background * @param {object} $pageElement node referring to the root page element of the current view */ StoryPrint.prototype._addBlocker = function _addBlocker($pageElement) { this.blocker = $('