mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 23:42:29 -05:00
Add ability to update accounts to UI
This commit is contained in:
parent
0377b5f42b
commit
5be612cee8
@ -38,14 +38,15 @@ const AccountCombobox = React.createClass({
|
|||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
includeRoot: true,
|
includeRoot: true,
|
||||||
rootName: "New Root Account"
|
rootName: "New Top-level Account"
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleAccountChange: function(account) {
|
handleAccountChange: function(account) {
|
||||||
if (this.props.onSelect != null &&
|
if (this.props.onSelect != null &&
|
||||||
account.hasOwnProperty('AccountId') &&
|
account.hasOwnProperty('AccountId') &&
|
||||||
this.props.account_map.hasOwnProperty([account.AccountId])) {
|
(this.props.account_map.hasOwnProperty([account.AccountId]) ||
|
||||||
this.props.onSelect(this.props.account_map[account.AccountId])
|
account.AccountId == -1)) {
|
||||||
|
this.props.onSelect(account)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
@ -62,27 +63,31 @@ const AccountCombobox = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const NewAccountModal = React.createClass({
|
const AddEditAccountModal = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
var security = 1;
|
var s = {
|
||||||
var parentaccountid = -1;
|
accountid: -1,
|
||||||
var type = 1;
|
security: 1,
|
||||||
if (this.props.initialParentAccount != null) {
|
parentaccountid: -1,
|
||||||
security = this.props.initialParentAccount.SecurityId;
|
type: 1,
|
||||||
parentaccountid = this.props.initialParentAccount.AccountId;
|
|
||||||
type = this.props.initialParentAccount.Type;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
security: security,
|
|
||||||
parentaccountid: parentaccountid,
|
|
||||||
type: type,
|
|
||||||
name: ""
|
name: ""
|
||||||
};
|
};
|
||||||
|
if (this.props.editAccount != null) {
|
||||||
|
s.accountid = this.props.editAccount.AccountId;
|
||||||
|
s.name = this.props.editAccount.Name;
|
||||||
|
s.security = this.props.editAccount.SecurityId;
|
||||||
|
s.parentaccountid = this.props.editAccount.ParentAccountId;
|
||||||
|
s.type = this.props.editAccount.Type;
|
||||||
|
} else if (this.props.initialParentAccount != null) {
|
||||||
|
s.security = this.props.initialParentAccount.SecurityId;
|
||||||
|
s.parentaccountid = this.props.initialParentAccount.AccountId;
|
||||||
|
s.type = this.props.initialParentAccount.Type;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
},
|
},
|
||||||
handleCancel: function() {
|
handleCancel: function() {
|
||||||
if (this.props.onCancel != null)
|
if (this.props.onCancel != null)
|
||||||
this.props.onCancel();
|
this.props.onCancel();
|
||||||
this.setState(this.getInitialState());
|
|
||||||
},
|
},
|
||||||
handleChange: function() {
|
handleChange: function() {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -107,17 +112,15 @@ const NewAccountModal = React.createClass({
|
|||||||
handleSubmit: function() {
|
handleSubmit: function() {
|
||||||
var a = new Account();
|
var a = new Account();
|
||||||
|
|
||||||
|
if (this.props.editAccount != null)
|
||||||
|
a.AccountId = this.state.accountid;
|
||||||
a.Name = this.state.name;
|
a.Name = this.state.name;
|
||||||
a.ParentAccountId = this.state.parentaccountid;
|
a.ParentAccountId = this.state.parentaccountid;
|
||||||
a.SecurityId = this.state.security;
|
a.SecurityId = this.state.security;
|
||||||
a.Type = this.state.type;
|
a.Type = this.state.type;
|
||||||
|
|
||||||
this.handleSaveSettings(a);
|
|
||||||
this.setState(this.getInitialState());
|
|
||||||
},
|
|
||||||
handleSaveSettings: function(account) {
|
|
||||||
if (this.props.onSubmit != null)
|
if (this.props.onSubmit != null)
|
||||||
this.props.onSubmit(account);
|
this.props.onSubmit(a);
|
||||||
},
|
},
|
||||||
componentWillReceiveProps: function(nextProps) {
|
componentWillReceiveProps: function(nextProps) {
|
||||||
if (nextProps.show && !this.props.show) {
|
if (nextProps.show && !this.props.show) {
|
||||||
@ -125,10 +128,12 @@ const NewAccountModal = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
var headerText = (this.props.editAccount != null) ? "Edit" : "Create New";
|
||||||
|
var rootName = (this.props.editAccount != null) ? "Top-level Account" : "New Top-level Account";
|
||||||
return (
|
return (
|
||||||
<Modal show={this.props.show} onHide={this.handleCancel}>
|
<Modal show={this.props.show} onHide={this.handleCancel}>
|
||||||
<Modal.Header closeButton>
|
<Modal.Header closeButton>
|
||||||
<Modal.Title>Create New Account</Modal.Title>
|
<Modal.Title>{headerText} Account</Modal.Title>
|
||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
<form onSubmit={this.handleSubmit}
|
<form onSubmit={this.handleSubmit}
|
||||||
@ -148,6 +153,7 @@ const NewAccountModal = React.createClass({
|
|||||||
accounts={this.props.accounts}
|
accounts={this.props.accounts}
|
||||||
account_map={this.props.account_map}
|
account_map={this.props.account_map}
|
||||||
value={this.state.parentaccountid}
|
value={this.state.parentaccountid}
|
||||||
|
rootName={rootName}
|
||||||
onSelect={this.handleParentChange}
|
onSelect={this.handleParentChange}
|
||||||
ref="parent" />
|
ref="parent" />
|
||||||
</Input>
|
</Input>
|
||||||
@ -388,6 +394,7 @@ const AccountsTab = React.createClass({
|
|||||||
return {
|
return {
|
||||||
selectedAccount: null,
|
selectedAccount: null,
|
||||||
creatingNewAccount: false,
|
creatingNewAccount: false,
|
||||||
|
editingAccount: false,
|
||||||
deletingAccount: false
|
deletingAccount: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -395,7 +402,7 @@ const AccountsTab = React.createClass({
|
|||||||
this.setState({creatingNewAccount: true});
|
this.setState({creatingNewAccount: true});
|
||||||
},
|
},
|
||||||
handleEditAccount: function() {
|
handleEditAccount: function() {
|
||||||
console.log("handleEditAccount");
|
this.setState({editingAccount: true});
|
||||||
},
|
},
|
||||||
handleDeleteAccount: function() {
|
handleDeleteAccount: function() {
|
||||||
this.setState({deletingAccount: true});
|
this.setState({deletingAccount: true});
|
||||||
@ -403,6 +410,9 @@ const AccountsTab = React.createClass({
|
|||||||
handleCreationCancel: function() {
|
handleCreationCancel: function() {
|
||||||
this.setState({creatingNewAccount: false});
|
this.setState({creatingNewAccount: false});
|
||||||
},
|
},
|
||||||
|
handleEditingCancel: function() {
|
||||||
|
this.setState({editingAccount: false});
|
||||||
|
},
|
||||||
handleDeletionCancel: function() {
|
handleDeletionCancel: function() {
|
||||||
this.setState({deletingAccount: false});
|
this.setState({deletingAccount: false});
|
||||||
},
|
},
|
||||||
@ -411,10 +421,16 @@ const AccountsTab = React.createClass({
|
|||||||
this.props.onCreateAccount(account);
|
this.props.onCreateAccount(account);
|
||||||
this.setState({creatingNewAccount: false});
|
this.setState({creatingNewAccount: false});
|
||||||
},
|
},
|
||||||
|
handleUpdateAccount: function(account) {
|
||||||
|
if (this.props.onUpdateAccount != null)
|
||||||
|
this.props.onUpdateAccount(account);
|
||||||
|
this.setState({editingAccount: false});
|
||||||
|
},
|
||||||
handleRemoveAccount: function(account) {
|
handleRemoveAccount: function(account) {
|
||||||
if (this.props.onDeleteAccount != null)
|
if (this.props.onDeleteAccount != null)
|
||||||
this.props.onDeleteAccount(account);
|
this.props.onDeleteAccount(account);
|
||||||
this.setState({deletingAccount: false});
|
this.setState({deletingAccount: false,
|
||||||
|
selectedAccount: null});
|
||||||
},
|
},
|
||||||
handleAccountSelected: function(account) {
|
handleAccountSelected: function(account) {
|
||||||
this.setState({selectedAccount: account});
|
this.setState({selectedAccount: account});
|
||||||
@ -423,10 +439,12 @@ const AccountsTab = React.createClass({
|
|||||||
var accounts = this.props.accounts;
|
var accounts = this.props.accounts;
|
||||||
var account_map = this.props.account_map;
|
var account_map = this.props.account_map;
|
||||||
|
|
||||||
|
var disabled = (this.state.selectedAccount == null) ? "disabled" : "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid fluid><Row>
|
<Grid fluid><Row>
|
||||||
<Col xs={2}>
|
<Col xs={2}>
|
||||||
<NewAccountModal
|
<AddEditAccountModal
|
||||||
show={this.state.creatingNewAccount}
|
show={this.state.creatingNewAccount}
|
||||||
initialParentAccount={this.state.selectedAccount}
|
initialParentAccount={this.state.selectedAccount}
|
||||||
accounts={this.props.accounts}
|
accounts={this.props.accounts}
|
||||||
@ -434,6 +452,14 @@ const AccountsTab = React.createClass({
|
|||||||
onCancel={this.handleCreationCancel}
|
onCancel={this.handleCreationCancel}
|
||||||
onSubmit={this.handleCreateAccount}
|
onSubmit={this.handleCreateAccount}
|
||||||
securities={this.props.securities}/>
|
securities={this.props.securities}/>
|
||||||
|
<AddEditAccountModal
|
||||||
|
show={this.state.editingAccount}
|
||||||
|
editAccount={this.state.selectedAccount}
|
||||||
|
accounts={this.props.accounts}
|
||||||
|
account_map={this.props.account_map}
|
||||||
|
onCancel={this.handleEditingCancel}
|
||||||
|
onSubmit={this.handleUpdateAccount}
|
||||||
|
securities={this.props.securities}/>
|
||||||
<DeleteAccountModal
|
<DeleteAccountModal
|
||||||
show={this.state.deletingAccount}
|
show={this.state.deletingAccount}
|
||||||
initialAccount={this.state.selectedAccount}
|
initialAccount={this.state.selectedAccount}
|
||||||
@ -447,9 +473,11 @@ const AccountsTab = React.createClass({
|
|||||||
<ButtonGroup className="pull-right">
|
<ButtonGroup className="pull-right">
|
||||||
<Button onClick={this.handleNewAccount} bsStyle="success">
|
<Button onClick={this.handleNewAccount} bsStyle="success">
|
||||||
<Glyphicon glyph='plus-sign' /></Button>
|
<Glyphicon glyph='plus-sign' /></Button>
|
||||||
<Button onClick={this.handleEditAccount} bsStyle="primary">
|
<Button onClick={this.handleEditAccount}
|
||||||
|
bsStyle="primary" disabled={disabled}>
|
||||||
<Glyphicon glyph='cog' /></Button>
|
<Glyphicon glyph='cog' /></Button>
|
||||||
<Button onClick={this.handleDeleteAccount} bsStyle="danger">
|
<Button onClick={this.handleDeleteAccount}
|
||||||
|
bsStyle="danger" disabled={disabled}>
|
||||||
<Glyphicon glyph='trash' /></Button>
|
<Glyphicon glyph='trash' /></Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</Col><Col xs={10}>
|
</Col><Col xs={10}>
|
||||||
|
Loading…
Reference in New Issue
Block a user