"use strict"; /* * Licensed Materials - Property of IBM * * IBM Cognos Products: ADMIN * * (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/admin/nls/StringResource', 'bi/schedule/service/service'], function (Class, StringResource, shareService) { 'use strict'; var ContextMenuButtonView = Class.extend({ shareService: shareService, onSelectItem: function onSelectItem(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 isItemVisible(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; }*/ return true; }, _showSubscriptionPane: function _showSubscriptionPane(glassContext, descriptor, launchPoint, callback) { var content = { 'module': 'bi/schedule/views/SubscriptionView', 'glassContext': glassContext, 'descriptor': descriptor }; if (callback !== undefined) { content.callback = callback; } glassContext.appController.showSlideOut({ 'position': 'right', 'content': content, 'width': "400px", 'enableTabLooping': true, 'label': StringResource.get('subscription_header_region'), 'launchPoint': launchPoint }); }, _updateSubscriptionMenuItem: function _updateSubscriptionMenuItem(options) { var subscriptionId = options.context.target.activeObject.subscriptionId; var updateCallback = options.context.target.activeObject.updateCallback; this.shareService.getSubscriptionDetails(subscriptionId, options.context.glassContext).then(function (data) { this._showSubscriptionPane(options.context.glassContext, data, options.launchPoint, { onUpdate: updateCallback }); }.bind(this)); }, _showVersionsPane: function _showVersionsPane(glassContext, properties, launchPoint) { var content = { 'module': 'bi/content_apps/VersionsView', 'glassContext': glassContext, 'objectInformation': properties.data[0] }; glassContext.appController.showSlideOut({ 'position': 'right', 'content': content, 'width': '350px', 'enableTabLooping': true, 'label': StringResource.get('schedule_subscription_version_aria_label'), 'launchPoint': launchPoint }); }, _viewVersionsOfSubscriptionMenuItem: function _viewVersionsOfSubscriptionMenuItem(options) { var subscriptionId = options.context.target.activeObject.subscriptionId; this.shareService.getObjectProperties(subscriptionId, options.context.glassContext).then(function (properties) { this._showVersionsPane(options.context.glassContext, properties, options.launchPoint); }.bind(this)); }, _deleteSubscriptionMenuItem: function _deleteSubscriptionMenuItem(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(StringResource.get('delete_subscription_confirm_message'), StringResource.get('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(StringResource.get('delete_sub_message'), { 'type': 'info', 'btnLabel': StringResource.get('delete_undo'), 'callback': function callback() { deleteOptions.pending = false; deleteCallbacks.undoDelete($subscriptionRow); }, 'newestOnTop': true, 'preventDuplicates': false, 'timeOut': 6000, 'extendedTimeOut': 1000, 'onHidden': function onHidden() { deleteCallbacks.complete(deleteOptions); } }); } } }); return ContextMenuButtonView; });