SuppressionAction.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../widgets/livewidget/nls/StringResources', 'jquery', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (stringResources, $, APIFactory, ContentActionsProviderAPI) {
  9. var PROP_ID_SUPPRESSION = 'suppression';
  10. var SuppressionAction = function () {
  11. function SuppressionAction(_ref) {
  12. var features = _ref.features;
  13. _classCallCheck(this, SuppressionAction);
  14. if (features) {
  15. this.dashboardApi = features.API;
  16. this.icons = features.Icons;
  17. features.ContentActions.registerProvider('suppressionAction', this.getAPI());
  18. }
  19. }
  20. SuppressionAction.prototype.getAPI = function getAPI() {
  21. if (!this._api) {
  22. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  23. }
  24. return this._api;
  25. };
  26. SuppressionAction.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
  27. return [{
  28. name: 'post:dashboard.initialize',
  29. action: this.postDashboardInitialize.bind(this)
  30. }];
  31. };
  32. SuppressionAction.prototype.postDashboardInitialize = function postDashboardInitialize() {
  33. return Promise.resolve();
  34. };
  35. SuppressionAction.prototype.destroy = function destroy() {
  36. this.dashboardApi = null;
  37. };
  38. SuppressionAction.prototype.isEnabled = function isEnabled(idList) {
  39. var selectedContent = this._getSelectedContent();
  40. var propertyProvider = selectedContent && selectedContent.getFeature('SuppressionPropertyProvider');
  41. return idList.length === 1 && propertyProvider && propertyProvider.getPropertyList().length && this.dashboardApi.getMode() !== this.dashboardApi.MODES.EDIT_GROUP;
  42. };
  43. SuppressionAction.prototype.getContentActionList = function getContentActionList(idList) {
  44. var iconSuppresion = this.icons.getIcon('iconSuppresion');
  45. if (this.isEnabled(idList)) {
  46. return [{
  47. name: PROP_ID_SUPPRESSION,
  48. label: this._getLabel(),
  49. icon: iconSuppresion.id,
  50. type: 'Button',
  51. actions: {
  52. apply: this._toggleSuppress.bind(this, idList)
  53. }
  54. }];
  55. }
  56. return [];
  57. };
  58. SuppressionAction.prototype._getSelectedContent = function _getSelectedContent() {
  59. return this.dashboardApi.getCanvas().getSelectedContentList()[0];
  60. };
  61. SuppressionAction.prototype._getLabel = function _getLabel(suppressValue) {
  62. suppressValue = suppressValue || this._getValue();
  63. return suppressValue === 'rowsAndColumns' ? stringResources.get('disableSuppression') : stringResources.get('enableSuppression');
  64. };
  65. SuppressionAction.prototype._getValue = function _getValue() {
  66. return this._getSelectedContent().getPropertyValue(PROP_ID_SUPPRESSION);
  67. };
  68. SuppressionAction.prototype._toggleSuppress = function _toggleSuppress(idList, evt) {
  69. var propValue = this._getValue();
  70. var toggleValue = propValue === 'rowsAndColumns' ? 'none' : 'rowsAndColumns';
  71. var $suppressBtn = $(evt.currentTarget).find('.suppressBtnToggle').addBack();
  72. var label = this._getLabel(toggleValue);
  73. $suppressBtn.attr('title', label);
  74. $suppressBtn.find('svg title').text(label);
  75. this._getSelectedContent().setPropertyValue(PROP_ID_SUPPRESSION, toggleValue);
  76. };
  77. return SuppressionAction;
  78. }();
  79. return SuppressionAction;
  80. });
  81. //# sourceMappingURL=SuppressionAction.js.map