parsley/app/javascript/components/TheLogEditor.vue

56 lines
1.5 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-06-09 12:36:46 -05:00
<log-edit v-if="log !== null" :log="log" :validation-errors="validationErrors">
2018-04-15 14:15:42 -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>
<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>
2024-10-02 14:34:50 -05:00
<script setup>
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
import { computed, onBeforeMount, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
2018-04-15 14:15:42 -05:00
import api from "../lib/Api";
import * as Errors from "../lib/Errors";
import LogEdit from "./LogEdit";
2024-10-02 14:34:50 -05:00
import { useLoadResource } from "../lib/useLoadResource";
const { loadResource } = useLoadResource();
const route = useRoute();
const router = useRouter();
const validationErrors = ref({});
const log = ref(null);
const logId = computed(() => route.params.id);
onBeforeMount(() => {
loadResource(
api.getLog(logId.value)
.then(data => { log.value = data; return data; })
);
});
function save() {
validationErrors.value = {};
loadResource(
api.patchLog(log.value)
.then(() => router.push('/'))
.catch(Errors.onlyFor(Errors.ApiValidationError, err => validationErrors.value = err.validationErrors()))
);
2018-04-13 10:25:18 -05:00
}
</script>
<style lang="scss" scoped>
</style>