OpenModuleHandler.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: Modeling UI
  5. *
  6. * Copyright IBM Corp. 2017, 2018
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['bi/glass/core/Class', 'underscore'], function(BaseClass, _) {
  11. var ModuleEditHandler = BaseClass.extend({
  12. init: function() {
  13. ModuleEditHandler.inherited('init', this, arguments);
  14. },
  15. doAction: function(context) {
  16. return this._passSecurityCheck(context)
  17. ? Promise.resolve(this.onSelectItem(context))
  18. : Promise.reject();
  19. },
  20. onSelectItem: function(context) {
  21. var application = context.glassContext;
  22. if (application.currentAppView.perspective === 'ca-modeller') {
  23. // launch the glass open dialog
  24. application.getCurrentContentView().openModel();
  25. return;
  26. }
  27. application.closeAppView('ca-modeller').then(
  28. function() {
  29. // from the glass open dialog
  30. var id = context.target.activeObject.aSelectedContext[0].id;
  31. application.openAppView('ca-modeller', {
  32. content: {
  33. objRef: id,
  34. id: id
  35. }
  36. });
  37. }
  38. );
  39. },
  40. _passSecurityCheck: function(context) {
  41. var aPerm = ['read'];
  42. var selection =
  43. context &&
  44. context.target &&
  45. context.target.activeObject &&
  46. context.target.activeObject.aSelectedContext;
  47. return (
  48. selection &&
  49. selection.length &&
  50. _.intersection(selection[0].permissions, aPerm).length === aPerm.length &&
  51. context.glassContext.services.userProfile.capabilities.indexOf(
  52. 'canUseWebBasedModeling'
  53. ) >= 0
  54. );
  55. },
  56. /**
  57. * Method invoked when rendering glass Menu, ContextMenu and GlassPlugin classes to determine if the item should be displayed
  58. * @param {context} which contains the following:
  59. * <ul>
  60. * <li>glassContext</li>
  61. * <li>target: object containing info on the target: plugin and itemId</li>
  62. * <li>activeObject: object for which the menu is displayed, used for the context menu</li>
  63. * </ul>
  64. * @return true or false
  65. */
  66. isItemVisible: function(context) {
  67. return (
  68. context.target.activeObject.aSelectedContext.length === 1 &&
  69. context.target.activeObject.aSelectedContext[0].type === 'module' &&
  70. this._passSecurityCheck(context)
  71. );
  72. }
  73. });
  74. return ModuleEditHandler;
  75. });