'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ 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) { var EditTitleAction = function () { function EditTitleAction(_ref) { var features = _ref.features; _classCallCheck(this, EditTitleAction); if (features) { this.dashboard = features.API; features.ContentActions.registerProvider('editTitle', this.getAPI()); this._icons = features.Icons; } } EditTitleAction.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]); } return this._api; }; EditTitleAction.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() { return [{ name: 'post:dashboard.initialize', action: this.postDashboardInitialize.bind(this) }]; }; EditTitleAction.prototype.postDashboardInitialize = function postDashboardInitialize() { this.controller = this.dashboard.getFeature('InteractionController.internal'); return Promise.resolve(); }; EditTitleAction.prototype.destroy = function destroy() { this.dashboard = null; this.controller = null; }; EditTitleAction.prototype.getNodes = function getNodes(idList) { return Utils.getNodes(this.controller, idList); }; EditTitleAction.prototype.isEnabled = function isEnabled(idList) { // Make sure edit title action is supported for the widget if (idList.length === 1) { this.content = this.dashboard.getCanvas().getContent(idList[0]); var capabilitiesFeature = ContentRegistryUtil.getCapabilities(this.content); var supportsTitle = void 0; if (capabilitiesFeature) { supportsTitle = capabilitiesFeature.getCapabilities().title; } else { var node = this.getNodes(idList)[0]; supportsTitle = node._layout.supportsTitle; } var authoringMode = this.dashboard.getMode() === this.dashboard.MODES.EDIT; var _ref2 = this.dashboard.getAppConfig('interactions') || {}, editTitle = _ref2.editTitle; var canEditTitle = editTitle === undefined || editTitle === true || editTitle === 'true'; var state = this.content && this.content.getFeature('state'); var hasError = Boolean(state && !!state.getError()); return supportsTitle && canEditTitle && authoringMode && !hasError; } return false; }; EditTitleAction.prototype.getContentActionList = function getContentActionList(idList) { if (this.isEnabled(idList)) { return [{ name: 'editTitle', label: stringResources.get('toolbarActionEditTitle'), icon: this._icons.getIcon('text-creation').id, type: 'Button', actions: { apply: this.editTitle.bind(this, idList) } }]; } return []; }; /** * Edit the widget's title * @param {String[]} idList Array of model id list. */ EditTitleAction.prototype.editTitle = function editTitle(idList) { // Setting to false first to force focus in case the title is already shown if (this.dashboard) { var featureChecker = this.dashboard.getGlassCoreSvc('.FeatureChecker'); if (featureChecker) { var isSmartTitleEnabled = !featureChecker.checkValue('dashboard', 'SmartTitle', 'disabled'); var content = this.dashboard.getCanvas().getContent(idList[0]); if (!isSmartTitleEnabled) { content.setPropertyValue('showTitle', false); content.setPropertyValue('showTitle', true); } else { var titleMode = content.getPropertyValue('titleMode'); if (titleMode === 'noTitle') { content.setPropertyValue('titleMode', 'customTitle'); } else { var titleFeature = content.getFeature('WidgetTitleTruncate'); if (titleFeature) { titleFeature.highlightTitle(); } } } } } }; /** * wrap the widget's title * @param {String[]} idList Array of model id list. */ EditTitleAction.prototype.wrapTitle = function wrapTitle(idList) { // Setting to false first to force focus in case the title is already shown var value = this.dashboard.getCanvas().getContent(idList[0]).getPropertyValue('truncateTitle'); this.dashboard.getCanvas().getContent(idList[0]).setPropertyValue('truncateTitle', !value); this.dashboard.getCanvas().getContent(idList[0]).setPropertyValue('titleMode', 'customTitle'); }; return EditTitleAction; }(); return EditTitleAction; }); //# sourceMappingURL=EditTitleAction.js.map