SubscriptionManagementContextMenu.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * (C) Copyright IBM Corp. 2015, 2016
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define([
  11. 'bi/glass/core/Class',
  12. 'bi/sharecommon/utils/translator',
  13. 'bi/schedule/app/appControler'
  14. ], function(Class, t, appController) {
  15. 'use strict';
  16. var ContextMenuButtonView = Class.extend({
  17. onSelectItem: function(context) {
  18. var options =
  19. {
  20. context: context,
  21. launchPoint: context.target.plugin.activeObject.currentTarget
  22. };
  23. var idTokens = context.target.itemId.split('.');
  24. var key = idTokens[idTokens.length - 1];
  25. if(key === "update") {
  26. this._updateSubscriptionMenuItem(options);
  27. }
  28. else if(key === "versions") {
  29. this._viewVersionsOfSubscriptionMenuItem(options);
  30. }
  31. else if(key === "delete") {
  32. this._deleteSubscriptionMenuItem(options);
  33. }
  34. },
  35. isItemVisible: function(context) {
  36. var idTokens = context.target.itemId.split('.');
  37. var key = idTokens[idTokens.length - 1];
  38. if(key === "update" || key === "versions" || key === "delete") {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. },
  44. _updateSubscriptionMenuItem: function(options) {
  45. var subscriptionId = options.context.target.activeObject.subscriptionId;
  46. var updateCallback = options.context.target.activeObject.updateCallback;
  47. appController.getSubscriptionDetails(subscriptionId, options.context.glassContext).then(function(data) {
  48. appController.showSubscriptionPane(options.context.glassContext, data, options.launchPoint, {
  49. onUpdate: updateCallback
  50. });
  51. });
  52. },
  53. _viewVersionsOfSubscriptionMenuItem: function(options) {
  54. var subscriptionId = options.context.target.activeObject.subscriptionId;
  55. appController.getSubscriptionRunHistory(subscriptionId, options.context.glassContext).then(function(properties) {
  56. appController.showVersionsPane(options.context.glassContext, properties, options.launchPoint);
  57. });
  58. },
  59. _deleteSubscriptionMenuItem: function(options) {
  60. var subscriptionId = options.context.target.activeObject.subscriptionId;
  61. var deleteCallbacks = options.context.target.activeObject.deleteCallbacks;
  62. var $subscriptionRow = $(options.context.target.activeObject.currentTarget).closest('tr');
  63. var deleteOptions = {
  64. subscriptionId : subscriptionId,
  65. pending: true
  66. };
  67. if (options.context.glassContext.services.userProfile.preferences.accessibilityFeatures) {
  68. options.context.glassContext.appController.showMessage(t.translate('delete_subscription_confirm_message'), t.translate('delete_confirm'), 'info', ['ok','cancel'], undefined, function(evt) {
  69. if (evt.btn==='ok') {
  70. deleteCallbacks.hideRow($subscriptionRow).done(function() {
  71. deleteCallbacks.complete(deleteOptions);
  72. });
  73. //set focus to "Enabled" table header
  74. $("table.subscriptions_list_table thead tr th").eq(0).focus();
  75. } else {
  76. //set the focus back to the chevron that was clicked
  77. $(options.launchPoint).focus();
  78. }
  79. }.bind(this));
  80. } else {
  81. deleteCallbacks.hideRow($subscriptionRow);
  82. //set focus to "Enabled" table header
  83. $("table.subscriptions_list_table thead tr th").eq(0).focus();
  84. options.context.glassContext.appController.showToast(t.translate('delete_sub_message'),
  85. {
  86. 'type': 'info',
  87. 'btnLabel' : t.translate('delete_undo'),
  88. 'callback' : function() {
  89. deleteOptions.pending = false;
  90. deleteCallbacks.undoDelete($subscriptionRow);
  91. },
  92. 'newestOnTop' : true,
  93. 'preventDuplicates' : false,
  94. 'timeOut': 6000,
  95. 'extendedTimeOut': 1000,
  96. 'onHidden' : function() {
  97. deleteCallbacks.complete(deleteOptions);
  98. }
  99. });
  100. }
  101. }
  102. });
  103. return ContextMenuButtonView;
  104. });