2016-02-12 20:36:59 -05:00
|
|
|
var React = require('react');
|
|
|
|
var ReactDOM = require('react-dom');
|
2015-07-03 09:33:45 -04:00
|
|
|
|
2016-02-12 20:36:59 -05:00
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
2015-07-04 08:28:09 -04:00
|
|
|
var Grid = ReactBootstrap.Grid;
|
|
|
|
var Row = ReactBootstrap.Row;
|
|
|
|
var Col = ReactBootstrap.Col;
|
2016-09-27 11:30:39 -04:00
|
|
|
var Form = ReactBootstrap.Form;
|
|
|
|
var FormGroup = ReactBootstrap.FormGroup;
|
|
|
|
var FormControl = ReactBootstrap.FormControl;
|
2016-09-27 11:57:35 -04:00
|
|
|
var Checkbox = ReactBootstrap.Checkbox;
|
2016-09-27 11:30:39 -04:00
|
|
|
var ControlLabel = ReactBootstrap.ControlLabel;
|
2015-07-04 08:28:09 -04:00
|
|
|
var Button = ReactBootstrap.Button;
|
|
|
|
var ButtonGroup = ReactBootstrap.ButtonGroup;
|
|
|
|
var Glyphicon = ReactBootstrap.Glyphicon;
|
2016-02-12 20:36:59 -05:00
|
|
|
var ListGroup = ReactBootstrap.ListGroup;
|
|
|
|
var ListGroupItem = ReactBootstrap.ListGroupItem;
|
2016-02-13 10:46:08 -05:00
|
|
|
var Alert = ReactBootstrap.Alert;
|
2016-02-12 20:36:59 -05:00
|
|
|
var Modal = ReactBootstrap.Modal;
|
|
|
|
var Collapse = ReactBootstrap.Collapse;
|
2017-05-31 21:04:01 -04:00
|
|
|
var Tabs = ReactBootstrap.Tabs;
|
|
|
|
var Tab = ReactBootstrap.Tab;
|
|
|
|
var Panel = ReactBootstrap.Panel;
|
2015-07-04 08:28:09 -04:00
|
|
|
|
2016-02-12 20:36:59 -05:00
|
|
|
var Combobox = require('react-widgets').Combobox;
|
2015-07-04 11:42:52 -04:00
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var models = require('../models');
|
2016-02-13 16:31:12 -05:00
|
|
|
var Security = models.Security;
|
|
|
|
var Account = models.Account;
|
2017-05-31 21:04:01 -04:00
|
|
|
var AccountType = models.AccountType;
|
2016-02-13 16:31:12 -05:00
|
|
|
var AccountTypeList = models.AccountTypeList;
|
|
|
|
|
2018-11-02 21:14:34 -04:00
|
|
|
var AccountTree = require('./AccountTree');
|
2016-10-05 13:45:09 -04:00
|
|
|
var AccountCombobox = require('./AccountCombobox');
|
|
|
|
var AccountRegister = require('./AccountRegister');
|
2018-11-02 21:14:34 -04:00
|
|
|
var AddEditAccountModal = require('./AddEditAccountModal');
|
2016-02-12 20:36:59 -05:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class DeleteAccountModal extends React.Component {
|
|
|
|
getInitialState(props) {
|
|
|
|
if (!props)
|
|
|
|
var accountid = -1;
|
|
|
|
else if (props.initialAccount != null)
|
|
|
|
var accountid = props.initialAccount.AccountId;
|
|
|
|
else if (props.accounts.length > 0)
|
|
|
|
var accountid = props.accounts[0].AccountId;
|
2015-07-04 21:11:00 -04:00
|
|
|
else
|
|
|
|
var accountid = -1;
|
2017-06-07 19:12:53 -04:00
|
|
|
|
|
|
|
return {
|
|
|
|
error: "",
|
2015-07-04 21:11:00 -04:00
|
|
|
accountid: accountid,
|
|
|
|
checked: false,
|
2017-06-07 19:12:53 -04:00
|
|
|
show: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getInitialState();
|
|
|
|
this.onCancel = this.handleCancel.bind(this);
|
|
|
|
this.onChange = this.handleChange.bind(this);
|
|
|
|
this.onCheckboxClick = this.handleCheckboxClick.bind(this);
|
|
|
|
this.onSubmit = this.handleSubmit.bind(this);
|
|
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.show && !this.props.show) {
|
|
|
|
this.setState(this.getInitialState(nextProps));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleCancel() {
|
2015-07-04 21:11:00 -04:00
|
|
|
if (this.props.onCancel != null)
|
|
|
|
this.props.onCancel();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleChange(account) {
|
2015-07-04 21:11:00 -04:00
|
|
|
this.setState({accountid: account.AccountId});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleCheckboxClick() {
|
2015-07-04 21:11:00 -04:00
|
|
|
this.setState({checked: !this.state.checked});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleSubmit() {
|
2016-10-05 13:36:47 -04:00
|
|
|
if (this.props.accounts.hasOwnProperty(this.state.accountid)) {
|
2015-07-04 21:11:00 -04:00
|
|
|
if (this.state.checked) {
|
|
|
|
if (this.props.onSubmit != null)
|
2016-10-05 13:36:47 -04:00
|
|
|
this.props.onSubmit(this.props.accounts[this.state.accountid]);
|
2015-07-04 21:11:00 -04:00
|
|
|
} else {
|
|
|
|
this.setState({error: "You must confirm you wish to delete this account."});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setState({error: "You must select an account."});
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2015-07-04 21:11:00 -04:00
|
|
|
var checkbox = [];
|
2016-10-05 13:36:47 -04:00
|
|
|
if (this.props.accounts.hasOwnProperty(this.state.accountid)) {
|
|
|
|
var parentAccountId = this.props.accounts[this.state.accountid].ParentAccountId;
|
2015-07-04 21:11:00 -04:00
|
|
|
var parentAccount = "will be deleted and any child accounts will become top-level accounts.";
|
|
|
|
if (parentAccountId != -1)
|
2016-10-05 13:36:47 -04:00
|
|
|
parentAccount = "and any child accounts will be re-parented to: " + this.props.accounts[parentAccountId].Name;
|
2015-07-04 21:11:00 -04:00
|
|
|
|
|
|
|
var warningString = "I understand that deleting this account cannot be undone and that all transactions " + parentAccount;
|
2016-09-27 11:57:35 -04:00
|
|
|
checkbox = (
|
|
|
|
<FormGroup>
|
|
|
|
<Col xsOffset={2} sm={10}>
|
|
|
|
<Checkbox
|
2016-09-27 11:30:39 -04:00
|
|
|
checked={this.state.checked ? "checked" : ""}
|
2017-06-07 19:12:53 -04:00
|
|
|
onClick={this.onCheckboxClick}>
|
2016-09-27 11:57:35 -04:00
|
|
|
{warningString}
|
|
|
|
</Checkbox>
|
|
|
|
</Col>
|
2016-09-27 11:30:39 -04:00
|
|
|
</FormGroup>);
|
2015-07-04 21:11:00 -04:00
|
|
|
}
|
|
|
|
var warning = [];
|
|
|
|
if (this.state.error.length != "") {
|
|
|
|
warning = (
|
|
|
|
<Alert bsStyle="danger"><strong>Error: </strong>{this.state.error}</Alert>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
2016-09-27 11:57:35 -04:00
|
|
|
show={this.props.show}
|
2017-06-07 19:12:53 -04:00
|
|
|
onHide={this.onCancel}
|
2016-09-27 11:57:35 -04:00
|
|
|
ref="modal">
|
2015-07-04 21:11:00 -04:00
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>Delete Account</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
|
|
|
{warning}
|
2017-06-07 19:12:53 -04:00
|
|
|
<Form horizontal onSubmit={this.onSubmit}>
|
2016-09-27 11:30:39 -04:00
|
|
|
<FormGroup>
|
2016-09-27 11:57:35 -04:00
|
|
|
<Col componentClass={ControlLabel} xs={2}>Delete Account</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<AccountCombobox
|
|
|
|
includeRoot={false}
|
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2016-09-27 11:57:35 -04:00
|
|
|
value={this.state.accountid}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onChange}/>
|
2016-09-27 11:57:35 -04:00
|
|
|
</Col>
|
2016-09-27 11:30:39 -04:00
|
|
|
</FormGroup>
|
2016-09-27 11:57:35 -04:00
|
|
|
{checkbox}
|
2016-09-27 11:30:39 -04:00
|
|
|
</Form>
|
2015-07-04 21:11:00 -04:00
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
|
|
|
<ButtonGroup className="pull-right">
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button onClick={this.onCancel} bsStyle="warning">Cancel</Button>
|
|
|
|
<Button onClick={this.onSubmit} bsStyle="success">Delete Account</Button>
|
2015-07-04 21:11:00 -04:00
|
|
|
</ButtonGroup>
|
|
|
|
</Modal.Footer>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
2015-07-04 21:11:00 -04:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class AccountsTab extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
2015-07-04 21:11:00 -04:00
|
|
|
creatingNewAccount: false,
|
2015-07-04 21:55:49 -04:00
|
|
|
editingAccount: false,
|
2015-07-04 21:11:00 -04:00
|
|
|
deletingAccount: false
|
2015-07-04 08:28:09 -04:00
|
|
|
};
|
2017-06-07 19:12:53 -04:00
|
|
|
this.onNewAccount = this.handleNewAccount.bind(this);
|
|
|
|
this.onEditAccount = this.handleEditAccount.bind(this);
|
|
|
|
this.onDeleteAccount = this.handleDeleteAccount.bind(this);
|
|
|
|
this.onCreationCancel = this.handleCreationCancel.bind(this);
|
|
|
|
this.onEditingCancel = this.handleEditingCancel.bind(this);
|
|
|
|
this.onDeletionCancel = this.handleDeletionCancel.bind(this);
|
|
|
|
this.onCreateAccount = this.handleCreateAccount.bind(this);
|
|
|
|
this.onUpdateAccount = this.handleUpdateAccount.bind(this);
|
|
|
|
this.onRemoveAccount = this.handleRemoveAccount.bind(this);
|
|
|
|
this.onAccountSelected = this.handleAccountSelected.bind(this);
|
|
|
|
}
|
|
|
|
handleNewAccount() {
|
2015-07-04 08:28:09 -04:00
|
|
|
this.setState({creatingNewAccount: true});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleEditAccount() {
|
2015-07-04 21:55:49 -04:00
|
|
|
this.setState({editingAccount: true});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDeleteAccount() {
|
2015-07-04 21:11:00 -04:00
|
|
|
this.setState({deletingAccount: true});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleCreationCancel() {
|
2015-07-04 08:28:09 -04:00
|
|
|
this.setState({creatingNewAccount: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleEditingCancel() {
|
2015-07-04 21:55:49 -04:00
|
|
|
this.setState({editingAccount: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleDeletionCancel() {
|
2015-07-04 21:11:00 -04:00
|
|
|
this.setState({deletingAccount: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleCreateAccount(account) {
|
2015-07-04 08:28:09 -04:00
|
|
|
if (this.props.onCreateAccount != null)
|
|
|
|
this.props.onCreateAccount(account);
|
|
|
|
this.setState({creatingNewAccount: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleUpdateAccount(account) {
|
2015-07-04 21:55:49 -04:00
|
|
|
if (this.props.onUpdateAccount != null)
|
|
|
|
this.props.onUpdateAccount(account);
|
|
|
|
this.setState({editingAccount: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleRemoveAccount(account) {
|
2015-07-04 21:11:00 -04:00
|
|
|
if (this.props.onDeleteAccount != null)
|
|
|
|
this.props.onDeleteAccount(account);
|
2016-10-05 13:36:47 -04:00
|
|
|
this.setState({deletingAccount: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleAccountSelected(account) {
|
2016-10-05 13:36:47 -04:00
|
|
|
this.props.onSelectAccount(account.AccountId);
|
2017-05-22 20:36:36 -04:00
|
|
|
this.props.onFetchTransactionPage(account, 20, 0);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2016-10-05 13:36:47 -04:00
|
|
|
var disabled = (this.props.selectedAccount == -1) ? true : false;
|
2015-07-03 09:33:45 -04:00
|
|
|
|
2016-10-05 13:36:47 -04:00
|
|
|
var selectedAccount = null;
|
|
|
|
if (this.props.accounts.hasOwnProperty(this.props.selectedAccount))
|
|
|
|
selectedAccount = this.props.accounts[this.props.selectedAccount];
|
2015-07-04 21:55:49 -04:00
|
|
|
|
2015-07-03 09:33:45 -04:00
|
|
|
return (
|
2015-07-07 20:18:09 -04:00
|
|
|
<Grid fluid className="fullheight"><Row className="fullheight">
|
|
|
|
<Col xs={2} className="fullheight account-column">
|
2015-07-04 21:55:49 -04:00
|
|
|
<AddEditAccountModal
|
2015-07-04 08:28:09 -04:00
|
|
|
show={this.state.creatingNewAccount}
|
2016-10-05 13:36:47 -04:00
|
|
|
initialParentAccount={selectedAccount}
|
2015-07-04 08:28:09 -04:00
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2017-06-07 19:12:53 -04:00
|
|
|
onCancel={this.onCreationCancel}
|
|
|
|
onSubmit={this.onCreateAccount}
|
2016-10-05 13:36:47 -04:00
|
|
|
security_list={this.props.security_list}/>
|
2015-07-04 21:55:49 -04:00
|
|
|
<AddEditAccountModal
|
|
|
|
show={this.state.editingAccount}
|
2016-10-05 13:36:47 -04:00
|
|
|
editAccount={selectedAccount}
|
2015-07-04 21:55:49 -04:00
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2017-06-07 19:12:53 -04:00
|
|
|
onCancel={this.onEditingCancel}
|
|
|
|
onSubmit={this.onUpdateAccount}
|
2016-10-05 13:36:47 -04:00
|
|
|
security_list={this.props.security_list}/>
|
2015-07-04 21:11:00 -04:00
|
|
|
<DeleteAccountModal
|
|
|
|
show={this.state.deletingAccount}
|
2016-10-05 13:36:47 -04:00
|
|
|
initialAccount={selectedAccount}
|
2015-07-04 21:11:00 -04:00
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2017-06-07 19:12:53 -04:00
|
|
|
onCancel={this.onDeletionCancel}
|
|
|
|
onSubmit={this.onRemoveAccount}/>
|
2015-07-04 11:42:52 -04:00
|
|
|
<AccountTree
|
2016-10-05 13:36:47 -04:00
|
|
|
accounts={this.props.accounts}
|
|
|
|
accountChildren={this.props.accountChildren}
|
|
|
|
selectedAccount={this.props.selectedAccount}
|
2017-06-07 19:12:53 -04:00
|
|
|
onSelect={this.onAccountSelected}/>
|
2015-07-07 20:18:09 -04:00
|
|
|
<ButtonGroup className="account-buttongroup">
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button onClick={this.onNewAccount} bsStyle="success">
|
2015-07-04 08:28:09 -04:00
|
|
|
<Glyphicon glyph='plus-sign' /></Button>
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button onClick={this.onEditAccount}
|
2015-07-04 21:55:49 -04:00
|
|
|
bsStyle="primary" disabled={disabled}>
|
2015-07-04 08:28:09 -04:00
|
|
|
<Glyphicon glyph='cog' /></Button>
|
2017-06-07 19:12:53 -04:00
|
|
|
<Button onClick={this.onDeleteAccount}
|
2015-07-04 21:55:49 -04:00
|
|
|
bsStyle="danger" disabled={disabled}>
|
2015-07-04 08:28:09 -04:00
|
|
|
<Glyphicon glyph='trash' /></Button>
|
|
|
|
</ButtonGroup>
|
2015-07-07 20:18:09 -04:00
|
|
|
</Col><Col xs={10} className="fullheight transactions-column">
|
2015-08-05 21:25:25 -04:00
|
|
|
<AccountRegister
|
2017-05-22 20:36:36 -04:00
|
|
|
pageSize={20}
|
2016-10-05 13:36:47 -04:00
|
|
|
selectedAccount={this.props.selectedAccount}
|
2015-08-05 21:25:25 -04:00
|
|
|
accounts={this.props.accounts}
|
2016-10-05 13:36:47 -04:00
|
|
|
accountChildren={this.props.accountChildren}
|
2017-05-22 20:36:36 -04:00
|
|
|
securities={this.props.securities}
|
2017-05-24 19:47:18 -04:00
|
|
|
transactions={this.props.transactions}
|
2017-05-22 20:36:36 -04:00
|
|
|
transactionPage={this.props.transactionPage}
|
2017-06-04 16:01:42 -04:00
|
|
|
imports={this.props.imports}
|
|
|
|
onFetchAllAccounts={this.props.onFetchAllAccounts}
|
2017-06-10 14:38:40 -04:00
|
|
|
onFetchAllSecurities={this.props.onFetchAllSecurities}
|
2017-05-24 19:47:18 -04:00
|
|
|
onCreateTransaction={this.props.onCreateTransaction}
|
|
|
|
onUpdateTransaction={this.props.onUpdateTransaction}
|
|
|
|
onDeleteTransaction={this.props.onDeleteTransaction}
|
|
|
|
onSelectTransaction={this.props.onSelectTransaction}
|
|
|
|
onUnselectTransaction={this.props.onUnselectTransaction}
|
2017-06-04 16:01:42 -04:00
|
|
|
onFetchTransactionPage={this.props.onFetchTransactionPage}
|
|
|
|
onOpenImportModal={this.props.onOpenImportModal}
|
|
|
|
onCloseImportModal={this.props.onCloseImportModal}
|
|
|
|
onImportOFX={this.props.onImportOFX}
|
|
|
|
onImportOFXFile={this.props.onImportOFXFile}
|
|
|
|
onImportGnucash={this.props.onImportGnucash} />
|
2015-07-04 08:28:09 -04:00
|
|
|
</Col>
|
|
|
|
</Row></Grid>
|
2015-07-03 09:33:45 -04:00
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AccountsTab;
|