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;
cancelEditUser = () => {
this.actions.editUser(true)
}
- osePanel = () => {
+ closePanel = () => {
this.actions.handleCloseUserPanel();
}
// updateUser = (e) => {
deleteUser = (e) => {
e.preventDefault();
e.stopPropagation();
- this.Store.deleteUser({
+ 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();
if(this.state['new-password'] != this.state['confirm-password']) {
this.props.actions.showNotification('Passwords do not match')
} else {
- this.Store.createUser({
- 'user-name': this.state['user-name'],
- 'user-domain': this.state['user-domain'],
- 'password': this.state['new-password']
- // 'confirm-password': this.state['confirm-password']
- });
+ 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) => {
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'],
- 'password': this.state['new-password']
- }));
+ '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) {
+ // 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;
}
disableChange = (e) => {
let value = e.target.value;
value = value.toUpperCase();
- if (value=="TRUE") {
- value = true;
- } else {
- value = false;
- }
- console.log(value)
+ this.actions.handleDisabledChange(value);
}
render() {
let self = this;
state.isEdit ?
(
<ButtonGroup className="buttonGroup">
- <Button label="Update" type="submit" onClick={this.updateUser} />
<Button label="Delete" onClick={this.deleteUser} />
<Button label="Cancel" onClick={this.cancelEditUser} />
+ <Button label="Update" type="submit" onClick={this.updateUser} />
</ButtonGroup>
)
: (
<ButtonGroup className="buttonGroup">
+ <Button label="Cancel" onClick={this.closePanel} />
<Button label="Create" type="submit" onClick={this.createUser} />
</ButtonGroup>
)
<div>
Domain
</div>
+ <div>
+ Status
+ </div>
</div>
{state.users && state.users.map((u, k) => {
let platformRoles = [];
<div>
{u['user-domain']}
</div>
+ <div>
+ {u['disabled'] ? "DISABLED" : "ENABLED"}
+ </div>
</div>
style={{marginBottom: 0}}
hasCloseButton={this.closePanel}
no-corners>
- <FormSection title="USER INFO">
+ <FormSection title="USER INFO" className="userInfo">
{
- this.state.isEdit ?
- null
- : <Input readonly={state.isReadOnly} label="Username" value={state['user-name']} onChange={this.updateInput.bind(null, 'user-name')} />
+ (!state.isEditUser || state.isReadOnly) ?
+ <Input className="userInfo-section" readonly={state.isReadOnly || this.state.isEdit} label="Username" value={state['user-name']} onChange={this.updateInput.bind(null, 'user-name')} />
+ : null
}
- <Input readonly={true} label="Domain" value={state['user-domain']} onChange={this.updateInput.bind(null, 'user-domain')}></Input>
-
- <Input type="radiogroup" readonly={state.isReadOnly} label="Disabled" value={state.disabled} options={[{value: true, label: 'YES'}, {value: false, label: 'NO'}]} onChange={this.disableChange} />
+ {
+ (!state.isEditUser || state.isReadOnly) ?
+ <Input className="userInfo-section" readonly={true} label="Domain" value={state['user-domain']} onChange={this.updateInput.bind(null, 'user-domain')}></Input>
+ : null
+ }
+ <Input className="userInfo-section"
+ type="radiogroup"
+ onChange={this.disableChange}
+ label="STATUS"
+ value={this.state.disabled}
+ options={[{label: "DISABLED", value: "TRUE"},{label: "ENABLED", value: "FALSE"}]}
+ readonly={state.isReadOnly}
+ readonlydisplay={this.state.disabled == "TRUE" ? "DISABLED" : "ENABLED"}
+ />
</FormSection>
<FormSection title="PLATFORM ROLES" style={{display:'none'}}>
<Input label="Super Admin" onChange={this.platformChange.bind(null, 'super_admin')} checked={state.platformRoles.super_admin} type="checkbox" />
<Input label="Platform Admin" onChange={this.platformChange.bind(null, 'platform_admin')} checked={state.platformRoles.platform_admin} type="checkbox" />
<Input label="Platform Oper" onChange={this.platformChange.bind(null, 'platform_oper')} checked={state.platformRoles.platform_oper} type="checkbox" />
</FormSection>
- <FormSection title="PROJECT ROLES" style={{display:'none'}}>
- <InputCollection
- inital={true}
- type='select'
- readonly={state.isReadOnly}
- options={state.projectRolesOptions}
- collection={state.projectRoles}
- onChange={this.updateProjectRole}
- AddItemFn={this.addProjectRole}
- RemoveItemFn={this.removeProjectRole}
- />
- </FormSection>
+ {
+ !state.isEditUser ?
+ <FormSection title="PROJECT ROLES">
+ <table className="userProfile-table">
+ <thead>
+ <tr>
+ <td>Project</td>
+ <td>Role</td>
+ </tr>
+ </thead>
+ <tbody>
+ {
+ this.state.projects && this.state.projects.ids && this.state.projects.ids.map((p,i)=> {
+ let project = self.state.projects.data[p];
+ let userRoles = [];
+ return (
+ <tr key={i}>
+ <td>
+ {p}
+ </td>
+ <td>
+ {
+ project.map(function(k) {
+ return <div>{k}</div>
+ })
+ }
+ </td>
+ </tr>
+ )
+ })
+ }
+ </tbody>
+ </table>
+ </FormSection>
+ : null
+ }
+
{passwordSectionHTML}
</Panel>