'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. 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../WidgetTitleTruncateAPI'], function (APIFactory, WidgetTitleTruncateAPI) { 'use strict'; var defaultValues = { truncateTitle: false }; var WidgetTitleTruncate = function () { function WidgetTitleTruncate(options) { _classCallCheck(this, WidgetTitleTruncate); this._content = options.content; this._internal = options.features && options.features['Dashboard.internal']; this._dashboard = options.dashboardAPI; this._getProperty = this._getModelProp.bind(this); this._state = { initialWidgetRenderDone: false, truncateOn: false }; } WidgetTitleTruncate.prototype._isSmartTitleFeatureEnabled = function _isSmartTitleFeatureEnabled() { return this._dashboard ? !this._dashboard.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'SmartTitle', 'disabled') : false; }; WidgetTitleTruncate.prototype.getExtensionHooks = function getExtensionHooks() { if (!this._isSmartTitleFeatureEnabled()) { return undefined; } return { onInit: this._handleTitleTruncation.bind(this), onSetText: this._onSetText.bind(this), onEditStart: this._onEditStart.bind(this), onEditUpdate: this._onEditUpdate.bind(this), onEditEnd: this._onEditEnd.bind(this), //onModifyTextColor: this._onModifyTextColor.bind(this), isTextWrapOn: this._isTextWrapOn.bind(this), onTextWrapChanged: this._onTextWrapChanged.bind(this) }; }; WidgetTitleTruncate.prototype.setUpdateModelContent = function setUpdateModelContent(setter) { this._updateModelContent = setter; }; WidgetTitleTruncate.prototype.setTitleHighlighter = function setTitleHighlighter(setter) { this.highlightTitle = setter; }; WidgetTitleTruncate.prototype.highlightTitle = function highlightTitle() { if (this.highlightTitle) { this.highlightTitle(); } }; WidgetTitleTruncate.prototype.getState = function getState() { return { truncateTitleOn: this._content.getPropertyValue('truncateTitle'), truncateTemporarilyOff: this._truncateTemporarilyOff }; }; WidgetTitleTruncate.prototype.getAPI = function getAPI() { return APIFactory.createAPI(this, [WidgetTitleTruncateAPI]); }; WidgetTitleTruncate.prototype._showTitle = function _showTitle() { var titleMode = this._getProperty('titleMode'); if (titleMode !== 'noTitle') { return true; } return false; }; WidgetTitleTruncate.prototype._isTextWrapOn = function _isTextWrapOn() { if (!this._isSmartTitleFeatureEnabled()) { return false; } var truncateTitle = this._getProperty('truncateTitle'); return truncateTitle === true ? false : true; }; WidgetTitleTruncate.prototype._onTextWrapChanged = function _onTextWrapChanged(textWrapFlag) { this._setProperty('truncateTitle', !textWrapFlag); }; WidgetTitleTruncate.prototype._handleTitleTruncation = function _handleTitleTruncation(textEditor) { var _this = this; if (this._content) { this._onWidgetRenderDone(); var showTitle = this._showTitle(); var truncateTitle = this._getProperty('truncateTitle'); if (showTitle && truncateTitle) { this._setTruncate(textEditor, true, true); } this._content.on('change:property:truncateTitle', function (event) { var showTitle = _this._showTitle(); if (event.info.value === true) { if (showTitle && !_this._isTruncateStateSet()) { _this._setTruncate(textEditor, true); } } else { if (showTitle && _this._isTruncateStateSet()) { _this._setTruncate(textEditor, false); } } }); } }; WidgetTitleTruncate.prototype._onWidgetRenderDone = function _onWidgetRenderDone() { var _this2 = this; var stateAPI = this._content.getFeature('state'); if (!this._state.initialWidgetRenderDone) { return stateAPI.whenStatusChanges('rendered').then(function () { _this2._getProperty = _this2._getContentProperty.bind(_this2); _this2._state.initialWidgetRenderDone = true; }); } return Promise.resolve(true); }; WidgetTitleTruncate.prototype._getContentProperty = function _getContentProperty(name) { return this._content.getPropertyValue(name); }; WidgetTitleTruncate.prototype._getModelProp = function _getModelProp(name) { var boardModel = this._internal.getBoardModel(); var id = this._content.getId(); var widgetModel = boardModel.getWidgetModel(id); var value = widgetModel.get(name); return value !== undefined ? value : defaultValues[name]; }; WidgetTitleTruncate.prototype._setProperty = function _setProperty(name, value) { var _this3 = this; if (this._state.initialWidgetRenderDone) { this._content.setPropertyValue(name, value); } else { var stateAPI = this._content.getFeature('state'); stateAPI.whenStatusChanges('rendered').then(function () { _this3._content.setPropertyValue(name, value); }); } }; WidgetTitleTruncate.prototype._isTruncateStateSet = function _isTruncateStateSet() { return this._state.truncateOn; }; WidgetTitleTruncate.prototype._setTruncateState = function _setTruncateState(value) { this._state.truncateOn = value; }; WidgetTitleTruncate.prototype._setTruncate = function _setTruncate(textEditor, truncateFlag) { var forcePropertySet = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; //used only when setting during initial widget rendering if (truncateFlag) { this._setTruncateState(true); textEditor.setTruncateOn(); forcePropertySet && this._setProperty('truncateTitle', true); //ensure that its on on init } else if (truncateFlag === false) { this._setTruncateState(false); textEditor.setTruncateOff(); this._updateModelContent && this._updateModelContent({}); //make sure titleHtml is in synch } }; WidgetTitleTruncate.prototype._onSetText = function _onSetText(textEditor) { if (this._content) { var showTitle = this._showTitle(); var truncateTitle = this._getProperty('truncateTitle'); if (showTitle && truncateTitle) { this._setTruncate(textEditor, true, true); } } }; WidgetTitleTruncate.prototype._onEditStart = function _onEditStart(textEditor) { //disable truncate when starting editing this._disableTruncateOnManualEditStart(textEditor); }; WidgetTitleTruncate.prototype._onEditUpdate = function _onEditUpdate(currentTitle, currentTitleHtml, newTitle, transactionid) { //also disable smart title when editing manually if (currentTitle !== newTitle) { this._disableSmartTitleOnManualEdit(transactionid); } //title is the same, if partial formatting done, disable smart title var formattedPortionKey = newTitle + ''; var currentTitleHtml_ = currentTitleHtml.replace('', ''); currentTitleHtml_ = currentTitleHtml_.replace('', ''); currentTitleHtml_ = currentTitleHtml_.replace('', ''); if (currentTitleHtml_.indexOf(formattedPortionKey) === -1) { this._disableSmartTitleOnManualEdit(transactionid); } }; WidgetTitleTruncate.prototype._onEditEnd = function _onEditEnd(textEditor) { //restore truncate when stopped editing this._restoreTruncateAfterManualEdit(textEditor); }; WidgetTitleTruncate.prototype._disableTruncateOnManualEditStart = function _disableTruncateOnManualEditStart(textEditor) { if (this._content && !this._truncateTemporarilyOff) { var showTitle = this._showTitle(); var truncateTitle = this._content.getPropertyValue('truncateTitle'); if (showTitle) { if (truncateTitle) { this._setTruncate(textEditor, false); this._truncateTemporarilyOff = true; } } } }; WidgetTitleTruncate.prototype._disableSmartTitleOnManualEdit = function _disableSmartTitleOnManualEdit(transactionid) { if (this._content) { var titleMode = this._content.getPropertyValue('titleMode'); if (titleMode && titleMode === 'smartTitle') { this._content.setPropertyValue('titleMode', 'customTitle', { undoRedoTransactionId: transactionid }); } } }; WidgetTitleTruncate.prototype._restoreTruncateAfterManualEdit = function _restoreTruncateAfterManualEdit(textEditor) { if (this._content && this._truncateTemporarilyOff) { var showTitle = this._showTitle(); var truncateTitle = this._content.getPropertyValue('truncateTitle'); if (showTitle) { if (truncateTitle) { this._setTruncate(textEditor, true); this._truncateTemporarilyOff = false; } } } }; // _onModifyTextColor(textEditor, addedClass, removedClass) { // textEditor.updateCssOnParagraphs(addedClass, removedClass); // } return WidgetTitleTruncate; }(); return WidgetTitleTruncate; }); //# sourceMappingURL=WidgetTitleTruncate.js.map