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);
42 componentWillUnmount() {
43 this.Store.unlisten(this.updateState);
45 updateState = (state) => {
48 updateInput = (key, e) => {
50 this.actions.handleUpdateInput({
51 [property]:e.target.value
54 disabledChange = (e) => {
55 this.actions.handleDisabledChange(e.target.checked);
57 platformChange = (platformRole, e) => {
58 this.actions.handlePlatformRoleUpdate(platformRole, e.currentTarget.checked);
60 addProjectRole = (e) => {
61 this.actions.handleAddProjectItem();
63 removeProjectRole = (i, e) => {
64 this.actions.handleRemoveProjectItem(i);
66 updateProjectRole = (i, e) => {
67 this.actions.handleUpdateProjectRole(i, e)
70 this.actions.handleAddUser();
72 viewUser = (un, index) => {
73 this.actions.viewUser(un, index);
76 this.actions.editUser(false);
78 cancelEditUser = () => {
79 this.actions.editUser(true)
82 this.actions.handleCloseUserPanel();
84 // updateUser = (e) => {
85 // e.preventDefault();
86 // e.stopPropagation();
88 // this.Store.updateUser();
93 this.Store.deleteUser({
94 'user-name': this.state['user-name'],
95 'user-domain': this.state['user-domain']
101 if(this.state['new-password'] != this.state['confirm-password']) {
102 this.props.actions.showNotification('Passwords do not match')
104 this.Store.createUser({
105 'user-name': this.state['user-name'],
106 'user-domain': this.state['user-domain'],
107 'password': this.state['new-password']
108 // 'confirm-password': this.state['confirm-password']
112 updateUser = (e) => {
116 let validatedPasswords = validatePasswordFields(this.state);
117 if(validatedPasswords) {
118 this.Store.updateUser(_.merge({
119 'user-name': this.context.userProfile.userId,
120 'user-domain': this.state['user-domain'],
121 'password': this.state['new-password']
124 function validatePasswordFields(state) {
125 let oldOne = state['old-password'];
126 let newOne = state['new-password'];
127 let confirmOne = state['confirm-password'];
129 if(oldOne == newOne) {
130 self.props.actions.showNotification('Your new password must not match your old one');
133 if(newOne != confirmOne) {
134 self.props.actions.showNotification('Passwords do not match');
138 // 'old-password': oldOne,
139 'new-password': newOne,
140 'confirm-password': confirmOne
147 evaluateSubmit = (e) => {
148 if (e.keyCode == 13) {
149 if (this.props.isEdit) {
158 onTransitionEnd = (e) => {
159 this.actions.handleHideColumns(e);
160 console.log('transition end')
162 disableChange = (e) => {
163 let value = e.target.value;
164 value = value.toUpperCase();
175 const User = this.context.userProfile || {};
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 passwordSectionHTML = (
187 <FormSection title="PASSWORD CHANGE">
188 <Input label="NEW PASSWORD" type="password" value={state['new-password']} onChange={this.updateInput.bind(null, 'new-password')}/>
189 <Input label="REPEAT NEW PASSWORD" type="password" value={state['confirm-password']} onChange={this.updateInput.bind(null, 'confirm-password')}/>
194 <ButtonGroup className="buttonGroup">
195 <Button label="Update" type="submit" onClick={this.updateUser} />
200 <PanelWrapper column>
201 <PanelWrapper className={`row userManagement ${!this.state.userOpen ? 'userList-open' : ''}`} style={{'flexDirection': 'row'}} >
202 <PanelWrapper ref={(div) => { this.UserList = div}} className={`column userList expanded hideColumns`}>
203 <Panel title={User.userId} style={{marginBottom: 0}} no-corners>
204 <FormSection title="USER INFO">
205 <table className="userProfile-table">
214 User.data && User.data.projectId && User.data.projectId.map((p,i)=> {
215 let project = User.data.project[p];
216 let projectConfig = project && project.data['project-config'];
225 project && Object.keys(project.role).map(function(k) {
226 return <div>{k}</div>
237 {passwordSectionHTML}
240 <div className="buttonSection">
251 // onClick={this.Store.update.bind(null, Account)}
252 UserProfileDashboard.contextTypes = {
253 router: React.PropTypes.object,
254 userProfile: React.PropTypes.object
257 UserProfileDashboard.defaultProps = {
262 export default SkyquakeComponent(UserProfileDashboard);
265 function isElementInView(el) {
266 var rect = el && el.getBoundingClientRect() || {};
271 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
272 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
277 // isReadOnly={state.isReadOnly} disabled={state.disabled} onChange={this.disableChange}
279 class isDisabled extends React.Component {
284 let props = this.props;
292 class InputCollection extends React.Component {
295 this.collection = props.collection;
297 buildTextInput(onChange, v, i) {
300 readonly={this.props.readonly}
301 style={{flex: '1 1'}}
304 onChange= {onChange.bind(null, i)}
308 buildSelectOption(initial, options, onChange, v, i) {
311 readonly={this.props.readonly}
312 key={`${i}-${v.replace(' ', '_')}`}
316 onChange={onChange.bind(null, i)}
324 const props = this.props;
326 let className = "InputCollection";
327 if (props.className) {
328 className = `${className} ${props.className}`;
330 if (props.type == 'select') {
331 inputType = this.buildSelectOption.bind(this, props.initial, props.options, props.onChange);
333 inputType = this.buildTextInput.bind(this, props.onChange)
336 <div className="InputCollection-wrapper">
337 {props.collection.map((v,i) => {
339 <div key={i} className={className} >
342 props.readonly ? null : <span onClick={props.RemoveItemFn.bind(null, i)} className="removeInput"><img src={imgRemove} />Remove</span>}
346 { props.readonly ? null : <span onClick={props.AddItemFn} className="addInput"><img src={imgAdd} />Add</span>}
353 InputCollection.defaultProps = {
356 onChange: function(i, e) {
358 Updating with: ${e.target.value}
362 AddItemFn: function(e) {
363 console.log(`Adding a new item to collection`)
365 RemoveItemFn: function(i, e) {
366 console.log(`Removing item from collection at index of: ${i}`)
370 class FormSection extends React.Component {
372 let className = 'FormSection ' + this.props.className;
375 style={this.props.style}
376 className={className}
378 <div className="FormSection-title">
381 <div className="FormSection-body">
382 {this.props.children}
390 FormSection.defaultProps = {