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