DisconnectEventGroupAction.js 3.6 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. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2020
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['./EventGroupActions', '../../../../app/nls/StringResources', 'underscore'], function (EventGroupActions, stringResources, _) {
  11. var DisconnectEventGroupAction = function (_EventGroupActions) {
  12. _inherits(DisconnectEventGroupAction, _EventGroupActions);
  13. function DisconnectEventGroupAction(_ref) {
  14. var features = _ref.features;
  15. _classCallCheck(this, DisconnectEventGroupAction);
  16. var _this = _possibleConstructorReturn(this, _EventGroupActions.call(this, { features: features }));
  17. if (features) {
  18. features.ContentActions.registerProvider('disconnectFilterGroup', _this.getAPI());
  19. _this._icons = features.Icons;
  20. }
  21. return _this;
  22. }
  23. DisconnectEventGroupAction.prototype.getContentActionList = function getContentActionList(idList) {
  24. if (this._isAvailable(idList)) {
  25. return [{
  26. name: 'disconnectFilterGroup',
  27. label: stringResources.get('toolbarActionDisconnectFilterGroup'),
  28. icon: this._icons.getIcon('unlink').id,
  29. type: 'Button',
  30. order: 1,
  31. actions: {
  32. apply: this.execute.bind(this, idList)
  33. },
  34. disabled: this.isDisabled.bind(this, idList),
  35. update: true
  36. }];
  37. } else {
  38. return [];
  39. }
  40. };
  41. DisconnectEventGroupAction.prototype.execute = function execute(idList) {
  42. this.eventGroups.removeFromGroup(idList, _.uniqueId('_disconnectFromGroup_'));
  43. };
  44. DisconnectEventGroupAction.prototype.isDisabled = function isDisabled(idList) {
  45. var _this2 = this;
  46. if (this._isStaticWidget(idList)) {
  47. return true;
  48. }
  49. var groups = this.eventGroups.getGroupIdsOnPage(this._getPageId(idList));
  50. if (!(groups.length > 0)) {
  51. // disable if no groups on page
  52. return true;
  53. }
  54. var count = this._getCountGroupsAffected(idList);
  55. //if the number of groups remaining after disconnecting will be greater than 5, it should be disabled
  56. if (this.getNumberOfGroups(idList) + idList.length - count > 5) {
  57. return true;
  58. }
  59. //also if the selection contains only groups that have a single widget, it should be disabled
  60. var selectedGroupsWithMoreThanOneWidget = _.filter(idList, function (id) {
  61. var groupId = _this2.eventGroups.getGroupId(id);
  62. return _this2.eventGroups.getContentIdList(groupId).length > 1;
  63. });
  64. if (selectedGroupsWithMoreThanOneWidget.length === 0) {
  65. return true;
  66. }
  67. return false;
  68. };
  69. return DisconnectEventGroupAction;
  70. }(EventGroupActions);
  71. return DisconnectEventGroupAction;
  72. });
  73. //# sourceMappingURL=DisconnectEventGroupAction.js.map