123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- '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 + '</span>';
- var currentTitleHtml_ = currentTitleHtml.replace('</i>', '');
- currentTitleHtml_ = currentTitleHtml_.replace('</u>', '');
- currentTitleHtml_ = currentTitleHtml_.replace('</b>', '');
- 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
|