parsley/app/javascript/components/TheLogEditor.vue

65 lines
1.4 KiB
Vue
Raw Normal View History

2018-04-13 10:25:18 -05:00
<template>
2018-04-15 14:15:42 -05:00
<div>
2018-04-13 10:25:18 -05:00
2018-04-15 14:15:42 -05:00
<log-edit v-if="log !== null" :log="log">
<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>
<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>
</div>
2018-04-13 10:25:18 -05:00
</template>
<script>
2018-04-15 14:15:42 -05:00
import { mapState } from "vuex";
import api from "../lib/Api";
import * as Errors from "../lib/Errors";
import LogEdit from "./LogEdit";
2018-04-13 10:25:18 -05:00
export default {
2018-04-15 14:15:42 -05:00
data() {
return {
validationErrors: [],
log: null
}
},
computed: {
...mapState({
logId: state => state.route.params.id,
})
},
methods: {
save() {
this.loadResource(
api.patchLog(this.log)
.then(() => this.$router.push('/'))
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
);
}
},
created() {
this.loadResource(
api.getLog(this.logId)
.then(data => { this.log = data; return data; })
);
},
2018-04-13 10:25:18 -05:00
2018-04-15 14:15:42 -05:00
components: {
LogEdit
}
2018-04-13 10:25:18 -05:00
}
</script>
<style lang="scss" scoped>
</style>