2 * STANDARD_RIFT_IO_COPYRIGHT
5 import React from 'react';
6 import ReactDOM from 'react-dom';
7 import AppHeader from 'widgets/header/header.jsx';
8 import UserProfileStore from './userProfileStore.js';
9 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
10 import 'style/layout.scss';
11 import '../dashboard/userMgmt.scss';
12 import {Panel, PanelWrapper} from 'widgets/panel/panel';
15 import TextInput from 'widgets/form_controls/textInput.jsx';
16 import Input from 'widgets/form_controls/input.jsx';
17 import Button, {ButtonGroup} from 'widgets/button/sq-button.jsx';
18 import SelectOption from 'widgets/form_controls/selectOption.jsx';
19 import 'widgets/form_controls/formControls.scss';
20 import imgAdd from '../../node_modules/open-iconic/svg/plus.svg'
21 import imgRemove from '../../node_modules/open-iconic/svg/trash.svg';
23 class UserProfileDashboard extends React.Component {
26 this.Store = this.props.flux.stores.hasOwnProperty('UserProfileStore') ? this.props.flux.stores.UserProfileStore : this.props.flux.createStore(UserProfileStore);
27 this.state = this.Store.getState();
28 this.actions = this.state.actions;
31 componentDidUpdate() {
33 ReactDOM.findDOMNode(this.UserList).addEventListener('transitionend', this.onTransitionEnd, false);
34 setTimeout(function() {
35 let element = self[`user-ref-${self.state.activeIndex}`]
36 element && !isElementInView(element) && element.scrollIntoView({block: 'end', behavior: 'smooth'});
39 componentWillMount() {
40 this.Store.listen(this.updateState);
41 this.Store.getUsers();
43 componentWillUnmount() {
44 this.Store.unlisten(this.updateState);
46 updateState = (state) => {
49 updateInput = (key, e) => {
51 this.actions.handleUpdateInput({
52 [property]:e.target.value
55 disabledChange = (e) => {
56 this.actions.handleDisabledChange(e.target.checked);
58 platformChange = (platformRole, e) => {
59 this.actions.handlePlatformRoleUpdate(platformRole, e.currentTarget.checked);
61 addProjectRole = (e) => {
62 this.actions.handleAddProjectItem();
64 removeProjectRole = (i, e) => {
65 this.actions.handleRemoveProjectItem(i);
67 updateProjectRole = (i, e) => {
68 this.actions.handleUpdateProjectRole(i, e)
71 this.actions.handleAddUser();
73 viewUser = (un, index) => {
74 this.actions.viewUser(un, index);
77 this.actions.editUser(false);
79 cancelEditUser = () => {
80 this.actions.editUser(true)
83 this.actions.handleCloseUserPanel();
85 // updateUser = (e) => {
86 // e.preventDefault();
87 // e.stopPropagation();
89 // this.Store.updateUser();
94 this.Store.deleteUser({
95 'user-name': this.state['user-name'],
96 'user-domain': this.state['user-domain']
102 if(this.state['new-password'] != this.state['confirm-password']) {
103 this.props.actions.showNotification('Passwords do not match')
105 this.Store.createUser({
106 'user-name': this.state['user-name'],
107 'user-domain': this.state['user-domain'],
108 'password': this.state['new-password']
109 // 'confirm-password': this.state['confirm-password']
113 updateUser = (e) => {
117 let validatedPasswords = validatePasswordFields(this.state);
118 if(validatedPasswords) {
119 this.Store.updateUser(_.merge({
120 'user-name': this.context.userProfile.userId,
121 'user-domain': this.state['user-domain'],
122 'password': this.state['new-password']
125 function validatePasswordFields(state) {
126 let oldOne = state['old-password'];
127 let newOne = state['new-password'];
128 let confirmOne = state['confirm-password'];
130 if(oldOne == newOne) {
131 self.props.actions.showNotification('Your new password must not match your old one');
134 if(newOne != confirmOne) {
135 self.props.actions.showNotification('Passwords do not match');
139 // 'old-password': oldOne,
140 'new-password': newOne,
141 'confirm-password': confirmOne
148 evaluateSubmit = (e) => {
149 if (e.keyCode == 13) {
150 if (this.props.isEdit) {
159 onTransitionEnd = (e) => {
160 this.actions.handleHideColumns(e);
161 console.log('transition end')
163 disableChange = (e) => {
164 let value = e.target.value;
165 value = value.toUpperCase();
177 let props = this.props;
178 let state = this.state;
179 let passwordSectionHTML = null;
180 let formButtonsHTML = (
181 <ButtonGroup className="buttonGroup">
182 <Button label="EDIT" type="submit" onClick={this.editUser} />
185 const User = this.context.userProfile || {};
186 passwordSectionHTML = (
188 <FormSection title="PASSWORD CHANGE">
189 <Input label="NEW PASSWORD" type="password" value={state['new-password']} onChange={this.updateInput.bind(null, 'new-password')}/>
190 <Input label="REPEAT NEW PASSWORD" type="password" value={state['confirm-password']} onChange={this.updateInput.bind(null, 'confirm-password')}/>
197 <ButtonGroup className="buttonGroup">
198 <Button label="Update" type="submit" onClick={this.updateUser} />
205 <PanelWrapper column>
206 <PanelWrapper className={`row userManagement ${!this.state.userOpen ? 'userList-open' : ''}`} style={{'flexDirection': 'row'}} >
207 <PanelWrapper ref={(div) => { this.UserList = div}} className={`column userList expanded hideColumns`}>
208 <Panel title={User.userId} style={{marginBottom: 0}} no-corners>
214 state.roles.map((r,i) => {
215 return <td key={i}>{r}</td>
222 User.projects && User.projects.map((p,i)=> {
223 let projectConfig = p['project-config'];
225 if(projectConfig && projectConfig.user) {
226 projectConfig.user.map((u) => {
227 if(u['user-name'] == User.userId) {
228 userRoles = u.role && u.role.map((r) => {
240 state.roles.map((r,j) => {
241 return <td key={j}><Input readonly={state.isReadOnly} type="checkbox" checked={(userRoles.indexOf(r) > -1)} /></td>
250 {passwordSectionHTML}
261 // onClick={this.Store.update.bind(null, Account)}
262 UserProfileDashboard.contextTypes = {
263 router: React.PropTypes.object,
264 userProfile: React.PropTypes.object
267 UserProfileDashboard.defaultProps = {
272 export default SkyquakeComponent(UserProfileDashboard);
275 function isElementInView(el) {
276 var rect = el && el.getBoundingClientRect() || {};
281 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
282 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
287 // isReadOnly={state.isReadOnly} disabled={state.disabled} onChange={this.disableChange}
289 class isDisabled extends React.Component {
294 let props = this.props;
302 class InputCollection extends React.Component {
305 this.collection = props.collection;
307 buildTextInput(onChange, v, i) {
310 readonly={this.props.readonly}
311 style={{flex: '1 1'}}
314 onChange= {onChange.bind(null, i)}
318 buildSelectOption(initial, options, onChange, v, i) {
321 readonly={this.props.readonly}
322 key={`${i}-${v.replace(' ', '_')}`}
326 onChange={onChange.bind(null, i)}
334 const props = this.props;
336 let className = "InputCollection";
337 if (props.className) {
338 className = `${className} ${props.className}`;
340 if (props.type == 'select') {
341 inputType = this.buildSelectOption.bind(this, props.initial, props.options, props.onChange);
343 inputType = this.buildTextInput.bind(this, props.onChange)
346 <div className="InputCollection-wrapper">
347 {props.collection.map((v,i) => {
349 <div key={i} className={className} >
352 props.readonly ? null : <span onClick={props.RemoveItemFn.bind(null, i)} className="removeInput"><img src={imgRemove} />Remove</span>}
356 { props.readonly ? null : <span onClick={props.AddItemFn} className="addInput"><img src={imgAdd} />Add</span>}
363 InputCollection.defaultProps = {
366 onChange: function(i, e) {
368 Updating with: ${e.target.value}
372 AddItemFn: function(e) {
373 console.log(`Adding a new item to collection`)
375 RemoveItemFn: function(i, e) {
376 console.log(`Removing item from collection at index of: ${i}`)
380 class FormSection extends React.Component {
382 let className = 'FormSection ' + this.props.className;
385 style={this.props.style}
386 className={className}
388 <div className="FormSection-title">
391 <div className="FormSection-body">
392 {this.props.children}
400 FormSection.defaultProps = {