CommonViewWrapper.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['underscore', '../lib/@waca/core-client/js/core-client/ui/core/View', '../lib/@waca/core-client/js/core-client/utils/ClassFactory', '../filters/finder/FilterModuleFinder', '../filters/FilterMetadataHelper'], function (_, View, ClassFactory, FilterModuleFinder, FilterMetadataHelper) {
  8. var Wrapper = View.extend({
  9. className: 'localFilterViewWrapper',
  10. init: function init(options) {
  11. Wrapper.inherited('init', this, arguments);
  12. this.options = options.state || options;
  13. this.logger = this.options.dashboardApi.getGlassCoreSvc('.Logger');
  14. },
  15. // Need to preload to have the Flyout sized properly.
  16. preload: function preload() {
  17. var moduleOptions = {
  18. origin: 'localFilter'
  19. };
  20. var metadata = FilterMetadataHelper.getFilterMetadataInfo(this.options.metadataColumn, this.options.slot, this.options.mapIndex);
  21. _.extend(moduleOptions, metadata);
  22. //TODO: For legacy reasons, the metadata info is needed on 'this.options' as well.
  23. //Metadata info can be access from the controller using this.metadataInfo.
  24. //When the code is cleaned up, then this line can be deleted.
  25. _.extend(this.options, metadata);
  26. var dataSources = this.options.dashboardApi.getFeature('dataSources.deprecated');
  27. moduleOptions.dataSources = dataSources;
  28. return FilterModuleFinder.getModule(moduleOptions).then(function (module) {
  29. return ClassFactory.loadModule(module);
  30. }).then(function (FilterController) {
  31. this.options.commonView = this;
  32. this.filterController = new FilterController(this.options);
  33. return this.filterController.initialize().catch(function (e) {
  34. this.logger.error(e);
  35. }.bind(this));
  36. }.bind(this));
  37. },
  38. remove: function remove() {
  39. if (!this._removing) {
  40. this._removing = true;
  41. if (this.toolbar && this.toolbar.flyout) {
  42. this.toolbar.flyout.close();
  43. }
  44. if (this.filterController) {
  45. this.filterController.remove();
  46. this.filterController = null;
  47. }
  48. Wrapper.inherited('remove', this, arguments);
  49. }
  50. },
  51. renderInFilterItemView: function renderInFilterItemView(viewModel) {
  52. if (viewModel && viewModel.viewClass) {
  53. this.$el.addClass(viewModel.viewClass);
  54. }
  55. var viewOptions = {
  56. mountNode: this.$el.get(0)
  57. };
  58. return Promise.resolve(viewOptions);
  59. },
  60. renderCallBack: function renderCallBack(toolbar) {
  61. this.setToolBar(toolbar);
  62. return Promise.resolve();
  63. },
  64. onViewClose: function onViewClose() {
  65. this.remove();
  66. },
  67. onFlyoutClose: function onFlyoutClose() {
  68. if (this.filterController && this.filterController.onClose && !this.filterController.closed) {
  69. this.filterController.onClose();
  70. }
  71. },
  72. bindFlyoutClose: function bindFlyoutClose(toolbar) {
  73. toolbar.on('flyout:hide', this.onFlyoutClose.bind(this));
  74. toolbar.on('toolbar:show', this.onFlyoutShow.bind(this));
  75. },
  76. _renderFilterInstance: function _renderFilterInstance() {
  77. if (this.filterController) {
  78. return this.filterController.render();
  79. }
  80. return Promise.resolve();
  81. },
  82. setToolBar: function setToolBar(toolbar) {
  83. this.toolbar = toolbar;
  84. this.bindFlyoutClose(toolbar);
  85. },
  86. onFlyoutShow: function onFlyoutShow() {
  87. var _this = this;
  88. return this._renderFilterInstance().then(function () {
  89. // unlike most (if not all) flyout content view our render is async.
  90. // When the flyout is dealing with focus we don't always have any content that is focusable
  91. //
  92. // Here we wait until we are rendered and take focus if we don't already have it.
  93. if (!_this.$el.find(document.activeElement).length) {
  94. _this.$el.find(':tabbable:first').focus();
  95. }
  96. });
  97. }
  98. });
  99. return Wrapper;
  100. });
  101. //# sourceMappingURL=CommonViewWrapper.js.map