12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI
- * (C) Copyright IBM Corp. 2016, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery'], function ($) {
- 'use strict';
- var _singletonInstance = null;
- var MenuActionHelper = function MenuActionHelper() {};
- /**
- * options.dashboardApi {object} - the dashboard API
- * options.id {string} - the ID of the data source
- * options.type {string} - the Type of the data source
- * options.event {obj} - The mouse event that triggered the menu to be opened
- * options.menuId {string} - The menu id to open
- **/
- MenuActionHelper.prototype.getActionPayload = function (options) {
- // We only do a CM query for dataSet2.
- // TODO the SourceModel is already doing a CM query, should just you its information
- if (!options || options.type === 'dataSet2' && !options.id || !options.event) {
- return Promise.resolve(true);
- }
- return this._getCMInfo(options).then(function (cmProperties) {
- var position = {};
- var evt = options.event;
- if (evt.pageX === undefined || evt.gesture && (evt.gesture.center === undefined || evt.gesture.center.pageX === undefined)) {
- position = $(evt.target).offset();
- } else {
- position.left = evt.pageX || evt.gesture.center.pageX;
- position.top = evt.pageY || evt.gesture.center.pageY;
- }
- var actionPayload = {
- position: {
- pageX: position.left,
- pageY: position.top
- },
- menuId: options.menuId,
- activeObject: {
- aSelectedContext: cmProperties
- }
- };
- return actionPayload;
- });
- };
- MenuActionHelper.prototype._getCMInfo = function (options) {
- if (options.type === 'dataSet2') {
- return options.dashboardApi.getGlassSvc('.Content').then(function (contentSvc) {
- return contentSvc.getBaseObjectsURL() + '/' + options.id;
- }).then(function (url) {
- return options.dashboardApi.getGlassCoreSvc('.Ajax').ajax({
- url: url,
- type: 'GET',
- 'headers': {
- 'Content-Type': 'application/vnd.ibm.bi.platform.execution+json; charset=UTF-8',
- 'Accept': 'application/json'
- },
- 'datatype': 'json',
- 'data': {
- 'fields': 'permissions,defaultName'
- }
- });
- }).then(function (result) {
- var response = result.data;
- if (response && response.data) {
- return response.data;
- } else {
- throw response;
- }
- });
- } else {
- return Promise.resolve({});
- }
- };
- var _static = {
- getInstance: function getInstance() {
- if (!_singletonInstance) {
- _singletonInstance = new MenuActionHelper();
- }
- return _singletonInstance;
- }
- };
- return _static.getInstance();
- });
- //# sourceMappingURL=MenuActionHelper.js.map
|