'use strict'; /* *+------------------------------------------------------------------------+ *| 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(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../app/util/ErrorUtils', 'underscore', '../util/InstrumentationUtil'], function (BaseClass, Utils, _, InstrumentationUtil) { var ActionHandler = BaseClass.extend({ /** * Public API to indicate if the Action should be shown */ isItemVisible: function isItemVisible(options) { return this.canExecute(options); }, /** * Public API to indicate if the Action can be executed. */ canExecute: function canExecute(options) { var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext; var isSelectionAllowed = false; if (selection.length === 1) { isSelectionAllowed = this._isSelectionValid(options, true); } return isSelectionAllowed && Utils.hasCapability(options.glassContext); }, /** * Public API to perform the action. */ doAction: function doAction(context) { return this._openDashboardView(context); }, /** * Handle the open dashboard action */ onSelectItem: function onSelectItem(context) { return this._openDashboardView(context); }, _openDashboardView: function _openDashboardView(context) { var id = context.target.activeObject.aSelectedContext[0].id; return this._getTargetPerspective(id, context).then(function (perspective) { InstrumentationUtil.track(context.glassContext, 'viewed', { objectType: perspective, object: id, type: 'Read Object' }); return context.glassContext.appController.openAppView(perspective, { id: id, content: { boardId: id, isAuthoringMode: false, // build a complete urlMap context for dashboard/story objRef: id } }); }); }, _getTargetPerspective: function _getTargetPerspective() { return Promise.resolve('dashboard'); }, _hasValidTags: function _hasValidTags(item) { var tags = item.tags || []; return tags.indexOf('dashboard') !== -1; }, _isSelectionValid: function _isSelectionValid(options, defaultValue) { var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext; if (selection) { for (var _iterator = selection, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var item = _ref; if (!this._hasValidTags(item)) { return false; } // The item must be either module or uploaded File var aType = ['exploration', 'page_asset']; if (_.intersection([item.type], aType).length < 1) { return false; } // The item must have read permission var aPerm = ['read', 'execute']; if (_.intersection(item.permissions, aPerm).length < aPerm.length) { return false; } // The item must not be disabled if (item.disabled && item.disabled.toString().toLowerCase() === 'true') { return false; } } return true; } return defaultValue || false; } }); return ActionHandler; }); //# sourceMappingURL=OpenActionHandler.js.map