'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: BI Dashboard *| (C) Copyright IBM Corp. 2019 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils', 'jquery'], function (UpgradeBase, WidgetUpgradeUtils, $) { var LIVE_WIDGET_TYPE = 'live'; var TEXT_WIDGET_TYPE = 'text'; var WidgetTitleAriaLabelUpgrade = function (_UpgradeBase) { _inherits(WidgetTitleAriaLabelUpgrade, _UpgradeBase); function WidgetTitleAriaLabelUpgrade() { _classCallCheck(this, WidgetTitleAriaLabelUpgrade); var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this)); _this.VERSION = 1402; return _this; } /** * Perform upgrade for the aria label by removing the old one so that the new * label will not be duplicated by the new code. * This is needed to solve the issue of titles getting duplicate text when * being pinned in the dashboard. * * * @param {object} spec - The widget spec that the upgrade is performed on * * @return {Promise} Promise to be resolved with upgrade performed. */ WidgetTitleAriaLabelUpgrade.prototype.up = function up(spec) { if (!spec) { return Promise.resolve(spec); } if (!WidgetUpgradeUtils.specHasWidgets(spec)) { return Promise.resolve(spec); } return this._upgradeWidgets(spec); }; WidgetTitleAriaLabelUpgrade.prototype._upgradeWidgets = function _upgradeWidgets(spec) { for (var widget in spec.widgets) { var model = spec.widgets[widget]; if (model.titleHtml && model.type == LIVE_WIDGET_TYPE) { model.titleHtml = this._upgradeLiveVisualizations(model.titleHtml); model.name = this._updateTranslationTable(model.titleHtml); } else if (model.type == TEXT_WIDGET_TYPE) { model.name = this._updateTranslationTable(model.content); } } return Promise.resolve(spec); }; WidgetTitleAriaLabelUpgrade.prototype._generateTitle = function _generateTitle(html) { var $titleHtml = $(html); var title = ''; $titleHtml.find('p, li').each(function (index, el) { title = title + ' ' + el.textContent; }); return title.trim(); }; WidgetTitleAriaLabelUpgrade.prototype._updateTranslationTable = function _updateTranslationTable(table) { var new_table = JSON.parse(JSON.stringify(table)); if (table.translationTable) { for (var locale in table.translationTable) { new_table.translationTable[locale] = this._generateTitle(table.translationTable[locale]); } } else { //No translation table new_table = this._generateTitle(table); } return new_table; }; WidgetTitleAriaLabelUpgrade.prototype._removeAriaLabelNode = function _removeAriaLabelNode(html) { var $titleHtml = $(html); var $ariaLabel = $titleHtml.find('.ariaLabelNode'); $ariaLabel.remove(); return $titleHtml[0].outerHTML; }; WidgetTitleAriaLabelUpgrade.prototype._upgradeLiveVisualizations = function _upgradeLiveVisualizations(titleHtml) { if (titleHtml.translationTable) { for (var locale in titleHtml.translationTable) { titleHtml.translationTable[locale] = this._removeAriaLabelNode(titleHtml.translationTable[locale]); } } else { titleHtml = this._removeAriaLabelNode(titleHtml); } return titleHtml; }; return WidgetTitleAriaLabelUpgrade; }(UpgradeBase); return new WidgetTitleAriaLabelUpgrade(); }); //# sourceMappingURL=WidgetTitleAriaLabelUpgrade.js.map