var React = require('react'); var ReactBootstrap = require('react-bootstrap'); var Button = ReactBootstrap.Button; var Collapse = ReactBootstrap.Collapse; var Glyphicon = ReactBootstrap.Glyphicon; class AccountTreeNode extends React.Component { constructor() { super(); this.state = {expanded: false}; this.onToggle = this.handleToggle.bind(this); this.onChildSelect = this.handleChildSelect.bind(this); this.onSelect = this.handleSelect.bind(this); } handleToggle(e) { e.preventDefault(); this.setState({expanded:!this.state.expanded}); } handleChildSelect(account) { if (this.props.onSelect != null) this.props.onSelect(account); } handleSelect() { if (this.props.onSelect != null) this.props.onSelect(this.props.account); } render() { var glyph = this.state.expanded ? 'minus' : 'plus'; var active = (this.props.selectedAccount != -1 && this.props.account.AccountId == this.props.selectedAccount); var self = this; var children = this.props.accountChildren[this.props.account.AccountId].map(function(childId) { var account = self.props.accounts[childId]; return ( ); }); var accounttreeClasses = "accounttree" var expandButton = []; if (children.length > 0) { expandButton.push(( )); } else { accounttreeClasses += "-nochildren"; } return (
{expandButton}
{children}
); } } class AccountTree extends React.Component { constructor() { super(); this.onSelect = this.handleSelect.bind(this); } handleSelect(account) { if (this.props.onSelectAccount != null) { this.props.onSelectAccount(account); } if (this.props.onSelect != null && this.props.onSelectKey != null) { this.props.onSelect(this.props.onSelectKey); } } render() { var accounts = this.props.accounts; var children = []; for (var accountId in accounts) { if (accounts.hasOwnProperty(accountId) && accounts[accountId].isRootAccount()) { children.push(()); } } return (
{children}
); } } module.exports = AccountTree;