123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- '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 = $('<div>', {
- 'class': 'printBlocker'
- });
- $pageElement.append(this.blocker);
- };
- /**
- * Removes the blocker after printing to pdf is completed
- */
- StoryPrint.prototype._removeBlocker = function _removeBlocker() {
- this.blocker.remove();
- this.blocker = null;
- };
- return StoryPrint;
- }();
- return StoryPrint;
- });
- //# sourceMappingURL=StoryPrint.js.map
|