MenuActionHelper.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI
  5. * (C) Copyright IBM Corp. 2016, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['jquery'], function ($) {
  9. 'use strict';
  10. var _singletonInstance = null;
  11. var MenuActionHelper = function MenuActionHelper() {};
  12. /**
  13. * options.dashboardApi {object} - the dashboard API
  14. * options.id {string} - the ID of the data source
  15. * options.type {string} - the Type of the data source
  16. * options.event {obj} - The mouse event that triggered the menu to be opened
  17. * options.menuId {string} - The menu id to open
  18. **/
  19. MenuActionHelper.prototype.getActionPayload = function (options) {
  20. // We only do a CM query for dataSet2.
  21. // TODO the SourceModel is already doing a CM query, should just you its information
  22. if (!options || options.type === 'dataSet2' && !options.id || !options.event) {
  23. return Promise.resolve(true);
  24. }
  25. return this._getCMInfo(options).then(function (cmProperties) {
  26. var position = {};
  27. var evt = options.event;
  28. if (evt.pageX === undefined || evt.gesture && (evt.gesture.center === undefined || evt.gesture.center.pageX === undefined)) {
  29. position = $(evt.target).offset();
  30. } else {
  31. position.left = evt.pageX || evt.gesture.center.pageX;
  32. position.top = evt.pageY || evt.gesture.center.pageY;
  33. }
  34. var actionPayload = {
  35. position: {
  36. pageX: position.left,
  37. pageY: position.top
  38. },
  39. menuId: options.menuId,
  40. activeObject: {
  41. aSelectedContext: cmProperties
  42. }
  43. };
  44. return actionPayload;
  45. });
  46. };
  47. MenuActionHelper.prototype._getCMInfo = function (options) {
  48. if (options.type === 'dataSet2') {
  49. return options.dashboardApi.getGlassSvc('.Content').then(function (contentSvc) {
  50. return contentSvc.getBaseObjectsURL() + '/' + options.id;
  51. }).then(function (url) {
  52. return options.dashboardApi.getGlassCoreSvc('.Ajax').ajax({
  53. url: url,
  54. type: 'GET',
  55. 'headers': {
  56. 'Content-Type': 'application/vnd.ibm.bi.platform.execution+json; charset=UTF-8',
  57. 'Accept': 'application/json'
  58. },
  59. 'datatype': 'json',
  60. 'data': {
  61. 'fields': 'permissions,defaultName'
  62. }
  63. });
  64. }).then(function (result) {
  65. var response = result.data;
  66. if (response && response.data) {
  67. return response.data;
  68. } else {
  69. throw response;
  70. }
  71. });
  72. } else {
  73. return Promise.resolve({});
  74. }
  75. };
  76. var _static = {
  77. getInstance: function getInstance() {
  78. if (!_singletonInstance) {
  79. _singletonInstance = new MenuActionHelper();
  80. }
  81. return _singletonInstance;
  82. }
  83. };
  84. return _static.getInstance();
  85. });
  86. //# sourceMappingURL=MenuActionHelper.js.map