"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: admin * Copyright IBM Corp. 2018 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'react-dom', 'react', 'mobx', 'ba-react-admin/ba-react-admin.min'], function (_, ContentView, StringResource, ReactDOM, React, mobx, AdminReact) { 'use strict'; //NOSONAR: meant to be strict var CapabilitesTab = ContentView.extend({ init: function init(options) { CapabilitesTab.inherited('init', this, arguments); _.extend(this, options); }, addMembers: function addMembers(membersList) { var defaultTypes = this.objectInfo.type === 'group' ? ['group', 'account'] : ['group', 'role', 'account']; this.membersList = membersList; this.addMemberSlideout = this.glassContext.appController.showSlideOut({ 'parent': this.slideout, 'width': "450px", 'content': { 'module': 'bi/admin/account/slideout/SecurityObjectSelectorPane', 'parentView': this, 'objectInfo': [this.objectInfo], 'allowedSelectionTypes': defaultTypes, 'multiSelectCallback': this.addSelection.bind(this), targetType: [] } }); }, addSelection: function addSelection(selectedItems) { var tempList = mobx.toJS(this.membersList); _.each(selectedItems, function (item) { var memberObject = { 'label': item.defaultName, 'searchPath': item.searchPath, 'type': item.objectClass, 'openCustomSlideout': false, 'policyValue': 0, 'selectionValue': null }; tempList.push(memberObject); }.bind(this)); var uniqueList = _.uniq(tempList, function (item, key, a) { return item.searchPath; }); this.membersList.replace(uniqueList); }, setFocus: function setFocus() {}, render: function render() { this.$el.addClass("reactCapabilitiesView"); ReactDOM.unmountComponentAtNode(this.$el[0]); this.capabilitiesMemberList = React.createElement(AdminReact.CapabilitiesView, { 'glassContext': this.glassContext, 'slideout': this.slideout, 'StringResource': StringResource, 'objectInfo': this.objectInfo, 'parent': this }); ReactDOM.render(this.capabilitiesMemberList, this.$el[0]); if (this.slideout.contentView) { this.slideout.contentView.canHide = this._canHide.bind(this); } return Promise.resolve(); }, _canHide: function _canHide() { var propertyUIControl = this.slideout.contentView.getPropertyUIControl(); if (AdminReact.CapabilitiesMemberStore.forceSlideoutClose) { AdminReact.CapabilitiesMemberStore.forceSlideoutClose = false; return propertyUIControl.onClose().then(function () { return !propertyUIControl.hasValidationError(); }.bind(this)); } var policySet = true; if (this.membersList && this.membersList.length > 0) { _.each(this.membersList, function (item) { if (item.policyValue === 0) { policySet = false; } }.bind(this)); } if (!policySet) { AdminReact.CapabilitiesMemberStore.closeSlideoutDialog = true; return Promise.resolve(policySet); } else { return propertyUIControl.onClose().then(function () { return !propertyUIControl.hasValidationError(); }.bind(this)); } }, onClose: function onClose() { CapabilitesTab.inherited('onClose', this, arguments); if (this.$el[0]) { ReactDOM.unmountComponentAtNode(this.$el[0]); } } }); return CapabilitesTab; });