'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: Content Explorer *| (C) Copyright IBM Corp. 2015, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['../../../app/util/ErrorUtils', 'underscore'], function (Utils, _) { var ActionHandler = function () { function ActionHandler() { _classCallCheck(this, ActionHandler); } /** * Menu item handler */ ActionHandler.prototype.onSelectItem = function onSelectItem(context) { this._openCreateView(context); }; /** * Determine when we show/hide the menu item */ ActionHandler.prototype.isItemVisible = function isItemVisible(options) { return this.canExecute(options); }; /** * Default action handler */ ActionHandler.prototype.doAction = function doAction(context) { return this._openCreateView(context); }; /** * Determine if we can execute the action based on the selection */ ActionHandler.prototype.canExecute = function canExecute(options) { var isSelectionAllowed = this._isSelectionValid(options, true); return Utils.hasCapability(options.glassContext, 'canAuthorDashboard') && isSelectionAllowed; }; ActionHandler.prototype._openCreateView = function _openCreateView(context) { var perspectiveOptions = { content: {} }; var sources = this._getSources(context); if (sources && sources.length > 0) { perspectiveOptions.content.sources = sources; } return context.glassContext.appController.openAppView('createBoard', perspectiveOptions); }; ActionHandler.prototype._getSources = function _getSources(options) { var isSelectionValid = this._isSelectionValid(options, false); var dataSourcesArray = null; if (isSelectionValid) { dataSourcesArray = []; var selections = options.target.activeObject.aSelectedContext; for (var i = 0; i < selections.length; i++) { dataSourcesArray.push({ assetId: selections[i].id, type: selections[i].type, name: selections[i].defaultName, searchPath: selections[i].searchPath, isOlapPackage: selections[i].userInterfaces && _.indexOf(selections[i].userInterfaces, 'analysisStudio') >= 0 }); } } return dataSourcesArray; }; ActionHandler.prototype._isSelectionValid = function _isSelectionValid(options, defaultValue) { var typesToOpen = ['module', 'dataSet2', 'uploadedFile', 'package', 'data_asset']; var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext; if (selection) { for (var i = 0; i < selection.length; i++) { // The item must be either module or uploaded File var aType = typesToOpen; if (_.intersection([selection[i].type], aType).length < 1) { return false; } // The item must have read permission var aPerm = ['read']; if (_.intersection(selection[i].permissions, aPerm).length < aPerm.length) { return false; } // The item must not be disabled if (selection[i].disabled && selection[i].disabled.toString().toLowerCase() === 'true') { return false; } } return true; } return defaultValue || false; }; return ActionHandler; }(); return ActionHandler; }); //# sourceMappingURL=NewDashboardActionHandler.js.map