BaseView.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Dashboard
  6. *| (C) Copyright IBM Corp. 2015, 2020
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../../lib/@waca/baglass/js/baglass/app/ContentView', 'jquery', 'underscore', 'bspopover',
  13. //We require jquery-ui here to make sure it is loaded so that we can over its slider widget (for range filter and property sheet)
  14. // There is a conflict between the slider in jquery ui and bootstrap. No on using the jquery version, so we should be fine just by overriding it.
  15. 'jquery-ui'], function (BaseClass, $, _) {
  16. var DashboardView = BaseClass.extend({
  17. init: function init(options) {
  18. DashboardView.inherited('init', this, arguments);
  19. this.options = options || {};
  20. },
  21. getCDNUrl: function getCDNUrl() {
  22. //get the dashboard-cdn path and remove any cache busters
  23. var dashboardCdn = require.toUrl('dashboard-cdn');
  24. var cdn = '';
  25. if (dashboardCdn.indexOf('empty:') === -1) {
  26. cdn = dashboardCdn;
  27. }
  28. return cdn + 'dashboard-core/';
  29. },
  30. /**
  31. * Initialize and render the view
  32. *
  33. */
  34. render: function render() {
  35. // To be implemented by the concrete class
  36. return Promise.resolve();
  37. },
  38. /**
  39. * Destroy the view and its content
  40. */
  41. remove: function remove() {
  42. this.boardModel && this.boardModel.off();
  43. DashboardView.inherited('remove', this, arguments);
  44. },
  45. /**
  46. * Get the view title. This function should be implemented by the concrete classes
  47. */
  48. getTitle: function getTitle() {
  49. // To be implementd by the concrete classes
  50. },
  51. /**
  52. * Called by the glass when the view is deactivated (e.g. switching to a different view)
  53. */
  54. deactivate: function deactivate() {
  55. // Close all popover
  56. $('.popover').popover('hide');
  57. // Detach the current view node.
  58. // This should not be necessary, but some views do global jquery searches and we want to avoid access content from differen views
  59. this.$children = this.$el.children();
  60. this.$children.detach();
  61. // Update the state so that we can recreate the dashboard when it is activated.
  62. var content = this.getContent();
  63. if (content) {
  64. _.extend(this.options, content);
  65. }
  66. return Promise.resolve();
  67. },
  68. /**
  69. * Called by the glass just before the view is being shown
  70. */
  71. activate: function activate() {
  72. if (this.$children) {
  73. this.$el.append(this.$children);
  74. // Force resize in case the window was resize while this view is deactivated.
  75. setTimeout(function () {
  76. try {
  77. $(window).resize();
  78. } catch (e) {
  79. // eslint-disable-line no-empty
  80. }
  81. }, 100);
  82. this.$children = null;
  83. }
  84. return Promise.resolve();
  85. },
  86. clearTransientState: function clearTransientState() {
  87. this.transientState = {};
  88. },
  89. /**
  90. * Helper function to store some state associated with this view
  91. */
  92. setTransientState: function setTransientState(name, value) {
  93. if (!this.transientState) {
  94. this.transientState = {};
  95. }
  96. this.transientState[name] = value;
  97. },
  98. /**
  99. * Helper function to retrieve some state that was previously set using the setTransientState function
  100. */
  101. getTransientState: function getTransientState(name) {
  102. var value = null;
  103. if (this.transientState) {
  104. value = this.transientState[name];
  105. }
  106. return value;
  107. }
  108. });
  109. return DashboardView;
  110. });
  111. //# sourceMappingURL=BaseView.js.map