DeleteAction.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/core/APIFactory', '../api/SlotActionsProviderAPI'], function (stringResources, APIFactory, SlotActionsProviderAPI) {
  9. return function () {
  10. function DeleteAction(options) {
  11. _classCallCheck(this, DeleteAction);
  12. this.dashboard = options.dashboardAPI;
  13. this.content = options.content;
  14. this.icons = options.features['Dashboard.Icons'];
  15. options.features.SlotActions.registerProvider('deleteAction', this.getAPI());
  16. }
  17. DeleteAction.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex, options) {
  18. var dataSlot = this.content.getFeature('Visualization').getSlots().getSlot(dataSlotId);
  19. var deleteIcon = this.icons.getIcon('TrashIcon');
  20. if (dataSlot && this._supportAction(dataSlot, itemIndex, options)) {
  21. return [{
  22. name: 'delete',
  23. label: stringResources.get('toolbarDeleteActionText'),
  24. icon: deleteIcon.id,
  25. type: 'Button',
  26. group: 'deleteAction',
  27. removeThenApplyAction: true,
  28. actions: {
  29. apply: this.deleteSlot.bind(this, dataSlot, itemIndex)
  30. }
  31. }];
  32. }
  33. return [];
  34. };
  35. DeleteAction.prototype._supportAction = function _supportAction(dataSlot, itemIndex, options) {
  36. if (this.dashboard.getMode() !== this.dashboard.MODES.EDIT) {
  37. return false;
  38. }
  39. // Do not support action if excludeAction is true. Currently used by crosstab.
  40. if (options && options.excludeAction) {
  41. return false;
  42. }
  43. // We do not support delete action when clicking on the legend or on viz labels.
  44. if (itemIndex === null || itemIndex === undefined) {
  45. return false;
  46. }
  47. var dataItem = dataSlot.getDataItemList()[itemIndex];
  48. if (dataItem && dataItem.getColumnId() === '_multiMeasuresSeries') {
  49. return false;
  50. }
  51. // We do not support delete action in multiple selections.
  52. // (eg. selecting multiple columns in crosstab)
  53. if (Array.isArray(itemIndex)) {
  54. return false;
  55. }
  56. return true;
  57. };
  58. DeleteAction.prototype.deleteSlot = function deleteSlot(dataSlot, itemIndex) {
  59. var dataItem = dataSlot.getDataItemList()[itemIndex];
  60. var ids = [dataItem.getId()];
  61. dataSlot.removeDataItems(ids);
  62. };
  63. DeleteAction.prototype.getAPI = function getAPI() {
  64. if (!this._api) {
  65. this._api = APIFactory.createAPI(this, [SlotActionsProviderAPI]);
  66. }
  67. return this._api;
  68. };
  69. return DeleteAction;
  70. }();
  71. });
  72. //# sourceMappingURL=DeleteAction.js.map