summaryrefslogtreecommitdiff
path: root/pages/models
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-23 21:04:03 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-09-23 21:04:03 +0200
commit6164e98a11c2437fd6258672ad7fd636d2b66574 (patch)
treeca19d834b0afcf2a9ad787ad5e0310abebf3ecb9 /pages/models
parent503fb2b362da8cf5541ac9a7fc879593e64de7f4 (diff)
Edit model using a component for the same form
Diffstat (limited to 'pages/models')
-rw-r--r--pages/models/_id/edit.vue50
-rw-r--r--pages/models/_id/index.vue3
2 files changed, 52 insertions, 1 deletions
diff --git a/pages/models/_id/edit.vue b/pages/models/_id/edit.vue
new file mode 100644
index 0000000..45755be
--- /dev/null
+++ b/pages/models/_id/edit.vue
@@ -0,0 +1,50 @@
+<template lang="pug">
+ .mx-auto.w-90p.py-6#modelpage(class="sm:px-6 lg:px-8 md:max-w-7xl")
+ h1.text-3xl.font-bold Edit {{ model.name }}
+ model-form(:data="model" v-if="model.id")
+</template>
+
+<script>
+import { mapGetters } from "vuex";
+
+export default {
+ name: "ModelEditView",
+ layout: "default",
+ data() {
+ return {
+ model: {},
+ };
+ },
+ head() {
+ return {
+ title: "Modifica " + this.model.name + " ยท Verden",
+ };
+ },
+ components: {},
+ computed: {
+ ...mapGetters(["isLoading"]),
+ ...mapGetters("auth", ["isLogged", "me"]),
+ },
+ async created() {
+ this.id = this.$route.params.id;
+ this.baseAPI = this.$config.api;
+
+ if (!this.isLogged) {
+ window.location.href = "/models/" + this.id;
+ } else {
+ await this.$store.dispatch("auth/findMe");
+ this.$store.dispatch("models/findModel", this.id).then((response) => {
+ if (response.status != 200) {
+ window.location.href = "/models";
+ } else {
+ this.model = response.data;
+ if (!(this.model.author_id == this.me.id || this.me.is_staff)) {
+ window.location.href = "/models/" + this.id;
+ }
+ }
+ });
+ }
+ },
+ methods: {},
+};
+</script>
diff --git a/pages/models/_id/index.vue b/pages/models/_id/index.vue
index 909d5d9..1bb322e 100644
--- a/pages/models/_id/index.vue
+++ b/pages/models/_id/index.vue
@@ -50,8 +50,9 @@
p {{ model.description }}
.mb-5.text-right(v-if="me && me.id == model.author_id")
- button.inline-flex.leading-6.justify-center.rounded-md.border.border-transparent.bg-gray-600.py-2.px-4.mr-2.text-sm.font-medium.text-white.shadow-sm(
+ a.inline-flex.leading-6.justify-center.rounded-md.border.border-transparent.bg-gray-600.py-2.px-4.mr-2.text-sm.font-medium.text-white.shadow-sm(
class="hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2"
+ :href="'/models/'+model.id+'/edit'"
)
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125" />