/* * Licensed Materials - Property of IBM * * IBM Cognos Products: SHARE * * (C) Copyright IBM Corp. 2015, 2016 * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define([ 'bi/glass/core/Class', 'bi/sharecommon/utils/translator', 'bi/schedule/app/appControler' ], function(Class, t, appController) { 'use strict'; var ContextMenuButtonView = Class.extend({ onSelectItem: function(context) { var options = { context: context, launchPoint: context.target.plugin.activeObject.currentTarget }; var idTokens = context.target.itemId.split('.'); var key = idTokens[idTokens.length - 1]; if(key === "update") { this._updateSubscriptionMenuItem(options); } else if(key === "versions") { this._viewVersionsOfSubscriptionMenuItem(options); } else if(key === "delete") { this._deleteSubscriptionMenuItem(options); } }, isItemVisible: function(context) { var idTokens = context.target.itemId.split('.'); var key = idTokens[idTokens.length - 1]; if(key === "update" || key === "versions" || key === "delete") { return true; } else { return false; } }, _updateSubscriptionMenuItem: function(options) { var subscriptionId = options.context.target.activeObject.subscriptionId; var updateCallback = options.context.target.activeObject.updateCallback; appController.getSubscriptionDetails(subscriptionId, options.context.glassContext).then(function(data) { appController.showSubscriptionPane(options.context.glassContext, data, options.launchPoint, { onUpdate: updateCallback }); }); }, _viewVersionsOfSubscriptionMenuItem: function(options) { var subscriptionId = options.context.target.activeObject.subscriptionId; appController.getSubscriptionRunHistory(subscriptionId, options.context.glassContext).then(function(properties) { appController.showVersionsPane(options.context.glassContext, properties, options.launchPoint); }); }, _deleteSubscriptionMenuItem: function(options) { var subscriptionId = options.context.target.activeObject.subscriptionId; var deleteCallbacks = options.context.target.activeObject.deleteCallbacks; var $subscriptionRow = $(options.context.target.activeObject.currentTarget).closest('tr'); var deleteOptions = { subscriptionId : subscriptionId, pending: true }; if (options.context.glassContext.services.userProfile.preferences.accessibilityFeatures) { options.context.glassContext.appController.showMessage(t.translate('delete_subscription_confirm_message'), t.translate('delete_confirm'), 'info', ['ok','cancel'], undefined, function(evt) { if (evt.btn==='ok') { deleteCallbacks.hideRow($subscriptionRow).done(function() { deleteCallbacks.complete(deleteOptions); }); //set focus to "Enabled" table header $("table.subscriptions_list_table thead tr th").eq(0).focus(); } else { //set the focus back to the chevron that was clicked $(options.launchPoint).focus(); } }.bind(this)); } else { deleteCallbacks.hideRow($subscriptionRow); //set focus to "Enabled" table header $("table.subscriptions_list_table thead tr th").eq(0).focus(); options.context.glassContext.appController.showToast(t.translate('delete_sub_message'), { 'type': 'info', 'btnLabel' : t.translate('delete_undo'), 'callback' : function() { deleteOptions.pending = false; deleteCallbacks.undoDelete($subscriptionRow); }, 'newestOnTop' : true, 'preventDuplicates' : false, 'timeOut': 6000, 'extendedTimeOut': 1000, 'onHidden' : function() { deleteCallbacks.complete(deleteOptions); } }); } } }); return ContextMenuButtonView; });