mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 15:42:27 -05:00
Fixup transaction editing modal
* Only update the field that was modified when one is changed instead of deep-copying the entire Transaction object * Create a new AmountInput text box to allow for more intuitive editing of amounts.
This commit is contained in:
parent
770cd384a7
commit
01f0f9e68f
@ -71,6 +71,56 @@ const TransactionRow = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const AmountInput = React.createClass({
|
||||||
|
_getInitialState: function(props) {
|
||||||
|
// Ensure we can edit this without screwing up other copies of it
|
||||||
|
var a = props.value.toFixed(this.props.security.Precision);
|
||||||
|
return {
|
||||||
|
LastGoodAmount: a,
|
||||||
|
Amount: a
|
||||||
|
};
|
||||||
|
},
|
||||||
|
getInitialState: function() {
|
||||||
|
return this._getInitialState(this.props);
|
||||||
|
},
|
||||||
|
componentWillReceiveProps: function(nextProps) {
|
||||||
|
if (!nextProps.value.eq(this.props.value) && !nextProps.value.eq(this.getValue())) {
|
||||||
|
this.setState(this._getInitialState(nextProps));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
componentDidMount: function() {
|
||||||
|
this.refs.amount.getInputDOMNode().onblur = this.onBlur;
|
||||||
|
},
|
||||||
|
onBlur: function() {
|
||||||
|
this.setState({
|
||||||
|
Amount: (new Big(this.getValue())).toFixed(this.props.security.Precision)
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onChange: function() {
|
||||||
|
this.setState({Amount: this.refs.amount.getValue()});
|
||||||
|
if (this.props.onChange)
|
||||||
|
this.props.onChange();
|
||||||
|
},
|
||||||
|
getValue: function() {
|
||||||
|
try {
|
||||||
|
var value = this.refs.amount.getValue();
|
||||||
|
var ret = new Big(value);
|
||||||
|
this.setState({LastGoodAmount: value});
|
||||||
|
return ret;
|
||||||
|
} catch(err) {
|
||||||
|
return new Big(this.state.LastGoodAmount);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
render: function() {
|
||||||
|
return (
|
||||||
|
<Input type="text"
|
||||||
|
value={this.state.Amount}
|
||||||
|
onChange={this.onChange}
|
||||||
|
ref="amount"/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const AddEditTransactionModal = React.createClass({
|
const AddEditTransactionModal = React.createClass({
|
||||||
_getInitialState: function(props) {
|
_getInitialState: function(props) {
|
||||||
// Ensure we can edit this without screwing up other copies of it
|
// Ensure we can edit this without screwing up other copies of it
|
||||||
@ -80,66 +130,79 @@ const AddEditTransactionModal = React.createClass({
|
|||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return this._getInitialState(this.props);
|
return this._getInitialState(this.props);
|
||||||
},
|
},
|
||||||
|
componentWillReceiveProps: function(nextProps) {
|
||||||
|
if (nextProps.show && !this.props.show) {
|
||||||
|
this.setState(this._getInitialState(nextProps));
|
||||||
|
}
|
||||||
|
},
|
||||||
handleCancel: function() {
|
handleCancel: function() {
|
||||||
if (this.props.onCancel != null)
|
if (this.props.onCancel != null)
|
||||||
this.props.onCancel();
|
this.props.onCancel();
|
||||||
},
|
},
|
||||||
handleDescriptionChange: function() {
|
handleDescriptionChange: function() {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
|
||||||
transaction.Description = this.refs.description.getValue();
|
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: React.addons.update(this.state.transaction, {
|
||||||
|
Description: {$set: this.refs.description.getValue()}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleDateChange: function(date, string) {
|
handleDateChange: function(date, string) {
|
||||||
if (date == null)
|
if (date == null)
|
||||||
return;
|
return;
|
||||||
var transaction = this.state.transaction.deepCopy();
|
|
||||||
transaction.Date = date;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: React.addons.update(this.state.transaction, {
|
||||||
|
Date: {$set: date}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleStatusChange: function(status) {
|
handleStatusChange: function(status) {
|
||||||
if (status.hasOwnProperty('StatusId')) {
|
if (status.hasOwnProperty('StatusId')) {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
|
||||||
transaction.Status = status.StatusId;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: React.addons.update(this.state.transaction, {
|
||||||
|
Status: {$set: status.StatusId}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleDeleteSplit: function(split) {
|
handleDeleteSplit: function(split) {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
|
||||||
transaction.Splits.splice(split, 1);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: React.addons.update(this.state.transaction, {
|
||||||
|
Splits: {$splice: [[split, 1]]}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleUpdateNumber: function(split) {
|
handleUpdateNumber: function(split) {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
var transaction = this.state.transaction;
|
||||||
transaction.Splits[split].Number = this.refs['number-'+split].getValue();
|
transaction.Splits[split] = React.addons.update(transaction.Splits[split], {
|
||||||
|
Number: {$set: this.refs['number-'+split].getValue()}
|
||||||
|
});
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: transaction
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleUpdateMemo: function(split) {
|
handleUpdateMemo: function(split) {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
var transaction = this.state.transaction;
|
||||||
transaction.Splits[split].Memo = this.refs['memo-'+split].getValue();
|
transaction.Splits[split] = React.addons.update(transaction.Splits[split], {
|
||||||
|
Memo: {$set: this.refs['memo-'+split].getValue()}
|
||||||
|
});
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: transaction
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleUpdateAccount: function(account, split) {
|
handleUpdateAccount: function(account, split) {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
var transaction = this.state.transaction;
|
||||||
transaction.Splits[split].AccountId = account.AccountId;
|
transaction.Splits[split] = React.addons.update(transaction.Splits[split], {
|
||||||
|
AccountId: {$set: account.AccountId}
|
||||||
|
});
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: transaction
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleUpdateAmount: function(split) {
|
handleUpdateAmount: function(split) {
|
||||||
var transaction = this.state.transaction.deepCopy();
|
var transaction = this.state.transaction;
|
||||||
transaction.Splits[split].Amount = new Big(this.refs['amount-'+split].getValue());
|
transaction.Splits[split] = React.addons.update(transaction.Splits[split], {
|
||||||
|
Amount: {$set: new Big(this.refs['amount-'+split].getValue())}
|
||||||
|
});
|
||||||
this.setState({
|
this.setState({
|
||||||
transaction: transaction
|
transaction: transaction
|
||||||
});
|
});
|
||||||
@ -152,11 +215,6 @@ const AddEditTransactionModal = React.createClass({
|
|||||||
if (this.props.onDelete != null)
|
if (this.props.onDelete != null)
|
||||||
this.props.onDelete(this.state.transaction);
|
this.props.onDelete(this.state.transaction);
|
||||||
},
|
},
|
||||||
componentWillReceiveProps: function(nextProps) {
|
|
||||||
if (nextProps.show && !this.props.show) {
|
|
||||||
this.setState(this._getInitialState(nextProps));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var editing = this.props.transaction != null && this.props.transaction.isTransaction();
|
var editing = this.props.transaction != null && this.props.transaction.isTransaction();
|
||||||
var headerText = editing ? "Edit" : "Create New";
|
var headerText = editing ? "Edit" : "Create New";
|
||||||
@ -172,6 +230,7 @@ const AddEditTransactionModal = React.createClass({
|
|||||||
for (var i = 0; i < this.state.transaction.Splits.length; i++) {
|
for (var i = 0; i < this.state.transaction.Splits.length; i++) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var s = this.state.transaction.Splits[i];
|
var s = this.state.transaction.Splits[i];
|
||||||
|
var security = this.props.security_map[this.props.account_map[s.AccountId].SecurityId];
|
||||||
|
|
||||||
// Define all closures for calling split-updating functions
|
// Define all closures for calling split-updating functions
|
||||||
var deleteSplitFn = (function() {
|
var deleteSplitFn = (function() {
|
||||||
@ -223,8 +282,9 @@ const AddEditTransactionModal = React.createClass({
|
|||||||
includeRoot={false}
|
includeRoot={false}
|
||||||
onSelect={updateAccountFn}
|
onSelect={updateAccountFn}
|
||||||
ref={"account-"+i} /></Col>
|
ref={"account-"+i} /></Col>
|
||||||
<Col xs={2}><Input type="text"
|
<Col xs={2}><AmountInput type="text"
|
||||||
value={s.Amount}
|
value={s.Amount}
|
||||||
|
security={security}
|
||||||
onChange={updateAmountFn}
|
onChange={updateAmountFn}
|
||||||
ref={"amount-"+i} /></Col>
|
ref={"amount-"+i} /></Col>
|
||||||
{deleteSplitButton}
|
{deleteSplitButton}
|
||||||
@ -444,7 +504,6 @@ const AccountRegister = React.createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteTransaction: function(transaction) {
|
deleteTransaction: function(transaction) {
|
||||||
console.log("handleDeleteTransaction", transaction);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@ -542,7 +601,8 @@ const AccountRegister = React.createClass({
|
|||||||
onCancel={this.handleEditingCancel}
|
onCancel={this.handleEditingCancel}
|
||||||
onSubmit={this.handleUpdateTransaction}
|
onSubmit={this.handleUpdateTransaction}
|
||||||
onDelete={this.handleDeleteTransaction}
|
onDelete={this.handleDeleteTransaction}
|
||||||
securities={this.props.securities}/>
|
securities={this.props.securities}
|
||||||
|
security_map={this.props.security_map}/>
|
||||||
<div className="transactions-register-toolbar">
|
<div className="transactions-register-toolbar">
|
||||||
Transactions for '{name}'
|
Transactions for '{name}'
|
||||||
<ButtonToolbar className="pull-right">
|
<ButtonToolbar className="pull-right">
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react-with-addons.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/0.1.1/globalize.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/0.1.1/globalize.min.js"></script>
|
||||||
<script src="static/external/react-bootstrap/react-bootstrap.min.js"></script>
|
<script src="static/external/react-bootstrap/react-bootstrap.min.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user