/* * STANDARD_RIFT_IO_COPYRIGHT */ import React from 'react'; import ReactDOM from 'react-dom'; import AppHeader from 'widgets/header/header.jsx'; import UserManagementStore from './userMgmtStore.js'; import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx'; import 'style/layout.scss'; import './userMgmt.scss'; import {Panel, PanelWrapper} from 'widgets/panel/panel'; import SkyquakeRBAC from 'widgets/skyquake_rbac/skyquakeRBAC.jsx'; import TextInput from 'widgets/form_controls/textInput.jsx'; import Input from 'widgets/form_controls/input.jsx'; import Button, {ButtonGroup} from 'widgets/button/sq-button.jsx'; import SelectOption from 'widgets/form_controls/selectOption.jsx'; import 'widgets/form_controls/formControls.scss'; import imgAdd from '../../node_modules/open-iconic/svg/plus.svg' import imgRemove from '../../node_modules/open-iconic/svg/trash.svg'; import {merge} from 'lodash'; import ROLES from 'utils/roleConstants.js'; const PLATFORM = ROLES.PLATFORM; class UserManagementDashboard extends React.Component { constructor(props) { super(props); this.Store = this.props.flux.stores.hasOwnProperty('UserManagementStore') ? this.props.flux.stores.UserManagementStore : this.props.flux.createStore(UserManagementStore); this.state = this.Store.getState(); this.actions = this.state.actions; } componentDidUpdate() { let self = this; ReactDOM.findDOMNode(this.UserList).addEventListener('transitionend', this.onTransitionEnd, false); setTimeout(function() { let element = self[`user-ref-${self.state.activeIndex}`] element && !isElementInView(element) && element.scrollIntoView({block: 'end', behavior: 'smooth'}); }) } componentWillMount() { this.Store.listen(this.updateState); this.Store.getUsers(); } componentWillUnmount() { this.Store.unlisten(this.updateState); } updateState = (state) => { this.setState(state); } updateInput = (key, e) => { let property = key; this.actions.handleUpdateInput({ [property]:e.target.value }) } disabledChange = (e) => { this.actions.handleDisabledChange(e.target.checked); } platformChange = (platformRole, e) => { this.actions.handlePlatformRoleUpdate(platformRole, e.currentTarget.checked); } addProjectRole = (e) => { this.actions.handleAddProjectItem(); } removeProjectRole = (i, e) => { this.actions.handleRemoveProjectItem(i); } updateProjectRole = (i, e) => { this.actions.handleUpdateProjectRole(i, e) } addUser = () => { this.actions.handleAddUser(); } viewUser = (un, index) => { this.actions.viewUser(un, index); } editUser = () => { this.actions.editUser(false); } cancelEditUser = () => { this.actions.editUser(true) } closePanel = () => { this.actions.handleCloseUserPanel(); } // updateUser = (e) => { // e.preventDefault(); // e.stopPropagation(); // this.Store.updateUser(); // } deleteUser = (e) => { e.preventDefault(); e.stopPropagation(); if (confirm('Are you sure you want to delete this user?')) { this.Store.deleteUser({ 'user-name': this.state['user-name'], 'user-domain': this.state['user-domain'] }); } } createUser = (e) => { e.preventDefault(); e.stopPropagation(); if(this.state['new-password'] != this.state['confirm-password']) { this.props.actions.showNotification('Passwords do not match') } else { let isDisabled = {}; if (this.state.disabled == "TRUE") { let isDisabled = { disabled: [null] } } this.Store.createUser(_.merge({ 'user-name': this.state['user-name'], 'user-domain': this.state['user-domain'], 'password': this.state['new-password'] // 'confirm-password': this.state['confirm-password'] }, isDisabled)); } } updateUser = (e) => { let self = this; e.preventDefault(); e.stopPropagation(); let validatedPasswords = validatePasswordFields(this.state); if(validatedPasswords) { let isDisabled = {}; let password = {}; if (self.state.disabled == "TRUE") { isDisabled = { disabled: [null] } } if (this.state['new-password'] != '') { password = {'password': this.state['new-password']} } else { password = { 'password': this.state.currentPassword } } this.Store.updateUser(_.merge({ 'user-name': this.state['user-name'], 'user-domain': this.state['user-domain'] }, _.merge(isDisabled, password))); } function validatePasswordFields(state) { let oldOne = state['old-password']; let newOne = state['new-password']; let confirmOne = state['confirm-password']; if(true) { // if(!oldOne || !newOne) { // self.props.actions.showNotification('Please fill in all fields.'); // return false; // } if((oldOne || newOne) && (oldOne == newOne)) { self.props.actions.showNotification('Your new password must not match your old one'); return false; } if(newOne != confirmOne) { self.props.actions.showNotification('Passwords do not match'); return false; } return { // 'old-password': oldOne, 'new-password': newOne, 'confirm-password': confirmOne } } else { return {}; } } } evaluateSubmit = (e) => { if (e.keyCode == 13) { if (this.props.isEdit) { this.updateUser(e); } else { this.createUser(e); } e.preventDefault(); e.stopPropagation(); } } onTransitionEnd = (e) => { this.actions.handleHideColumns(e); console.log('transition end') } disableChange = (e) => { let value = e.target.value; value = value.toUpperCase(); this.actions.handleDisabledChange(value); } render() { let self = this; let html; let props = this.props; let state = this.state; let passwordSectionHTML = null; let formButtonsHTML = (