StoryPrint.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Storytelling
  7. *| (C) Copyright IBM Corp. 2019
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. define(['jquery', 'gemini/features/dashboard/dashboardPrint/api/AssetPrintAPI', 'gemini/lib/@waca/dashboard-common/dist/core/APIFactory'], function ($, AssetPrintAPI, APIFactory) {
  14. var StoryPrint = function () {
  15. function StoryPrint() {
  16. _classCallCheck(this, StoryPrint);
  17. this.style = {};
  18. this.containerClass = '.tabCntr';
  19. }
  20. /**
  21. * Creates the api to be used by the Print feature
  22. * @returns {Object} returns the api
  23. */
  24. StoryPrint.prototype.getAPI = function getAPI() {
  25. return APIFactory.createAPI(this, [AssetPrintAPI]);
  26. };
  27. /**
  28. * Shows all the scenes and appends/removes styles as necessary for printing
  29. * @param content.context the printing context
  30. * @param {array} content.modelIds id's of the different page contents of the asset
  31. * @param {string} content.layoutType type of the layout
  32. * @param {object} content.printPageSize the size of the pdf paper that the user chose
  33. * @param {object} content.pageElement node referring to the root page element of the current view
  34. * @returns {Promise} returns the promise of moving all the scenes to the end state
  35. */
  36. StoryPrint.prototype.showContentsForPrint = function showContentsForPrint(content) {
  37. var _this = this;
  38. this.storyAPI = content.context.getCurrentContentView().getStoryAPI();
  39. this.initCursorTime = this.storyAPI.getCurrentTime();
  40. var $pageElement = $(content.pageElement);
  41. this._addBlocker($pageElement);
  42. return this.storyAPI.enterPrintMode().then(function () {
  43. var modelIds = content.modelIds;
  44. _this.$timelinePlayer = $pageElement.find('.timelinePlayer');
  45. var $holdDiv = $pageElement.find(_this.containerClass);
  46. $holdDiv.css('display', 'block');
  47. _this.layoutType = content.layoutType;
  48. _this.isSlideShow = _this._getStoryType(content.layoutType) === 'slideshow';
  49. var pageSize = content.printPageSize;
  50. if (_this.isSlideShow) {
  51. _this._showContentsForSlideShow(modelIds, $pageElement, $holdDiv, pageSize);
  52. } else {
  53. _this._showContentsForGuidedJourney(modelIds, $pageElement, $holdDiv, pageSize);
  54. }
  55. _this.$timelinePlayer.hide();
  56. });
  57. };
  58. /**
  59. * Hides the previously shows scenes and adds/removes the styles after printing
  60. * @param {array} modelIds id's of the different page contents of the asset
  61. * @param {object} pageElement node referring to the root page element of the current view
  62. * @returns {Promise}
  63. */
  64. StoryPrint.prototype.hideContentsAfterPrint = function hideContentsAfterPrint(modelIds, pageElement) {
  65. var _this2 = this;
  66. var $pageElement = $(pageElement);
  67. $pageElement.find(this.containerClass).css('display', '');
  68. $pageElement.find('.page').first().css('display', 'flex');
  69. return this.storyAPI.leavePrintMode(this.initCursorTime).then(function () {
  70. modelIds.forEach(function (modelId) {
  71. var $page = $pageElement.find('#' + modelId + '_tab');
  72. var style = _this2.style[modelId];
  73. if (_this2.isSlideShow) {
  74. if (!$page.hasClass('selected')) {
  75. $page.toggleClass('hiddenScene', true);
  76. }
  77. $page[0].style.width = style.width;
  78. $page[0].style.height = style.height;
  79. $page.find('.page.pagecontainer')[0].style.width = style.childWidth;
  80. $page.find('.page.pagecontainer')[0].style.height = style.childHeight;
  81. } else {
  82. $page.css('transform-style', style.transformStyle);
  83. $page.toggleClass('step', true);
  84. $page.toggleClass('hiddenScene', false);
  85. $page.find('.sceneInfo').show();
  86. if (_this2.layoutType === 'panAndZoom6') {
  87. $page.find('.sceneConnector').show();
  88. $page.find('.sequenceTimeline').show();
  89. $page.find('.sequenceSceneTitle').show();
  90. }
  91. _this2.$startOverview.after($page);
  92. _this2.$startOverview = $page;
  93. $page.css('width', style.width);
  94. $page.css('height', style.height);
  95. $page.find('.page.pagecontainer').css('width', style.childWidth);
  96. $page.find('.page.pagecontainer').css('height', style.childHeight);
  97. }
  98. $page.css('transform', style.transform);
  99. });
  100. _this2.$timelinePlayer.show();
  101. }).then(this._removeBlocker.bind(this));
  102. };
  103. /**
  104. * Dummy function
  105. * @returns {boolean} returns false as offscreen page size not needed for stories
  106. */
  107. StoryPrint.prototype.getOffScreenPageSize = function getOffScreenPageSize() {
  108. return false;
  109. };
  110. /**
  111. * Determines if the story is slideshow or guided journey
  112. * @param {stirng} layoutType an array of model objects
  113. * @returns {boolean} returns true if the story is of type slideshow else false referring to guided journey
  114. */
  115. StoryPrint.prototype._getStoryType = function _getStoryType(layoutType) {
  116. return layoutType === 'slideshow' ? 'slideshow' : 'panAndZoom';
  117. };
  118. /**
  119. * Shows all the scenes and appends/removes styles for slideshow stories as necessary for printing
  120. * @param {array} modelIds id's of the different page contents of the asset
  121. * @param {object} $pageElement node referring to the root page element of the current view
  122. * @param {object} $holdDiv node referring to the parent element containing all the nodes for the scenes
  123. */
  124. StoryPrint.prototype._showContentsForSlideShow = function _showContentsForSlideShow(modelIds, $pageElement, $holdDiv, pageSize) {
  125. var _this3 = this;
  126. this.originalParentMap = {};
  127. var conversionFactor = 0.75;
  128. var $selectedScene = $pageElement.find('.pageTabContent.selected');
  129. var scaleFactor = $selectedScene.width() / $selectedScene.height();
  130. //Needed for firefox as display: flex produces inconsistent behaviour with page-breaks
  131. $pageElement.find('.page').first().css('display', 'block');
  132. modelIds.forEach(function (modelId) {
  133. var $page = $pageElement.find('#' + modelId + '_tab');
  134. var $pageContainer = $page.find('.page.pagecontainer');
  135. _this3.style[modelId] = {
  136. width: $page[0].style.width,
  137. height: $page[0].style.height,
  138. childWidth: $pageContainer[0].style.width,
  139. childHeight: $pageContainer[0].style.height,
  140. transform: $page[0].style.transform
  141. };
  142. if (!$page.hasClass('selected')) {
  143. $page.css('transform', '');
  144. $page.toggleClass('hiddenScene', false);
  145. }
  146. // Printing page size width and height in px
  147. var pdfSizeWidth = pageSize.width / conversionFactor;
  148. var pdfSizeHeight = pageSize.height / conversionFactor;
  149. var scaledWidth = pdfSizeWidth * 1.5;
  150. var scaledHeight = scaledWidth / scaleFactor;
  151. $page[0].style.width = scaledWidth + 'px';
  152. $page[0].style.height = Math.min(scaledHeight, pdfSizeHeight) + 'px';
  153. $pageContainer[0].style.width = scaledWidth + 'px';
  154. $pageContainer[0].style.height = Math.min(scaledHeight, pdfSizeHeight) + 'px';
  155. _this3.originalParentMap[modelId] = $page.parent();
  156. $holdDiv.append($page);
  157. });
  158. };
  159. /**
  160. * Shows all the scenes and appends/removes styles for guided journey stories as necessary for printing
  161. * @param {array} modelIds id's of the different page contents of the asset
  162. * @param {object} $pageElement node referring to the root page element of the current view
  163. * @param {object} $holdDiv node referring to the parent element containing all the nodes for the scenes
  164. * @param {object} content current content of the story
  165. */
  166. StoryPrint.prototype._showContentsForGuidedJourney = function _showContentsForGuidedJourney(modelIds, $pageElement, $holdDiv, pageSize) {
  167. var _this4 = this;
  168. this.$startOverview = $pageElement.find('[id^="start_overview_"]');
  169. var converstionFactor = 0.75;
  170. // Printing page size width and height in px
  171. var pdfSizeWidth = pageSize.width / converstionFactor;
  172. var pdfSizeHeight = pageSize.height / converstionFactor;
  173. //Needed for firefox as display: flex produces inconsistent behaviour with page-breaks
  174. $pageElement.find('.page').first().css('display', 'block');
  175. modelIds.forEach(function (modelId) {
  176. var $page = $pageElement.find('#' + modelId + '_tab');
  177. var $pageContainer = $page.find('.page.pagecontainer');
  178. var scaleFactor = $pageContainer.width() / $pageContainer.height();
  179. _this4.style[modelId] = {
  180. width: $page.width(),
  181. height: $page.height(),
  182. childWidth: $pageContainer.width(),
  183. childHeight: $pageContainer.height(),
  184. transformStyle: $page.css('transform-style'),
  185. transform: $page.css('transform')
  186. };
  187. var scaledWidth = pdfSizeWidth * 1.5;
  188. var scaledHeight = scaledWidth / scaleFactor; //making sure the height is proportionate to the width
  189. $page.width(scaledWidth);
  190. $page.height(Math.min(scaledHeight, pdfSizeHeight));
  191. $pageContainer.width(scaledWidth);
  192. $pageContainer.height(Math.min(scaledHeight, pdfSizeHeight));
  193. $page.find('.sceneInfo').hide();
  194. if (_this4.layoutType === 'panAndZoom6') {
  195. $page.find('.sceneConnector').hide();
  196. $page.find('.sequenceTimeline').hide();
  197. $page.find('.sequenceSceneTitle').hide();
  198. }
  199. $page.css('transform-style', '');
  200. $page.removeClass('step');
  201. $page.css('transform', '');
  202. $holdDiv.append($page);
  203. });
  204. };
  205. /**
  206. * Adds a blocker while building the pdf to prevent user from seeing the works in the background
  207. * @param {object} $pageElement node referring to the root page element of the current view
  208. */
  209. StoryPrint.prototype._addBlocker = function _addBlocker($pageElement) {
  210. this.blocker = $('<div>', {
  211. 'class': 'printBlocker'
  212. });
  213. $pageElement.append(this.blocker);
  214. };
  215. /**
  216. * Removes the blocker after printing to pdf is completed
  217. */
  218. StoryPrint.prototype._removeBlocker = function _removeBlocker() {
  219. this.blocker.remove();
  220. this.blocker = null;
  221. };
  222. return StoryPrint;
  223. }();
  224. return StoryPrint;
  225. });
  226. //# sourceMappingURL=StoryPrint.js.map