Last active
February 7, 2017 14:13
-
-
Save lukepolo/8b896887a24212462b7002eab5e722a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import Form from '../../../libraries/form.js'; | |
export default { | |
created() { | |
if ( !Object.keys(this.$store.getters.businesses).length ) | |
this.$store.dispatch('getBusinesses') | |
}, | |
data() { | |
return { | |
disableButtons: false | |
} | |
}, | |
methods: { | |
onSubmit() { | |
this.disableButtons = true; | |
let action = this.expense ? 'updateExpense' : 'createExpense'; | |
let current = this.expense ? this.expense.id : null; | |
this.$store.dispatch(action, {'data': this.form.data(), 'expenseID': current}) | |
.then(response => { | |
this.form.onSuccess(response.data); | |
this.disableButtons = false; | |
var destination = this.expense ? response.data.expense.url : '/expenses'; | |
this.$router.push(destination); | |
}) | |
.catch(error => { | |
this.form.onFail(error.response.data); | |
this.disableButtons = false; | |
}); | |
} | |
}, | |
computed: { | |
form() { | |
if (this.expense = this.$store.getters.currentExpense){ | |
return new Form(this.expense); | |
} | |
return new Form({ | |
'business_id': '', | |
'title': '', | |
'description': '', | |
'amount': '', | |
'date': '', | |
'location': '', | |
'currency_id': '1' | |
}); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment