|
|
|
@ -8,7 +8,7 @@ import Catalyst from 'react-catalyst';
|
|
|
|
|
import autobind from 'autobind-decorator'; |
|
|
|
|
import cx from 'classnames'; |
|
|
|
|
import parser from '../libs/parser'; |
|
|
|
|
import Moment from 'moment'; |
|
|
|
|
import moment from 'moment'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@autobind |
|
|
|
@ -23,7 +23,7 @@ class TxForm extends React.Component {
|
|
|
|
|
amount : this.parseEquation(this.refs.amount.value), |
|
|
|
|
currency : this.refs.currency.value, |
|
|
|
|
date : this.refs.date.value, |
|
|
|
|
account : this.refs.account.value, |
|
|
|
|
// account : this.refs.account.value,
|
|
|
|
|
note : this.refs.note.value |
|
|
|
|
} |
|
|
|
|
// 3. Add the tx to the App State
|
|
|
|
@ -57,14 +57,10 @@ class TxForm extends React.Component {
|
|
|
|
|
defaultTxState() { |
|
|
|
|
return { |
|
|
|
|
id: '', amount: '', currency: '', |
|
|
|
|
date: '2015-12-16', note: '' |
|
|
|
|
date: moment().format('YYYY-MM-DD'), note: '' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resetForm() { |
|
|
|
|
this.setState({tx: this.defaultTxState()}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
deleteItem() { |
|
|
|
|
var tx = { |
|
|
|
|
id : +this.refs.id.value |
|
|
|
@ -73,16 +69,26 @@ class TxForm extends React.Component {
|
|
|
|
|
this.refs.txForm.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resetForm() { |
|
|
|
|
this.refs.txForm.reset(); |
|
|
|
|
this.setState({tx: this.defaultTxState(), clearForm: true}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
this.state = this.state || {}; |
|
|
|
|
if (this.state.updated) { |
|
|
|
|
this.state.tx = this.state.updated; |
|
|
|
|
delete this.state["updated"]; |
|
|
|
|
} else { |
|
|
|
|
} else if (!this.state.clearForm) { |
|
|
|
|
this.state.tx = JSON.parse(JSON.stringify(this.props.tx)); |
|
|
|
|
} |
|
|
|
|
if (Object.keys(this.state.tx).length == 0) |
|
|
|
|
if (Object.keys(this.state.tx).length == 0) { |
|
|
|
|
this.state.tx = this.defaultTxState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.state.clearForm) { |
|
|
|
|
delete this.state["clearForm"]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var hasItem = ( (this.state.tx.id) ? true : false ); |
|
|
|
|
var delDisabledClassName = cx({ |
|
|
|
@ -130,15 +136,11 @@ class TxForm extends React.Component {
|
|
|
|
|
name="date" value={this.state.tx.date} onChange={this.handleChange} /> |
|
|
|
|
</div> |
|
|
|
|
<div className="small-12 medium-6 grid-content"> |
|
|
|
|
<select ref="account"> |
|
|
|
|
{this.props.accounts.map((account) => { |
|
|
|
|
var opts = { value: account.id }; |
|
|
|
|
return ( |
|
|
|
|
<option {...opts} key={account.id}> |
|
|
|
|
{account.title} ({account.currency})</option> |
|
|
|
|
) |
|
|
|
|
})} |
|
|
|
|
</select> |
|
|
|
|
<div className="small switch"> |
|
|
|
|
<input type="checkbox" id="switch-example" name="income" |
|
|
|
|
checked onChange={this.handleChange}/> |
|
|
|
|
<label></label> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div className="grid-block"> |
|
|
|
@ -150,9 +152,11 @@ class TxForm extends React.Component {
|
|
|
|
|
<div className="grid-block"> |
|
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
|
<input type="hidden" ref="id" value={this.state.tx.id} /> |
|
|
|
|
<button type="submit" className="success button">+ {( (this.state.tx.id) ? "Edit" : "Add" )} Tx</button> |
|
|
|
|
<button onClick={this.resetForm} className="default button">Reset</button> |
|
|
|
|
<button onClick={this.deleteItem} className={delDisabledClassName} disabled={!hasItem}>- Remove Tx</button> |
|
|
|
|
<button type="submit" className="success button"> |
|
|
|
|
+ {( (this.state.tx.id) ? "Edit" : "Add" )} Tx</button> |
|
|
|
|
<a onClick={this.resetForm} className="default button">Reset</a> |
|
|
|
|
<a onClick={this.deleteItem} className={delDisabledClassName} |
|
|
|
|
disabled={!hasItem}>- Remove Tx</a> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</form> |
|
|
|
|