diff client/src/components/Userdetail.vue @ 376:e42f42eb9353

refactor: Userdetails refactored to card model Primitive user editing etd.
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 10 Aug 2018 13:15:32 +0200
parents 112527683ee9
children 0a9aaf21f69f
line wrap: on
line diff
--- a/client/src/components/Userdetail.vue	Fri Aug 10 11:21:58 2018 +0200
+++ b/client/src/components/Userdetail.vue	Fri Aug 10 13:15:32 2018 +0200
@@ -5,7 +5,7 @@
         {{ currentUser.user }}
       </div>
       <div class="card-body">
-        <form>
+        <form @submit.prevent="save">
           <div class="form-group">
             <label for="country">Country</label>
             <select v-model="currentUser.country">
@@ -48,11 +48,52 @@
 }
 </style>
 <script>
+import app from "../main";
+
 export default {
   name: "userdetail",
-  props: ["currentUser"],
-  data() {},
-  computed: {},
-  methods: {}
+  data() {
+    return {
+      currentUser: {},
+      path: null
+    };
+  },
+  watch: {
+    user() {
+      this.currentUser = { ...this.user };
+      this.path = this.user.name;
+    }
+  },
+  computed: {
+    user() {
+      return this.$store.getters["usermanagement/currentUser"];
+    }
+  },
+  methods: {
+    save() {
+      this.$store
+        .dispatch("usermanagement/saveCurrentUser", {
+          path: this.user.user,
+          user: this.currentUser
+        })
+        .then(() => {
+          this.$store.commit("usermanagement/clearCurrentUser");
+          this.$store.dispatch("usermanagement/loadUsers").catch(error => {
+            const { status, data } = error.response;
+            app.$toast.error({
+              title: "Backend Error",
+              message: `${status}: ${data}`
+            });
+          });
+        })
+        .catch(error => {
+          const { status, data } = error.response;
+          app.$toast.error({
+            title: "Error while saving user",
+            message: `${status}: ${data}`
+          });
+        });
+    }
+  }
 };
 </script>