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'],
122 'ui-state': this.context.userProfile.data['ui-state']
125 function validatePasswordFields(state) {
126 let newOne = state['new-password'];
127 let confirmOne = state['confirm-password'];
128 if (!newOne || !confirmOne) {
129 self.props.actions.showNotification('Please fill in all fields.');
132 if (newOne != confirmOne) {
133 self.props.actions.showNotification('Passwords do not match');
137 'new-password': newOne,
138 'confirm-password': confirmOne
142 evaluateSubmit = (e) => {
143 if (e.keyCode == 13) {
144 if (this.state.isEdit) {
153 onTransitionEnd = (e) => {
154 this.actions.handleHideColumns(e);
155 console.log('transition end')
157 disableChange = (e) => {
158 let value = e.target.value;
159 value = value.toUpperCase();
160 if (value == "TRUE") {
170 const User = this.context.userProfile || {};
172 let props = this.props;
173 let state = this.state;
174 let passwordSectionHTML = null;
175 let formButtonsHTML = (
176 <ButtonGroup className="buttonGroup">
177 <Button label="EDIT" type="submit" onClick={this.editUser} />
180 passwordSectionHTML = (
182 <FormSection title="PASSWORD CHANGE">
183 <Input label="NEW PASSWORD" type="password" value={state['new-password']} onChange={this.updateInput.bind(null, 'new-password')} />
184 <Input label="REPEAT NEW PASSWORD" type="password" value={state['confirm-password']} onChange={this.updateInput.bind(null, 'confirm-password')} />
189 <ButtonGroup className="buttonGroup">
190 <Button label="Update" type="submit" onClick={this.updateUser} />
195 <PanelWrapper column>
196 <PanelWrapper className={`row userManagement ${!this.state.userOpen ? 'userList-open' : ''}`} style={{ 'flexDirection': 'row' }} >
197 <PanelWrapper ref={(div) => { this.UserList = div }} className={`column userList expanded hideColumns`}>
198 <Panel title={User.userId} style={{ marginBottom: 0 }} no-corners>
199 <FormSection title="USER INFO">
200 <table className="userProfile-table">
209 User.data && User.data.projectId && User.data.projectId.map((p, i) => {
210 let project = User.data.project[p];
211 let projectConfig = project && project.data['project-config'];
220 project && Object.keys(project.role).map(function (k, i) {
221 return <div key={i}>{k}</div>
232 {passwordSectionHTML}
235 <div className="buttonSection">
246 // onClick={this.Store.update.bind(null, Account)}
247 UserProfileDashboard.contextTypes = {
248 router: React.PropTypes.object,
249 userProfile: React.PropTypes.object
252 UserProfileDashboard.defaultProps = {
257 export default SkyquakeComponent(UserProfileDashboard);
260 function isElementInView(el) {
261 var rect = el && el.getBoundingClientRect() || {};
266 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
267 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
272 // isReadOnly={state.isReadOnly} disabled={state.disabled} onChange={this.disableChange}
274 class isDisabled extends React.Component {
279 let props = this.props;
287 class InputCollection extends React.Component {
290 this.collection = props.collection;
292 buildTextInput(onChange, v, i) {
295 readonly={this.props.readonly}
296 style={{ flex: '1 1' }}
299 onChange={onChange.bind(null, i)}
303 buildSelectOption(initial, options, onChange, v, i) {
306 readonly={this.props.readonly}
307 key={`${i}-${v.replace(' ', '_')}`}
311 onChange={onChange.bind(null, i)}
319 const props = this.props;
321 let className = "InputCollection";
322 if (props.className) {
323 className = `${className} ${props.className}`;
325 if (props.type == 'select') {
326 inputType = this.buildSelectOption.bind(this, props.initial, props.options, props.onChange);
328 inputType = this.buildTextInput.bind(this, props.onChange)
331 <div className="InputCollection-wrapper">
332 {props.collection.map((v, i) => {
334 <div key={i} className={className} >
337 props.readonly ? null : <span onClick={props.RemoveItemFn.bind(null, i)} className="removeInput"><img src={imgRemove} />Remove</span>}
341 {props.readonly ? null : <span onClick={props.AddItemFn} className="addInput"><img src={imgAdd} />Add</span>}
348 InputCollection.defaultProps = {
351 onChange: function (i, e) {
353 Updating with: ${e.target.value}
357 AddItemFn: function (e) {
358 console.log(`Adding a new item to collection`)
360 RemoveItemFn: function (i, e) {
361 console.log(`Removing item from collection at index of: ${i}`)
365 class FormSection extends React.Component {
367 let className = 'FormSection ' + this.props.className;
370 style={this.props.style}
371 className={className}
373 <div className="FormSection-title">
376 <div className="FormSection-body">
377 {this.props.children}
385 FormSection.defaultProps = {