From 6164e98a11c2437fd6258672ad7fd636d2b66574 Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Fri, 23 Sep 2022 21:04:03 +0200
Subject: Edit model using a component for the same form

---
 pages/models/_id/edit.vue | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 pages/models/_id/edit.vue

(limited to 'pages/models/_id/edit.vue')

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>
-- 
cgit v1.2.3-18-g5258

