'use strict'; /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: CA *| (C) Copyright IBM Corp. 2017 - 2020 *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', '../nls/StringResources', 'underscore'], function (BaseClass, StringResources, _) { 'use strict'; var AddSourceActionHandler = BaseClass.extend({ init: function init(options) { AddSourceActionHandler.inherited('init', this, arguments); this.dashboardApi = options.dashboardApi; }, /** * Add button event handler. Called when the add button is clicked or tapped. * This method will show an open dialog to select a source. */ execute: function execute() { var enableReportDatasource = this.dashboardApi.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'reportDatasource', 'enabled'); var typesToOpen = ['module', 'dataSet2', 'uploadedFile', 'package', 'data_asset']; if (enableReportDatasource) { typesToOpen.push('report'); } var options = { 'typesToOpen': typesToOpen, 'multiSelect': false, 'dialogTitle': StringResources.get('addDataSourceDialogTitle'), 'primaryBtnText': StringResources.get('addDataSourceDialogButtonLabel'), 'onOpenCallback': this.addDataSource.bind(this) }; this.dashboardApi.prepareGlassOptions(options); //This is present for testing purposes. if (this._openDialogInstance) { this._openDialogInstance.open(options); } else { return this.dashboardApi.getGlassSvc('.ContentDialogFactory').then(function (dialogFactory) { var openDialog = dialogFactory.createOpenDialog(options); openDialog.open(); }); } }, /** * Add the data sources based on some selections in the open dialog * * @param selectedItems - an array of CM object items * */ addDataSource: function addDataSource(selectedItems) { // There is only 1 selected data source in this function because multiSelect is set to false in onAddBtnClick var selectedItem = selectedItems[0]; var dataSource = { 'assetId': selectedItem.id, 'name': selectedItem.defaultName, 'type': selectedItem.type, 'searchPath': selectedItem.searchPath, 'isOlapPackage': selectedItem.userInterfaces && _.indexOf(selectedItem.userInterfaces, 'analysisStudio') >= 0, 'modificationTime': selectedItem.modificationTime }; var dataSourcesSvc = this.dashboardApi.getFeature('dataSources.deprecated'); var dataSourceCollection = dataSourcesSvc.getSourcesCollection(); var sourceId = dataSourceCollection.addSource(dataSource); this.dashboardApi.triggerDashboardEvent('dataSourcePanel:dataSourceAdded', { sender: sourceId }); } }); return AddSourceActionHandler; }); //# sourceMappingURL=AddSourceActionHandler.js.map