'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', '../lib/@waca/core-client/js/core-client/ui/core/View', '../lib/@waca/core-client/js/core-client/utils/ClassFactory', '../filters/finder/FilterModuleFinder', '../filters/FilterMetadataHelper'], function (_, View, ClassFactory, FilterModuleFinder, FilterMetadataHelper) { var Wrapper = View.extend({ className: 'localFilterViewWrapper', init: function init(options) { Wrapper.inherited('init', this, arguments); this.options = options.state || options; this.logger = this.options.dashboardApi.getGlassCoreSvc('.Logger'); }, // Need to preload to have the Flyout sized properly. preload: function preload() { var moduleOptions = { origin: 'localFilter' }; var metadata = FilterMetadataHelper.getFilterMetadataInfo(this.options.metadataColumn, this.options.slot, this.options.mapIndex); _.extend(moduleOptions, metadata); //TODO: For legacy reasons, the metadata info is needed on 'this.options' as well. //Metadata info can be access from the controller using this.metadataInfo. //When the code is cleaned up, then this line can be deleted. _.extend(this.options, metadata); var dataSources = this.options.dashboardApi.getFeature('dataSources.deprecated'); moduleOptions.dataSources = dataSources; return FilterModuleFinder.getModule(moduleOptions).then(function (module) { return ClassFactory.loadModule(module); }).then(function (FilterController) { this.options.commonView = this; this.filterController = new FilterController(this.options); return this.filterController.initialize().catch(function (e) { this.logger.error(e); }.bind(this)); }.bind(this)); }, remove: function remove() { if (!this._removing) { this._removing = true; if (this.toolbar && this.toolbar.flyout) { this.toolbar.flyout.close(); } if (this.filterController) { this.filterController.remove(); this.filterController = null; } Wrapper.inherited('remove', this, arguments); } }, renderInFilterItemView: function renderInFilterItemView(viewModel) { if (viewModel && viewModel.viewClass) { this.$el.addClass(viewModel.viewClass); } var viewOptions = { mountNode: this.$el.get(0) }; return Promise.resolve(viewOptions); }, renderCallBack: function renderCallBack(toolbar) { this.setToolBar(toolbar); return Promise.resolve(); }, onViewClose: function onViewClose() { this.remove(); }, onFlyoutClose: function onFlyoutClose() { if (this.filterController && this.filterController.onClose && !this.filterController.closed) { this.filterController.onClose(); } }, bindFlyoutClose: function bindFlyoutClose(toolbar) { toolbar.on('flyout:hide', this.onFlyoutClose.bind(this)); toolbar.on('toolbar:show', this.onFlyoutShow.bind(this)); }, _renderFilterInstance: function _renderFilterInstance() { if (this.filterController) { return this.filterController.render(); } return Promise.resolve(); }, setToolBar: function setToolBar(toolbar) { this.toolbar = toolbar; this.bindFlyoutClose(toolbar); }, onFlyoutShow: function onFlyoutShow() { var _this = this; return this._renderFilterInstance().then(function () { // unlike most (if not all) flyout content view our render is async. // When the flyout is dealing with focus we don't always have any content that is focusable // // Here we wait until we are rendered and take focus if we don't already have it. if (!_this.$el.find(document.activeElement).length) { _this.$el.find(':tabbable:first').focus(); } }); } }); return Wrapper; }); //# sourceMappingURL=CommonViewWrapper.js.map