Skip to content

Instantly share code, notes, and snippets.

@lukepolo
Last active February 7, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepolo/8b896887a24212462b7002eab5e722a6 to your computer and use it in GitHub Desktop.
Save lukepolo/8b896887a24212462b7002eab5e722a6 to your computer and use it in GitHub Desktop.
<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