2018-04-01 21:43:23 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
|
2018-04-13 10:25:18 -05:00
|
|
|
<h1 class="title">Creating {{ 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" action="Creating"></recipe-edit>
|
|
|
|
|
2018-04-01 22:32:13 -05:00
|
|
|
<button type="button" class="button is-primary" @click="save">Save</button>
|
|
|
|
<router-link class="button is-secondary" to="/">Cancel</router-link>
|
|
|
|
|
2018-04-01 21:43:23 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import RecipeEdit from "./RecipeEdit";
|
|
|
|
import api from "../lib/Api";
|
2018-04-01 22:32:13 -05:00
|
|
|
import * as Errors from '../lib/Errors';
|
2018-04-01 21:43:23 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2018-06-09 12:36:46 -05:00
|
|
|
validationErrors: {},
|
2018-04-01 21:43:23 -05:00
|
|
|
recipe: {
|
|
|
|
name: null,
|
|
|
|
source: null,
|
|
|
|
description: null,
|
|
|
|
yields: null,
|
|
|
|
total_time: null,
|
|
|
|
active_time: null,
|
|
|
|
step_text: null,
|
|
|
|
tags: [],
|
|
|
|
ingredients: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-01 22:32:13 -05:00
|
|
|
methods: {
|
|
|
|
save() {
|
2018-06-09 12:36:46 -05:00
|
|
|
this.validationErrors = {};
|
2018-04-01 22:32:13 -05:00
|
|
|
this.loadResource(
|
|
|
|
api.postRecipe(this.recipe)
|
|
|
|
.then(() => this.$router.push('/'))
|
|
|
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-01 21:43:23 -05:00
|
|
|
components: {
|
|
|
|
RecipeEdit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|