1010 //- tk-tiptap-editor(v-model="message" ref="editorDialog")
1111 q-editor(
1212 v-model ="message" placeholder ="Votre message ..."
13- :definitions ="editorDefinitions"
13+ :definitions ="editorDefinitions" : disable = "isDisabledTicket"
1414 :toolbar ="editorToolbar" dense style ="height: 100%"
1515 ) .col
1616 template( v-slot:threadTypes )
2525 q-item-label {{ type.label }}
2626 q-btn(
2727 icon ="mdi-send" size ="md" color ="primary" flat
28- @click ="sendMessage "
28+ @click ="isFullscreen = true "
2929 ) .col-1
3030 q-tooltip.text-body2 Envoyer
3131
3535
3636 q-dialog( v-model ="isFullscreen" )
3737 q-card
38+ q-card-section.bg-grey-2
39+ q-input( dense label ="From" v-model ="mailInfo.from" )
40+ q-input( dense label ="To" v-model ="mailInfo.to" )
41+ q-input( dense label ="Copy" v-model ="mailInfo.cc" )
42+ q-input( dense label ="Subject" v-model ="mailInfo.subject" )
3843 q-card-section
3944 q-editor(
4045 min-height ="50vh" min-width ="50vw"
4146 v-model ="message" placeholder ="Votre message ..."
4247 :definitions ="editorDefinitions"
4348 :toolbar ="editorToolbar" class ="q-pa-none"
44- :disable = "disabled " ref ="dropZoneRef"
49+ :readonly = "isDisabledTicket " ref ="dropZoneRef"
4550 )
4651 q-card-section.q-pa-sm
4752 div( ref ="dropZoneDialogRef" ) .row.center.bg-grey-3
4853 .col.text-center
4954 q-icon( name ="mdi-paperclip" size ="md" : class = "isOverDropZoneDialog ? 'text-primary' : 'text-grey-5'" )
5055 span.q-ml-md ( :class ="isOverDropZoneDialog ? 'text-primary' : 'text-grey-5'" ) Déposer un fichier
5156 q-card-section
52- q-chip( v-for ="attachement in attachements" : key= "attachement.id" icon ="mdi-paperclip" dense size ='md' : label= "attachement.name" removable @remove ="removeAttachment(attachement.id)" )
57+ q-scroll-area( style ="width: 100%; height: 100%" )
58+ q-virtual-scroll( :items ="attachements" virtual-scroll-horizontal v-slot ="{item}" )
59+ q-chip( v-for ="attachement in attachements" : key= "attachement.id" icon ="mdi-paperclip" dense size ='md' : label= "attachement.name" removable @remove ="removeAttachment(attachement.id)" )
5360
54- //- .col-1(ref="dropZoneRef").bg-grey-3.items-center.justify-center.q-pa-md
55- //- q-icon(name="mdi-paperclip" size="md" :class="isOverDropZone ? 'text-primary' : 'text-grey-5'")
56- //- span.q-ml-md(:class="isOverDropZone ? 'text-primary' : 'text-grey-5'") Déposer un fichier
61+ .row
62+ q-btn( label ="Envoyer en note interne" color ="primary" icon ="mdi-note" @click ="sendMessage(ThreadType.INTERNAL)" ) .col-6
63+ q-btn( label ="Envoyer par mail" color ="primary" icon ="mdi-email" @click ="sendMessage(ThreadType.OUTGOING)" ) .col-6
64+ //- .col-1(ref="dropZoneRef").bg-grey-3.items-center.justify-center.q-pa-md
65+ //- q-icon(name="mdi-paperclip" size="md" :class="isOverDropZone ? 'text-primary' : 'text-grey-5'")
66+ //- span.q-ml-md(:class="isOverDropZone ? 'text-primary' : 'text-grey-5'") Déposer un fichier
5767
5868 </template >
5969
6070<script lang="ts" setup>
61- import { ref , onMounted , computed } from ' vue'
71+ import { ref , onMounted , computed , inject } from ' vue'
6272import { useRoute , useRouter } from ' nuxt/app' ;
6373import { useHttpApi } from ' ~/composables' ;
6474import { useDayjs , usePinia } from " #imports" ;
@@ -72,6 +82,9 @@ import ObjectID from 'bson-objectid';
7282
7383type ThreadCreateDto = components [' schemas' ][' ThreadCreateDto' ]
7484type FsPart = components [" schemas" ][" IdfsPartDto" ]
85+ type MailinfoPartDto = components [" schemas" ][" MailinfoPartDto" ]
86+
87+ const emit = defineEmits ([' refreshThreadsList' ])
7588
7689const dayjs = useDayjs ()
7790const store = usePinia ()
@@ -91,6 +104,12 @@ const dropZoneDialogRef = ref<HTMLDivElement>()
91104const editorDialog = ref ()
92105const currentThreadId = ref <ObjectID | null >(null )
93106const attachements = ref <FsPart []>([])
107+ const mailInfo = ref ({
108+ from: ' ' ,
109+ to: ' ' ,
110+ cc: ' ' ,
111+ subject: ' '
112+ })
94113
95114const onDrop = (files : File [] | null ) => {
96115 if (! files ) return
@@ -131,6 +150,14 @@ const uploadFile = async (file: File) => {
131150 $q .notify (' Fichier envoyé' )
132151}
133152
153+ const emailReponse = (data : MailinfoPartDto ) => {
154+ mailInfo .value .to = data .from .address
155+ mailInfo .value .from = data .to [0 ].address
156+ mailInfo .value .subject = data .subject .startsWith (' Re:' ) ? data .subject : ` Re:${data .subject } `
157+ isFullscreen .value = true
158+ console .log (data )
159+ }
160+
134161const removeAttachment = (id : string ) => {
135162 const { data, error } = useHttpApi (` core/filestorage/${id } ` , {
136163 method: ' delete'
@@ -146,53 +173,52 @@ const removeAttachment = (id: string) => {
146173 $q .notify (' Fichier supprimé' )
147174}
148175
149- const sendMessage = async () => {
150- const payload: ThreadCreateDto = {
151- _id: currentThreadId ,
152- attachments: attachements .value ,
153- ticketId: generateMongoId (route .params .id .toString ()),
154- fragments: [
155- {
176+ const sendMessage = (type : ThreadType = ThreadType .OUTGOING ) => {
177+ const { data : thread, error } = useHttpApi (` tickets/thread ` , {
178+ method: ' post' ,
179+ body: {
180+ _id: currentThreadId .value ,
181+ attachments: attachements .value ,
182+ ticketId: generateMongoId (route .params .id .toString ()),
183+ fragments: [{
156184 id: generateMongoId (),
157185 disposition: ' raw' ,
158186 message: message .value
159- }
160- ],
161- metadata: {
162- createdBy: user .username ,
163- createdAt: dayjs ().toISOString (),
164- lastUpdatedAt: dayjs ().toISOString (),
165- lastUpdatedBy: user .username
166- },
167- type: ThreadType .OUTGOING
168- }
169- const { data : thread, error } = await useHttpApi (` tickets/thread ` , {
170- method: ' post' ,
171- body: payload
187+ }],
188+ metadata: {
189+ createdBy: user .username ,
190+ createdAt: dayjs ().toISOString (),
191+ lastUpdatedAt: dayjs ().toISOString (),
192+ lastUpdatedBy: user .username
193+ },
194+ type
195+ }
172196 })
197+
173198 if (error .value ) {
174199 $q .notify ({
175200 message: ' Impossible d\' envoyer le message' ,
176201 type: ' negative'
177202 })
178203 return
179204 }
180- threads . value ?. data . push ( thread . value ?. data )
205+
181206 message .value = ' '
182- scroll ()
183207 attachements .value = []
208+ currentThreadId .value = generateMongoId ()
209+ isFullscreen .value = false
184210 $q .notify (' Message envoyé' )
185-
211+ emit ( ' refreshThreadsList ' )
186212}
187213
188214const editorDefinitions = computed (() => (
189215 {
190- send : {
191- tip : ' Envoyer' ,
192- icon : ' mdi-send' ,
193- label : ' Envoyer' ,
194- handler : sendMessage
195- },
216+ // send: {
217+ // tip: 'Envoyer',
218+ // icon: 'mdi-send',
219+ // label: 'Envoyer',
220+ // handler: sendMessage
221+ // },
196222 attach : {
197223 tip : ' Joindre un fichier' ,
198224 icon : ' mdi-paperclip' ,
@@ -215,4 +241,10 @@ const editorToolbar = computed(() => {
215241 return [[' left' , ' center' , ' right' , ' justify' ], [' bold' , ' italic' , ' underline' , ' strike' ], [' undo' , ' redo' ], [' fullscreen' ]]
216242})
217243
244+ const isDisabledTicket = inject (' isDisabledTicket' )
245+
246+ defineExpose ({
247+ emailReponse
248+ })
249+
218250</script >
0 commit comments