123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- '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
|