EditTitleAction.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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(['../../../../app/nls/StringResources', '../../../../dashboard/util/ContentRegistryUtil', '../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (stringResources, ContentRegistryUtil, Utils, APIFactory, ContentActionsProviderAPI) {
  9. var EditTitleAction = function () {
  10. function EditTitleAction(_ref) {
  11. var features = _ref.features;
  12. _classCallCheck(this, EditTitleAction);
  13. if (features) {
  14. this.dashboard = features.API;
  15. features.ContentActions.registerProvider('editTitle', this.getAPI());
  16. this._icons = features.Icons;
  17. }
  18. }
  19. EditTitleAction.prototype.getAPI = function getAPI() {
  20. if (!this._api) {
  21. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  22. }
  23. return this._api;
  24. };
  25. EditTitleAction.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
  26. return [{
  27. name: 'post:dashboard.initialize',
  28. action: this.postDashboardInitialize.bind(this)
  29. }];
  30. };
  31. EditTitleAction.prototype.postDashboardInitialize = function postDashboardInitialize() {
  32. this.controller = this.dashboard.getFeature('InteractionController.internal');
  33. return Promise.resolve();
  34. };
  35. EditTitleAction.prototype.destroy = function destroy() {
  36. this.dashboard = null;
  37. this.controller = null;
  38. };
  39. EditTitleAction.prototype.getNodes = function getNodes(idList) {
  40. return Utils.getNodes(this.controller, idList);
  41. };
  42. EditTitleAction.prototype.isEnabled = function isEnabled(idList) {
  43. // Make sure edit title action is supported for the widget
  44. if (idList.length === 1) {
  45. this.content = this.dashboard.getCanvas().getContent(idList[0]);
  46. var capabilitiesFeature = ContentRegistryUtil.getCapabilities(this.content);
  47. var supportsTitle = void 0;
  48. if (capabilitiesFeature) {
  49. supportsTitle = capabilitiesFeature.getCapabilities().title;
  50. } else {
  51. var node = this.getNodes(idList)[0];
  52. supportsTitle = node._layout.supportsTitle;
  53. }
  54. var authoringMode = this.dashboard.getMode() === this.dashboard.MODES.EDIT;
  55. var _ref2 = this.dashboard.getAppConfig('interactions') || {},
  56. editTitle = _ref2.editTitle;
  57. var canEditTitle = editTitle === undefined || editTitle === true || editTitle === 'true';
  58. var state = this.content && this.content.getFeature('state');
  59. var hasError = Boolean(state && !!state.getError());
  60. return supportsTitle && canEditTitle && authoringMode && !hasError;
  61. }
  62. return false;
  63. };
  64. EditTitleAction.prototype.getContentActionList = function getContentActionList(idList) {
  65. if (this.isEnabled(idList)) {
  66. return [{
  67. name: 'editTitle',
  68. label: stringResources.get('toolbarActionEditTitle'),
  69. icon: this._icons.getIcon('text-creation').id,
  70. type: 'Button',
  71. actions: {
  72. apply: this.editTitle.bind(this, idList)
  73. }
  74. }];
  75. }
  76. return [];
  77. };
  78. /**
  79. * Edit the widget's title
  80. * @param {String[]} idList Array of model id list.
  81. */
  82. EditTitleAction.prototype.editTitle = function editTitle(idList) {
  83. // Setting to false first to force focus in case the title is already shown
  84. if (this.dashboard) {
  85. var featureChecker = this.dashboard.getGlassCoreSvc('.FeatureChecker');
  86. if (featureChecker) {
  87. var isSmartTitleEnabled = !featureChecker.checkValue('dashboard', 'SmartTitle', 'disabled');
  88. var content = this.dashboard.getCanvas().getContent(idList[0]);
  89. if (!isSmartTitleEnabled) {
  90. content.setPropertyValue('showTitle', false);
  91. content.setPropertyValue('showTitle', true);
  92. } else {
  93. var titleMode = content.getPropertyValue('titleMode');
  94. if (titleMode === 'noTitle') {
  95. content.setPropertyValue('titleMode', 'customTitle');
  96. } else {
  97. var titleFeature = content.getFeature('WidgetTitleTruncate');
  98. if (titleFeature) {
  99. titleFeature.highlightTitle();
  100. }
  101. }
  102. }
  103. }
  104. }
  105. };
  106. /**
  107. * wrap the widget's title
  108. * @param {String[]} idList Array of model id list.
  109. */
  110. EditTitleAction.prototype.wrapTitle = function wrapTitle(idList) {
  111. // Setting to false first to force focus in case the title is already shown
  112. var value = this.dashboard.getCanvas().getContent(idList[0]).getPropertyValue('truncateTitle');
  113. this.dashboard.getCanvas().getContent(idList[0]).setPropertyValue('truncateTitle', !value);
  114. this.dashboard.getCanvas().getContent(idList[0]).setPropertyValue('titleMode', 'customTitle');
  115. };
  116. return EditTitleAction;
  117. }();
  118. return EditTitleAction;
  119. });
  120. //# sourceMappingURL=EditTitleAction.js.map