parsley/app/javascript/components/TheLogCreator.vue

72 lines
1.6 KiB
Vue
Raw Permalink Normal View History

2018-04-13 10:25:18 -05:00
<template>
<div>
2018-06-09 12:36:46 -05:00
<log-edit v-if="log.recipe !== null" :log="log" :validation-errors="validationErrors">
2018-04-13 23:32:34 -05:00
<div class="buttons">
<button type="button" class="button is-primary" @click="save">Save Log</button>
<router-link class="button is-secondary" to="/">Cancel</router-link>
</div>
</log-edit>
2018-04-13 10:25:18 -05:00
2018-04-13 23:32:34 -05:00
<div class="buttons">
<button type="button" class="button is-primary" @click="save">Save Log</button>
<router-link class="button is-secondary" to="/">Cancel</router-link>
</div>
2018-04-13 10:25:18 -05:00
</div>
</template>
<script>
import LogEdit from "./LogEdit";
import { mapState } from "vuex";
import api from "../lib/Api";
import * as Errors from '../lib/Errors';
export default {
data() {
return {
2018-06-09 12:36:46 -05:00
validationErrors: {},
2018-04-13 10:25:18 -05:00
log: {
date: null,
rating: null,
notes: null,
recipe: null
}
}
},
computed: {
...mapState({
recipeId: state => state.route.params.recipeId,
})
},
methods: {
save() {
2018-04-13 23:32:34 -05:00
this.log.original_recipe_id = this.recipeId;
2018-06-09 12:36:46 -05:00
this.validationErrors = {};
2018-04-13 23:32:34 -05:00
2018-04-13 10:25:18 -05:00
this.loadResource(
api.postLog(this.log)
.then(() => this.$router.push('/'))
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
);
}
},
created() {
this.loadResource(
2018-06-09 12:36:46 -05:00
api.getRecipe(this.recipeId, null, null, null, data => this.log.recipe = data)
2018-04-13 10:25:18 -05:00
);
},
components: {
LogEdit
}
}
</script>
<style lang="scss" scoped>
</style>