SubscriptionManagementContextMenu.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. "use strict";
  2. /*
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: ADMIN
  5. * (C) Copyright IBM Corp. 2015, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['bi/glass/core/Class', 'bi/admin/nls/StringResource', 'bi/schedule/service/service'], function (Class, StringResource, shareService) {
  10. 'use strict'; //NOSONAR: Meant to be strict
  11. var ContextMenuButtonView = Class.extend({
  12. shareService: shareService,
  13. onSelectItem: function onSelectItem(context) {
  14. var options = {
  15. context: context,
  16. launchPoint: context.target.plugin.activeObject.currentTarget
  17. };
  18. var idTokens = context.target.itemId.split('.');
  19. var key = idTokens[idTokens.length - 1];
  20. if (key === "update") {
  21. this._updateSubscriptionMenuItem(options);
  22. } else if (key === "versions") {
  23. this._viewVersionsOfSubscriptionMenuItem(options);
  24. } else if (key === "delete") {
  25. this._deleteSubscriptionMenuItem(options);
  26. }
  27. },
  28. isItemVisible: function isItemVisible(context) {
  29. var idTokens = context.target.itemId.split('.');
  30. var key = idTokens[idTokens.length - 1];
  31. return key === "update" || key === "versions" || key === "delete";
  32. },
  33. _showSubscriptionPane: function _showSubscriptionPane(glassContext, descriptor, launchPoint, callback) {
  34. var content = {
  35. 'module': 'bi/schedule/views/SubscriptionView',
  36. 'glassContext': glassContext,
  37. 'descriptor': descriptor
  38. };
  39. if (callback !== undefined) {
  40. content.callback = callback;
  41. }
  42. glassContext.appController.showSlideOut({
  43. 'position': 'right',
  44. 'content': content,
  45. 'width': "400px",
  46. 'enableTabLooping': true,
  47. 'label': StringResource.get('subscription_header_region'),
  48. 'launchPoint': launchPoint
  49. });
  50. },
  51. _updateSubscriptionMenuItem: function _updateSubscriptionMenuItem(options) {
  52. var subscriptionId = options.context.target.activeObject.subscriptionId;
  53. var updateCallback = options.context.target.activeObject.updateCallback;
  54. this.shareService.getSubscriptionDetails(subscriptionId, options.context.glassContext).then(function (data) {
  55. this._showSubscriptionPane(options.context.glassContext, data, options.launchPoint, {
  56. onUpdate: updateCallback
  57. });
  58. }.bind(this));
  59. },
  60. _showVersionsPane: function _showVersionsPane(glassContext, properties, launchPoint) {
  61. var content = {
  62. 'module': 'bi/content_apps/VersionsView',
  63. 'glassContext': glassContext,
  64. 'objectInformation': properties.data[0]
  65. };
  66. glassContext.appController.showSlideOut({
  67. 'position': 'right',
  68. 'content': content,
  69. 'width': '350px',
  70. 'enableTabLooping': true,
  71. 'label': StringResource.get('schedule_subscription_version_aria_label'),
  72. 'launchPoint': launchPoint
  73. });
  74. },
  75. _viewVersionsOfSubscriptionMenuItem: function _viewVersionsOfSubscriptionMenuItem(options) {
  76. var subscriptionId = options.context.target.activeObject.subscriptionId;
  77. this.shareService.getObjectProperties(subscriptionId, options.context.glassContext).then(function (properties) {
  78. this._showVersionsPane(options.context.glassContext, properties, options.launchPoint);
  79. }.bind(this));
  80. },
  81. _deleteSubscriptionMenuItem: function _deleteSubscriptionMenuItem(options) {
  82. var subscriptionId = options.context.target.activeObject.subscriptionId;
  83. var deleteCallbacks = options.context.target.activeObject.deleteCallbacks;
  84. var $subscriptionRow = $(options.context.target.activeObject.currentTarget).closest('tr');
  85. var deleteOptions = {
  86. subscriptionId: subscriptionId,
  87. pending: true
  88. };
  89. if (options.context.glassContext.services.userProfile.preferences.accessibilityFeatures) {
  90. options.context.glassContext.appController.showMessage(StringResource.get('delete_subscription_confirm_message'), StringResource.get('delete_confirm'), 'info', ['ok', 'cancel'], undefined, function (evt) {
  91. if (evt.btn === 'ok') {
  92. deleteCallbacks.hideRow($subscriptionRow).done(function () {
  93. deleteCallbacks.complete(deleteOptions);
  94. }); //set focus to "Enabled" table header
  95. $("table.subscriptions_list_table thead tr th").eq(0).focus();
  96. } else {
  97. //set the focus back to the chevron that was clicked
  98. $(options.launchPoint).focus();
  99. }
  100. }.bind(this));
  101. } else {
  102. deleteCallbacks.hideRow($subscriptionRow); //set focus to "Enabled" table header
  103. $("table.subscriptions_list_table thead tr th").eq(0).focus();
  104. options.context.glassContext.appController.showToast(StringResource.get('delete_sub_message'), {
  105. 'type': 'info',
  106. 'btnLabel': StringResource.get('delete_undo'),
  107. 'callback': function callback() {
  108. deleteOptions.pending = false;
  109. deleteCallbacks.undoDelete($subscriptionRow);
  110. },
  111. 'newestOnTop': true,
  112. 'preventDuplicates': false,
  113. 'timeOut': 6000,
  114. 'extendedTimeOut': 1000,
  115. 'onHidden': function onHidden() {
  116. deleteCallbacks.complete(deleteOptions);
  117. }
  118. });
  119. }
  120. }
  121. });
  122. return ContextMenuButtonView;
  123. });