'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['jquery', 'underscore', '../VisView', '../../../util/DashboardFormatter', '../kpi/KpiView', '../infographic/InfographicView', '../../../DynamicFileLoader', '../../../lib/@waca/dashboard-common/dist/utils/MemUtil'], function ($, _, VisView, Formatter, KpiView, InfographicView, DynamicFileLoader, MemUtil) { 'use strict'; var SummaryProxyView = VisView.extend({ className: '', init: function init(options) { var _this = this; SummaryProxyView.inherited('init', this, arguments); this._content = options.content; this._colorsService = this.dashboardApi.getFeature('Colors'); this._visualizationAPI = this._content.getFeature('Visualization'); var proxiedOptions = _.extend({}, options, { proxiedView: true }); this._kpiView = new KpiView(proxiedOptions); this._infographicView = new InfographicView(proxiedOptions); this.updateActiveView(); ['resize', 'animate', '_renderIconView', 'removeIconView', 'getDescription', 'onVisible', 'renderIconView'].forEach(function (property) { _this._createProxyFunction(property); }); }, /** * expose this to summaryPropertyCallbacks */ getSubView: function getSubView(name) { if (name === 'kpiView') { return this._kpiView; } else if (name === 'infographicView') { return this._infographicView; } }, _createProxyFunction: function _createProxyFunction(functionName) { this[functionName] = function () { return this._activeView[functionName].apply(this._activeView, arguments); }; }, reveal: function reveal() { if (this._activeView && this._activeView.summaryReveal) { this._activeView.summaryReveal(); } }, remove: function remove() { var finalRemove = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; // todo livewidget_cleanup -- it is weird that we pass a finalRemove // It seems to be used to delayed the destruction of a vipr widget // but we could handle this in a better way this._kpiView.remove(finalRemove); this._infographicView.remove(finalRemove); if (finalRemove) { MemUtil.destroy(this); } }, /** * Loads and creates the control. Returns a promise which is resolved when the control * is created and ready to render */ whenVisControlReady: function whenVisControlReady() { var _this2 = this; //Initialize proxied view controls var controlPromises = [this._kpiView.whenVisControlReady(), this._infographicView.whenVisControlReady()]; return Promise.all(controlPromises).then(function () { if (_this2.visControl) { return _this2.visControl; } else { return DynamicFileLoader.load(['dashboard-analytics/visualizations/renderer/summary/control/SummaryControl']).then(function (modules) { var VisControl = modules[0]; _this2.visControl = new VisControl({ domNode: _this2.$el[0] }); return _this2.visControl; }); } }); }, placeAt: function placeAt(element) { this._containingElement = element; if (this._activeView) { this._activeView.placeAt(element); } }, updateActiveView: function updateActiveView() { if (this._activeView) { this._activeView.$el.detach(); } var isInfographic = this.isInfographic(true); if (isInfographic) { this._activeView = this._infographicView; } else { this._activeView = this._kpiView; } this.$el = this._activeView.$el; if (this._containingElement) { this._activeView.placeAt(this._containingElement); } }, getActiveView: function getActiveView() { return this._activeView; }, render: function render(renderInfo) { this.updateActiveView(); return this._activeView.render(renderInfo); }, isInfographic: function isInfographic() { var updateValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; if (this._isInfographic === undefined || updateValue) { var graphicData = this.content.getPropertyValue('value.graphic.content'); this._isInfographic = !!graphicData; } return this._isInfographic; }, getDecoratorAPI: function getDecoratorAPI() { if (this._activeView.getDecoratorAPI) { return this._activeView.getDecoratorAPI(); } else { return null; } } }); return SummaryProxyView; }); //# sourceMappingURL=SummaryProxyView.js.map