Browse code

FEATWEBML-522 Fix: make MailComposeToolbar buttons work

kladier authored on 25/11/2019 16:31:20
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+export default {
2
+    methods: {
3
+        /** Navigate to the parent path: from a/b/c to a/b */
4
+        navigateToParent() {
5
+            const path = this.$router.history.current.path;
6
+            const parentPath = path.substring(0, path.lastIndexOf("/") + 1);
7
+            this.$router.push(parentPath);
8
+        }
9
+    }
10
+};
0 11
\ No newline at end of file
... ...
@@ -1,4 +1,5 @@
1 1
 import global from "@bluemind/global";
2
+import RouterMixin from "./RouterMixin";
2 3
 import VueRouter from "vue-router";
3 4
 import Vue from "vue";
4 5
 
... ...
@@ -9,3 +10,4 @@ const options = {
9 10
 Vue.use(VueRouter);
10 11
 
11 12
 export default global.$router || (global.$router = new VueRouter(options));
13
+export { RouterMixin };
12 14
\ No newline at end of file
... ...
@@ -118,6 +118,7 @@ import {
118 118
     BmRichEditor,
119 119
     BmRow
120 120
 } from "@bluemind/styleguide";
121
+import { RouterMixin } from "@bluemind/router";
121 122
 import debounce from "lodash/debounce";
122 123
 import MailMessageNewFooter from "./MailMessageNewFooter";
123 124
 import MailMessageNewModes from "./MailMessageNewModes";
... ...
@@ -138,6 +139,7 @@ export default {
138 139
         BmRow,
139 140
         MailMessageNewFooter
140 141
     },
142
+    mixins: [ RouterMixin ],
141 143
     props: {
142 144
         message: {
143 145
             type: Object,
... ...
@@ -261,12 +263,6 @@ export default {
261 263
             } else {
262 264
                 return this.lastRecipients;
263 265
             }
264
-        },
265
-        /** Navigate to the parent path: from a/b/c to a/b */
266
-        navigateToParent() {
267
-            const path = this.$router.history.current.path;
268
-            const parentPath = path.substring(0, path.lastIndexOf("/") + 1);
269
-            this.$router.push(parentPath);
270 266
         }
271 267
     }
272 268
 };
... ...
@@ -5,7 +5,8 @@
5 5
             variant="link"
6 6
             :aria-label="$tc('mail.actions.send.aria')"
7 7
             :title="$tc('mail.actions.send.aria')"
8
-            @click="send()"
8
+            :disabled="isSending || isDeleting"
9
+            @click="doSend()"
9 10
         >
10 11
             <bm-icon icon="send" size="2x" />
11 12
             {{ $tc("mail.actions.send") }}
... ...
@@ -15,6 +16,8 @@
15 16
             variant="link"
16 17
             :aria-label="$tc('mail.actions.save.aria')"
17 18
             :title="$tc('mail.actions.save.aria')"
19
+            :disabled="isSaving || isSending || isDeleting"
20
+            @click="saveDraft()"
18 21
         >
19 22
             <bm-icon icon="save" size="2x" />
20 23
             {{ $tc("mail.actions.save") }}
... ...
@@ -24,6 +27,8 @@
24 27
             variant="link"
25 28
             :aria-label="$tc('mail.actions.remove.compose.aria')"
26 29
             :title="$tc('mail.actions.remove.compose.aria')"
30
+            :disabled="isSaving || isSending || isDeleting"
31
+            @click="doDelete()"
27 32
         >
28 33
             <bm-icon icon="trash" size="2x" />
29 34
             {{ $tc("mail.actions.remove") }}
... ...
@@ -33,6 +38,7 @@
33 38
             variant="link"
34 39
             :aria-label="$tc('mail.actions.attach.aria')"
35 40
             :title="$tc('mail.actions.attach.aria')"
41
+            :disabled="isSending || isDeleting"
36 42
         >
37 43
             <bm-icon icon="paper-clip" size="2x" />
38 44
             {{ $tc("mail.actions.attach") }}
... ...
@@ -42,17 +48,41 @@
42 48
 
43 49
 <script>
44 50
 import { BmButton, BmIcon, BmTooltip } from "@bluemind/styleguide";
45
-import { mapActions } from "vuex";
51
+import { DraftStatus } from "@bluemind/backend.mail.store";
52
+import { mapActions, mapState } from "vuex";
53
+import { RouterMixin } from "@bluemind/router";
46 54
 
47 55
 export default {
48 56
     name: "MailToolbarComposeMessage",
49 57
     components: {
50 58
         BmButton,
51 59
         BmIcon
52
-    },    
60
+    },
53 61
     directives: { BmTooltip },
62
+    mixins: [ RouterMixin ],
63
+    computed: {
64
+        ...mapState("mail-webapp", ["draft"]),
65
+        isSending() {
66
+            return this.draft.status == DraftStatus.SENDING;
67
+        },
68
+        isSaving() {
69
+            return this.draft.status == DraftStatus.SAVING;
70
+        },
71
+        isDeleting() {
72
+            return this.draft.status == DraftStatus.DELETING;
73
+        },
74
+        errorOccuredOnSave() {
75
+            return this.draft.status == DraftStatus.SAVE_ERROR;
76
+        },
77
+    },
54 78
     methods: {
55
-        ...mapActions("mail-webapp", ["send"])
79
+        ...mapActions("mail-webapp", ["deleteDraft", "saveDraft", "send"]),
80
+        doDelete() {
81
+            this.deleteDraft().then(() => this.navigateToParent());
82
+        },
83
+        doSend() {
84
+            this.send().then(() => this.navigateToParent());
85
+        }
56 86
     }
57 87
 };
58 88
 </script>