CreateEventGroupAction.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 CreateEventGroupAction = function (_EventGroupActions) {
  12. _inherits(CreateEventGroupAction, _EventGroupActions);
  13. function CreateEventGroupAction(_ref) {
  14. var features = _ref.features;
  15. _classCallCheck(this, CreateEventGroupAction);
  16. var _this = _possibleConstructorReturn(this, _EventGroupActions.call(this, { features: features }));
  17. if (features) {
  18. features.ContentActions.registerProvider('createFilterGroup', _this.getAPI());
  19. _this._icons = features.Icons;
  20. }
  21. return _this;
  22. }
  23. CreateEventGroupAction.prototype.getContentActionList = function getContentActionList(idList) {
  24. if (this._isAvailable(idList)) {
  25. return [{
  26. name: 'createFilterGroup',
  27. label: stringResources.get('toolbarActionCreateFilterGroup'),
  28. icon: this._icons.getIcon('new-link').id,
  29. actions: {
  30. apply: this.execute.bind(this, idList)
  31. },
  32. disabled: this.isDisabled.bind(this, idList),
  33. type: 'Button',
  34. order: 3,
  35. update: true
  36. }];
  37. } else {
  38. return [];
  39. }
  40. };
  41. CreateEventGroupAction.prototype.execute = function execute(idList) {
  42. this.eventGroups.createGroup(idList, _.uniqueId('_createGroup_'));
  43. };
  44. CreateEventGroupAction.prototype.isDisabled = function isDisabled(idList) {
  45. if (this._isStaticWidget(idList)) {
  46. return true;
  47. }
  48. /*
  49. * if the selection contains only 1 distinct group and the selection contains every widget in that group,
  50. * then disable the "Create event group" button
  51. */
  52. var distinctGroupIdsInSelection = this._getDistinctGroupIdsInSelection(idList);
  53. var numberOfWidgetsInGroup = this.eventGroups.getContentIdList(distinctGroupIdsInSelection[0]).length;
  54. if (distinctGroupIdsInSelection.length === 1 && idList.length === numberOfWidgetsInGroup) {
  55. return true;
  56. }
  57. /*
  58. * Also, if more than 5 groups will result from the execution of a create group event, then disable the button.
  59. * count represents the number of groups that will be eliminated after disconnecting
  60. */
  61. var count = this._getCountGroupsAffected(idList);
  62. if (this.getNumberOfGroups(idList) - count + 1 > 5) {
  63. return true;
  64. }
  65. return false;
  66. };
  67. return CreateEventGroupAction;
  68. }(EventGroupActions);
  69. return CreateEventGroupAction;
  70. });
  71. //# sourceMappingURL=CreateEventGroupAction.js.map