HideShowSummariesAction.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', 'jquery'], function (StringResources, ContentActionsProviderAPI, APIFactory, $) {
  9. var HideShowSummariesAction = function () {
  10. function HideShowSummariesAction(dashboard, dashboardState, icons) {
  11. _classCallCheck(this, HideShowSummariesAction);
  12. this._dashboard = dashboard;
  13. this._dashboardState = dashboardState;
  14. this._icons = icons;
  15. }
  16. HideShowSummariesAction.prototype.getContentActionList = function getContentActionList(idList) {
  17. var contribution = [];
  18. if (this._getSelectedContent(idList)) {
  19. var contentId = idList[0];
  20. var content = this._dashboard.getCanvas().getContent(contentId);
  21. var summaryIcon = this._icons.getIcon('dashboard-hideshowsummaries');
  22. if (this._supportAction(content)) {
  23. contribution = [{
  24. name: 'hideShowSummaries',
  25. label: this._getLabel(content),
  26. className: 'hideShowSummariesBtnToggle',
  27. icon: summaryIcon.id,
  28. actions: {
  29. apply: this.execute.bind(this, content)
  30. },
  31. type: 'Button'
  32. }];
  33. }
  34. }
  35. return contribution;
  36. };
  37. HideShowSummariesAction.prototype._supportAction = function _supportAction(content) {
  38. var isAllowed = false;
  39. var uiState = this._dashboardState.getUiState();
  40. var visualization = content.getFeature('Visualization');
  41. if (visualization && !uiState.eventGroups) {
  42. var visId = visualization.getDefinition().getId();
  43. var mappingComplete = visualization.getSlots().isMappingComplete();
  44. isAllowed = mappingComplete && (visId === 'crosstab' || visId === 'JQGrid');
  45. }
  46. return isAllowed;
  47. };
  48. HideShowSummariesAction.prototype._getLabel = function _getLabel(content) {
  49. var hideSummaries = content.getPropertyValue('hideSummaries');
  50. return hideSummaries ? StringResources.get('showSummariesLabel') : StringResources.get('hideSummariesLabel');
  51. };
  52. HideShowSummariesAction.prototype._getSelectedContent = function _getSelectedContent(idList) {
  53. return idList.length === 1;
  54. };
  55. HideShowSummariesAction.prototype.execute = function execute(content, event) {
  56. var currentValue = !content.getPropertyValue('hideSummaries');
  57. content.setPropertyValue('hideSummaries', currentValue);
  58. var $hideShowSummariesBtn = $(event.currentTarget).find('.hideShowSummariesBtnToggle').addBack();
  59. var label = this._getLabel(content);
  60. $hideShowSummariesBtn.attr('title', label);
  61. $hideShowSummariesBtn.find('svg title').text(label);
  62. };
  63. HideShowSummariesAction.prototype.getAPI = function getAPI() {
  64. if (!this._api) {
  65. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  66. }
  67. return this._api;
  68. };
  69. return HideShowSummariesAction;
  70. }();
  71. return HideShowSummariesAction;
  72. });
  73. //# sourceMappingURL=HideShowSummariesAction.js.map