parsley/app/javascript/components/TheRecipeEditor.vue

67 lines
1.5 KiB
Vue
Raw Normal View History

2018-04-01 21:43:23 -05:00
<template>
<div>
<div v-if="recipe === null">
Loading...
</div>
<div v-else>
2018-04-13 10:25:18 -05:00
<h1 class="title">Editing {{ recipe.name || "[Unamed Recipe]" }}</h1>
2018-06-09 12:36:46 -05:00
<app-validation-errors :errors="validationErrors"></app-validation-errors>
2018-04-01 21:43:23 -05:00
<recipe-edit :recipe="recipe"></recipe-edit>
</div>
<button type="button" class="button is-primary" @click="save">Save</button>
<router-link class="button is-secondary" to="/">Cancel</router-link>
</div>
</template>
<script>
import RecipeEdit from "./RecipeEdit";
import { mapState } from "vuex";
import api from "../lib/Api";
import * as Errors from '../lib/Errors';
export default {
data: function () {
return {
recipe: null,
2018-06-09 12:36:46 -05:00
validationErrors: {}
2018-04-01 21:43:23 -05:00
}
},
computed: {
...mapState({
recipeId: state => state.route.params.id,
})
},
methods: {
save() {
2018-06-09 12:36:46 -05:00
this.validationErrors = {};
2018-04-01 21:43:23 -05:00
this.loadResource(
api.patchRecipe(this.recipe)
.then(() => this.$router.push({name: 'recipe', params: {id: this.recipeId }}))
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
);
}
},
created() {
this.loadResource(
2018-05-01 10:55:57 -05:00
api.getRecipe(this.recipeId, null, null, null, data => { this.recipe = data; return data; })
2018-04-01 21:43:23 -05:00
);
},
components: {
RecipeEdit
}
}
</script>
<style lang="scss" scoped>
</style>