"use strict"; /** * Licensed Materials - Property of IBM * * IBM Cognos Products: ADMIN * * Copyright IBM Corp. 2017, 2022 * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['jquery', 'underscore', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'react', 'react-dom', 'ba-react-admin/ba-react-admin.min', 'bacontentnav/ui/dialogs/OpenDialog', 'bi/admin/account/slideout/SecurityObjectSelectorPane', 'bi/content_apps/PromptValuesView'], function ($, _, ContentView, StringResource, React, ReactDOM, AdminReact, OpenDialog, SecurityObjectSelectorPane, PromptValuesView) { var view = ContentView.extend({ selectableItems: _.keys(AdminReact.JobStepObjects), init: function init(options) { view.inherited('init', this, arguments); this.objectInfo = {}; if (this.objRef) { this.objectInfo.id = this.objRef; } $.extend(this, options); }, updateContent: function updateContent(options) { if (AdminReact.JobUIStore.isOpen) { if (options) { AdminReact.JobObjectStore.updateWithNewContent(this.glassContext, options); if (options.objectInfo && options.objectInfo.id) { this.objectInfo.id = options.objectInfo.id; } this.trigger("change:state"); } } }, deactivate: function deactivate() { return Promise.resolve(); }, activate: function activate(options) { if (options.setFocus) { return Promise.resolve(); } AdminReact.JobObjectStore.updateWithNewContent(this.glassContext, options); if (options.objectInfo && options.objectInfo.id) { this.objectInfo.id = options.objectInfo.id; } this.trigger("change:state"); return Promise.resolve(); }, getTitle: function getTitle() { var jobStore = AdminReact.JobObjectStore; if (jobStore.isNew) { return StringResource.get("newJob"); } else { return jobStore.defaultName; } }, getContent: function getContent() { if (AdminReact.JobObjectStore.isNew) { return { objRef: "" }; } if (this.objectInfo && this.objectInfo.id) { return { objRef: this.objectInfo.id }; } }, isDirty: function isDirty() { var jobStore = AdminReact.JobObjectStore; if (jobStore.isNew) { return true; } else { return jobStore.isDirty; } }, getIcon: function getIcon() { return 'common-open-tab'; }, setTitle: function setTitle() { this.trigger("change:title", { value: this.getTitle() }); }, updateAfterSave: function updateAfterSave() { this.setTitle(); this.trigger("change:dirty"); this.objectInfo.id = AdminReact.JobObjectStore.id; this.trigger("change:state"); }, renderAccountSelector: function renderAccountSelector(rootEl) { var anEl = $(rootEl); var defaultTypes = ['account']; var aPane = new SecurityObjectSelectorPane({ glassContext: this.glassContext, 'parentView': this, 'objectInfo': [{}], 'allowedSelectionTypes': defaultTypes, 'targetType': [], '$el': anEl }); aPane.renderBody(anEl); }, _openScheduleSlideout: function _openScheduleSlideout(objectInformation) { var objIn = JSON.parse(JSON.stringify(objectInformation)); this.glassContext.appController.showSlideOut({ content: { module: 'bi/schedule/views/SchedulesView', glassContext: this.glassContext, objectInfo: objIn }, width: '390px', enableTabLooping: true, label: "Schedule", position: 'left' }); }, _showOptionsSlideout: function _showOptionsSlideout(objectInformation, selectedStep) { this.glassContext.appController.showSlideOut({ content: { module: 'bi/admin/job/RunOptionsView', glassContext: this.glassContext, objectInformation: objectInformation, selectedStep: selectedStep }, width: '390px', enableTabLooping: true, label: StringResource.get("options"), position: 'left', onHide: function onHide() { this.contentView.onHide(); } }); }, openRelinkDialog: function openRelinkDialog() { var dialog = new OpenDialog({ glassContext: this.glassContext, typesToOpen: this.selectableItems, multiSelect: false, primaryBtnText: StringResource.get('ok'), onOpenCallback: AdminReact.JobUIStore.relinkDialogClosed.bind(AdminReact.JobUIStore, this.glassContext), dataManipulationCallback: this._filterOutNoExecute.bind(this), extraUrlParameters: ['options'] }); dialog.title = StringResource.get('relinkAsset'); dialog.primaryBtnText = StringResource.get('ok'); dialog.open(); }, openOptionsSlideout: function openOptionsSlideout(selectedStep, descriptor) { var runnable = selectedStep; if (selectedStep.stepObject && selectedStep.stepObject.length > 0) { runnable = selectedStep.stepObject[0]; } if (runnable.type === 'reportView') { AdminReact.JobAccess.getPropertiesForReportView(this.glassContext, runnable.id).then(function (result) { var objectInformation = result.data.data[0]; objectInformation.descriptor = descriptor; this._showOptionsSlideout(objectInformation, selectedStep); }.bind(this)); } else { this._showOptionsSlideout({ id: runnable.id, type: runnable.type, canBurst: selectedStep.canBurst, descriptor: descriptor }, selectedStep); } }, openDeploymentSelection: function openDeploymentSelection(addFunction) { var jobAccess = AdminReact.JobAccess; jobAccess.getAdminFolderID(this.glassContext).then(function (adminFolderID) { var rootObject = { id: adminFolderID, defaultName: 'Directory', type: 'adminFolder', _meta: { links: { items: { mimeType: 'application/json', url: 'v1/objects/' + adminFolderID + '/items' }, self: { mimeType: 'application/json', url: 'v1/objects/' + adminFolderID } } } }; var dialog = new OpenDialog({ glassContext: this.glassContext, typesToOpen: ['importDeployment', 'exportDeployment'], multiSelect: true, ancestors: [rootObject], rootObjects: [rootObject], onOpenCallback: addFunction, extraUrlParameters: ['options'] }); dialog.title = StringResource.get("addJobSteps"); dialog.primaryBtnText = StringResource.get("jobStepsToAdd"); dialog.open(); }.bind(this)); }, renderPromptSelector: function renderPromptSelector(rootEl, obj) { var anEl = $(rootEl); this.objectInfo = { id: obj.stepObject[0].id, type: obj.type }; var anEl = $(rootEl); var defaultTypes = ['account']; var aPane = new PromptValuesView({ glassContext: this.glassContext, 'parentView': this, 'promptDisplayValues': [], 'parameters': [], 'objectInformation': { id: obj.id, type: obj.type }, 'hasPermission': true, 'clearCallback': function clearCallback() { console.log('weeeeee'); }, 'editCallback': function editCallback() { console.log('weeeeee'); }, '$el': anEl, slideout: this }); aPane.render(); }, _filterOutNoExecute: function _filterOutNoExecute(response) { response.data = _.filter(response.data, function (result) { if (this.selectableItems.indexOf(result.type) === -1) { return true; } return result.permissions.indexOf("execute") !== -1; }.bind(this)); }, openContentSelection: function openContentSelection(addFunction) { var dialog = new OpenDialog({ glassContext: this.glassContext, typesToOpen: this.selectableItems, multiSelect: true, primaryBtnText: StringResource.get("addJobSteps"), filesToOpenTitle: StringResource.get("jobStepsToAdd"), onOpenCallback: addFunction, dataManipulationCallback: this._filterOutNoExecute.bind(this), extraUrlParameters: ['options'] }); dialog.title = StringResource.get("addJobSteps"); dialog.primaryBtnText = StringResource.get("jobStepsToAdd"); dialog.open(); }, remove: function remove() { AdminReact.JobUIStore.setIsOpen(false); view.inherited('remove', this, arguments); ReactDOM.unmountComponentAtNode(this.$el[0]); }, render: function render() { AdminReact.JobUIStore.setIsOpen(true); this.$el.addClass("jobmgt"); this.$el.css("width", "100%"); this.$el.css("height", "100%"); ReactDOM.unmountComponentAtNode(this.$el[0]); var jobPane = React.createElement(AdminReact.JobPane, { glassContext: this.glassContext, StringResource: StringResource, objectInfo: this.objectInfo, dialog: this, selectedJobSteps: this.selectedSteps }); AdminReact.JobObjectStore.setOptionDefault(this.glassContext); ReactDOM.render(jobPane, this.$el[0]); return Promise.resolve(); } }); view.openJobPane = function (glassContext, content) { var perspective = glassContext.appController.currentAppView.perspective; var context = { id: "123", content: content }; if (perspective === 'job_mgt' && content.setFocus) return; if (content.addToJob === true) { glassContext.appController.openAppView('job_mgt', context); return; } glassContext.appController.closeAppView('job_mgt', '123').then(function () { setTimeout(function () { glassContext.appController.openAppView('job_mgt', context); }, 1); }); }; return view; });