"use strict"; /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Content Explorer *| (C) Copyright IBM Corp. 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['underscore', 'ba-react-admin/ba-react-admin.min', 'bi/admin/job/JobPane', 'bi/commons/ui/core/Class'], function (_, AdminReact, JobPane, Class) { 'use strict'; var JobMenuController = Class.extend({ runnables: _.keys(AdminReact.JobStepObjects), _getSelectedObject: function _getSelectedObject(options) { return options.target.activeObject.aSelectedContext; }, canExecute: function canExecute(options) { var selections = this._getSelectedObject(options); this.glassContext = options.glassContext; return this.isViewable(selections); }, doAction: function doAction(opts) { this.executeEditJob(opts.target.activeObject.aSelectedContext[0].id); }, isViewable: function isViewable(selections) { return selections.length === 1 && selections[0].type === 'jobDefinition' && selections[0].permissions.indexOf("traverse") !== -1; }, _canAddToJob: function _canAddToJob(selections) { var hasRunnable = this.selectionHasAtLeastOneRunnable(selections); if (hasRunnable && selections.length === 1) { return selections[0].id !== AdminReact.JobObjectStore.id; } return selections.length > 0 && hasRunnable; }, isItemVisible: function isItemVisible(options) { this.glassContext = options.glassContext; var selections = this._getSelectedObject(options); switch (options.target.itemId) { case 'com.ibm.bi.job.editJob': return this.isViewable(selections); break; case 'com.ibm.bi.job.createJobWith': return selections.length > 0 && this.selectionHasAtLeastOneRunnable(selections); break; case 'com.ibm.bi.job.addToJob': return this._canAddToJob(selections) && AdminReact.JobUIStore.isOpen && AdminReact.JobObjectStore.canWrite; break; default: return false; } }, onSelectItem: function onSelectItem(options) { switch (options.target.itemId) { case "com.ibm.bi.job.editJob": this.executeEditJob(options.options[0].id); break; case "com.ibm.bi.job.createJobWith": this.executeCreateJob(options); break; case "com.ibm.bi.job.addToJob": this.executeAddToJob(options); break; default: return; } }, executeCreateJob: function executeCreateJob(options) { var selections = this._getFilterSelectedList(options.options); var context = { selectedSteps: selections }; JobPane.openJobPane(this.glassContext, context); }, _getFilterSelectedList: function _getFilterSelectedList(list) { return _.reject(list, function (item) { return this.runnables.indexOf(item.type) === -1; }.bind(this)); }, executeAddToJob: function executeAddToJob(options) { var selections = this._getFilterSelectedList(options.options); AdminReact.JobObjectStore.addJobStepsFromGlass(this.glassContext, selections); var context = { setFocus: true, addToJob: true }; JobPane.openJobPane(this.glassContext, context); }, selectionHasAtLeastOneRunnable: function selectionHasAtLeastOneRunnable(selections) { for (var i = 0; i < selections.length; i++) { var currentItem = selections[i]; if (this.runnables.indexOf(currentItem.type) !== -1) { return true; } } return false; }, executeEditJob: function executeEditJob(id) { var context = { objectInfo: { id: id } }; JobPane.openJobPane(this.glassContext, context); } }); return JobMenuController; });