This commit is contained in:
j3d1 2024-06-08 21:05:10 +02:00
parent 7c10fb76b9
commit db1e5a8249
2 changed files with 13 additions and 11 deletions

View file

@ -430,6 +430,14 @@ const store = createStore({
commit('setMessageTemplates', data);
}
},
async updateMessageTemplate({commit, state}, template) {
const {data, success} = await http.patch(`/2/message_templates/${template.id}/`,
{'message': template.message}, state.user.token);
const {data: newTemplates, success: newSuccess} = await http.get('/2/message_templates/', state.user.token);
if (data && success) {
commit('setMessageTemplates', data);
}
},
async fetchMessageTemplateVariables({commit, state}) {
const {data, success} = await http.get('/2/message_template_variables/', state.user.token);
if (data && success) {

View file

@ -4,7 +4,7 @@
<div v-for="template in messageTemplatesIntermediate" :key="template.id" class="card bg-dark">
<div class="card-header">{{ template.name }}</div>
<div class="card-body">
<FormatedText :value="template.message" :format="formatText" class="template-message"
<FormatedText :value="template.message" :format="formatText"
@input="changeMessageTemplate(template.id, $event)"/>
<br>
<button class="btn btn-primary" @click="resetMessageTemplate(template.id)"
@ -43,7 +43,7 @@ export default {
},
computed: mapState(['messageTemplates', 'messageTemplateVariables']),
methods: {
...mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables']),
...mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables', 'updateMessageTemplate']),
formatText(value) {
return value.replace(/{{(.+?)}}/g, (match, key) => {
return `<span class="text-primary">{{${key}}}</span>`;
@ -58,10 +58,11 @@ export default {
});
},
saveMessageTemplate(id) {
console.log(id);
this.updateMessageTemplate(this.messageTemplatesIntermediate.find(template => template.id === id));
},
resetMessageTemplate(id) {
console.log(id);
this.messageTemplatesIntermediate.find(template => template.id === id).message =
this.messageTemplates.find(template => template.id === id).message;
},
},
mounted() {
@ -79,11 +80,4 @@ pre {
word-wrap: break-word;
color: inherit;
}
.template-message {
border: none;
margin-left: 4em;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>