parsley/app/javascript/components/TheFoodCreator.vue

77 lines
1.7 KiB
Vue
Raw Permalink Normal View History

2018-04-02 00:10:06 -05:00
<template>
<div>
2018-09-11 22:56:26 -05:00
<food-edit :food="food" :validation-errors="validationErrors" action="Creating"></food-edit>
2018-04-02 00:10:06 -05:00
<button type="button" class="button is-primary" @click="save">Save</button>
2018-09-11 22:56:26 -05:00
<router-link class="button is-secondary" to="/food">Cancel</router-link>
2018-04-02 00:10:06 -05:00
</div>
</template>
<script>
2018-09-11 22:56:26 -05:00
import FoodEdit from "./FoodEdit";
2018-04-02 00:10:06 -05:00
import { mapState } from "vuex";
import api from "../lib/Api";
import * as Errors from '../lib/Errors';
export default {
data() {
return {
2018-09-11 22:56:26 -05:00
food: {
2018-04-03 18:31:20 -05:00
name: null,
notes: null,
ndbn: null,
density: null,
water: null,
ash: null,
protein: null,
kcal: null,
fiber: null,
sugar: null,
carbohydrates: null,
calcium: null,
iron: null,
magnesium: null,
phosphorus: null,
potassium: null,
sodium: null,
zinc: null,
copper: null,
manganese: null,
vit_c: null,
vit_b6: null,
vit_b12: null,
vit_a: null,
vit_e: null,
vit_d: null,
vit_k: null,
cholesterol: null,
lipids: null,
2018-09-11 22:56:26 -05:00
food_units: []
2018-04-02 00:10:06 -05:00
},
2018-06-09 12:36:46 -05:00
validationErrors: {}
2018-04-02 00:10:06 -05:00
}
},
methods: {
save() {
2018-06-09 12:36:46 -05:00
this.validationErrors = {}
2018-04-02 00:10:06 -05:00
this.loadResource(
2018-09-11 22:56:26 -05:00
api.postFood(this.food)
.then(() => this.$router.push('/foods'))
2018-04-02 00:10:06 -05:00
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
);
}
},
components: {
2018-09-11 22:56:26 -05:00
FoodEdit
2018-04-02 00:10:06 -05:00
}
}
</script>
<style lang="scss" scoped>
</style>