22 <div class =" sc-message--text" :style =" messageColors" >
33 <template >
44 <div class =" sc-message--toolbox" :style =" {background: messageColors.backgroundColor}" >
5- <button
6- v-if =" showEdition && me && message.id != null && message.id != undefined"
7- :disabled =" isEditing"
8- @click =" edit"
9- >
10- <IconBase :color =" isEditing ? 'black' : messageColors.color" width =" 10" icon-name =" edit" >
5+ <button v-if =" showEdition && me && message.id" @click =" edit" :disabled =" isEditing" >
6+ <IconBase :color =" isEditing? 'black': messageColors.color" width =" 10" icon-name =" edit" >
117 <IconEdit />
128 </IconBase >
139 </button >
14- <button
15- v-if =" showDeletion && me && message.id != null && message.id != undefined"
16- @click =" $emit('remove')"
17- >
18- <IconBase :color =" messageColors.color" width =" 10" icon-name =" remove" >
19- <IconCross />
20- </IconBase >
21- </button >
10+ <div v-if =" showDeletion" >
11+ <button v-if =" me && message.id != null && message.id != undefined" @click =" ifelse(showConfirmationDeletion, withConfirm('Do you really want to delete the message?', () => $emit('remove')), () => $emit('remove'))()" >
12+ <IconBase :color =" messageColors.color" width =" 10" icon-name =" remove" >
13+ <IconCross />
14+ </IconBase >
15+ </button >
16+ </div >
2217 <slot name =" text-message-toolbox" :message =" message" :me =" me" > </slot >
2318 </div >
2419 </template >
@@ -47,10 +42,10 @@ import store from './../store/'
4742const fmt = require (' msgdown' )
4843
4944export default {
50- components : {
51- IconBase,
52- IconCross,
53- IconEdit
45+ data () {
46+ return {
47+ store
48+ }
5449 },
5550 props: {
5651 message: {
@@ -72,12 +67,11 @@ export default {
7267 showDeletion: {
7368 type: Boolean ,
7469 required: true
75- }
76- },
77- data () {
78- return {
79- store
80- }
70+ },
71+ showConfirmationDeletion: {
72+ type: Boolean ,
73+ required: true
74+ },
8175 },
8276 computed: {
8377 messageText () {
@@ -98,7 +92,26 @@ export default {
9892 methods: {
9993 edit () {
10094 this .store .editMessage = this .message
101- }
95+ },
96+ ifelse (cond , funcIf , funcElse ) {
97+ return () => {
98+ if (funcIf && cond) funcIf ()
99+ else if (funcElse) funcElse ()
100+ }
101+ },
102+ withConfirm (msg , func ) {
103+ return () => {
104+ if (confirm (msg)) {
105+ console .log (func)
106+ func ()
107+ }
108+ }
109+ },
110+ },
111+ components: {
112+ IconBase,
113+ IconCross,
114+ IconEdit,
102115 }
103116}
104117 </script >
0 commit comments