/** * File: users.js * Author: Ricardo Hernandez-Montoya * Date: 02.05.2017 * * This file is part of VILLASweb. * * VILLASweb is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VILLASweb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VILLASweb. If not, see . ******************************************************************************/ import React, { Component } from 'react'; import { Container } from 'flux/utils'; import { Button, Modal, Glyphicon } from 'react-bootstrap'; import AppDispatcher from '../app-dispatcher'; import UserStore from '../stores/user-store'; import UsersStore from '../stores/users-store'; import Table from '../components/table'; import TableColumn from '../components/table-column'; import NewUserDialog from '../components/dialog/new-user'; import EditUserDialog from '../components/dialog/edit-user'; class Users extends Component { static getStores() { return [ UserStore, UsersStore ]; } static calculateState(prevState, props) { let tokenState = UserStore.getState().token; // If there is a token available and this method was called as a result of loading users if (!prevState && tokenState) { AppDispatcher.dispatch({ type: 'users/start-load', token: tokenState }); } return { token: tokenState, users: UsersStore.getState(), newModal: false, editModal: false, deleteModal: false, modalData: {} }; } closeNewModal(data) { this.setState({ newModal: false }); if (data) { AppDispatcher.dispatch({ type: 'users/start-add', data: data, token: this.state.token }); } } confirmDeleteModal() { this.setState({ deleteModal: false }); AppDispatcher.dispatch({ type: 'users/start-remove', data: this.state.modalData, token: this.state.token }); } closeEditModal(data) { this.setState({ editModal: false }); if (data) { AppDispatcher.dispatch({ type: 'users/start-edit', data: data, token: this.state.token }); } } getHumanRoleName(role_key) { const HUMAN_ROLE_NAMES = {admin: 'Administrator', user: 'User', guest: 'Guest'}; return HUMAN_ROLE_NAMES.hasOwnProperty(role_key)? HUMAN_ROLE_NAMES[role_key] : ''; } onModalKeyPress = (event) => { if (event.key === 'Enter') { event.preventDefault(); this.confirmDeleteModal(); } } render() { return (

Users

this.getHumanRoleName(role)} /> this.setState({ editModal: true, modalData: this.state.users[index] })} onDelete={index => this.setState({ deleteModal: true, modalData: this.state.users[index] })} />
this.closeNewModal(data)} /> this.closeEditModal(data)} user={this.state.modalData} /> this.setState({ deleteModal: falseĀ })} onKeyPress={this.onModalKeyPress}> Delete user Are you sure you want to delete the user '{this.state.modalData.username}'?
); } } export default Container.create(Users);