DashboardPrint.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: Content Explorer
  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', '../../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../AssetPrintAPI'], function ($, APIFactory, DashboardPrintAPI) {
  14. var DashboardPrint = function () {
  15. function DashboardPrint() {
  16. _classCallCheck(this, DashboardPrint);
  17. }
  18. DashboardPrint.prototype.getAPI = function getAPI() {
  19. return APIFactory.createAPI(this, [DashboardPrintAPI]);
  20. };
  21. DashboardPrint.prototype.showContentsForPrint = function showContentsForPrint(content) {
  22. var _this = this;
  23. this.blocker = $('<div>', {
  24. 'class': 'printBlocker'
  25. });
  26. var pageElement = content.pageElement;
  27. $(pageElement).append(this.blocker);
  28. $(pageElement).find('.tabPageHolder').css('display', 'block');
  29. var isTab = content.layoutType === 'tab';
  30. var holdDiv = $(pageElement).find('.tabPageHolder');
  31. if (isTab) {
  32. this.originalParentMap = {};
  33. }
  34. $.each(content.modelIds, function (i, modeId) {
  35. var page = $(pageElement).find('#' + modeId + '_tab');
  36. if (!page.hasClass('selected')) {
  37. page.css('display', 'inline-block');
  38. page.css('z-index', -1);
  39. }
  40. if (isTab) {
  41. _this.originalParentMap[modeId] = page.parent();
  42. holdDiv.append(page);
  43. }
  44. });
  45. return Promise.resolve();
  46. };
  47. DashboardPrint.prototype.hideContentsAfterPrint = function hideContentsAfterPrint(modelIds, pageElement) {
  48. var _this2 = this;
  49. $(pageElement).find('.tabPageHolder').css('display', '');
  50. var isTab = !!this.originalParentMap;
  51. $.each(modelIds, function (i, modeId) {
  52. var page = $(pageElement).find('#' + modeId + '_tab');
  53. if (!page.hasClass('selected')) {
  54. page.css('display', '');
  55. page.css('z-index', '');
  56. }
  57. if (isTab) {
  58. _this2.originalParentMap[modeId].append(page);
  59. }
  60. });
  61. this.originalParentMap = null;
  62. if (this.blocker) {
  63. this.blocker.remove();
  64. this.blocker = null;
  65. }
  66. return Promise.resolve();
  67. };
  68. /**
  69. * @description Get the minimum widget and height which can include all widgets on a page
  70. * @param {Element} pageElement
  71. * @returns {Object} An object which has the following structure:
  72. * {
  73. * width: 1234,
  74. * height: 4321
  75. * }
  76. */
  77. DashboardPrint.prototype.getOffScreenPageSize = function getOffScreenPageSize(pageElement) {
  78. var maxWidth = 0;
  79. var maxHeight = 0;
  80. var realDashboardSize = {};
  81. $.each($(pageElement).find('.widget'), function (i, widget) {
  82. var positionx = $(widget).position().left;
  83. var positiony = $(widget).position().top;
  84. if (positionx + $(widget).outerWidth() > maxWidth) {
  85. maxWidth = positionx + $(widget).outerWidth();
  86. }
  87. if (positiony + $(widget).outerHeight() > maxHeight) {
  88. maxHeight = positiony + $(widget).outerHeight();
  89. }
  90. }.bind(this));
  91. realDashboardSize = {
  92. 'width': maxWidth,
  93. 'height': maxHeight
  94. };
  95. return realDashboardSize;
  96. };
  97. return DashboardPrint;
  98. }();
  99. return DashboardPrint;
  100. });
  101. //# sourceMappingURL=DashboardPrint.js.map