This commit is contained in:
j3d1 2024-06-09 15:25:58 +02:00
parent 6b11cb8393
commit 1ede9b0930
2 changed files with 22 additions and 2 deletions

View file

@ -444,6 +444,12 @@ const store = createStore({
commit('setMessageTemplateVariables', data); commit('setMessageTemplateVariables', data);
} }
}, },
async createMessageTemplate({commit, state}, template_name) {
const {data, success} = await http.post('/2/message_templates/', {name: template_name}, state.user.token);
if (data && success) {
commit('setMessageTemplates', data);
}
}
}, },
plugins: [ plugins: [
persistentStatePlugin({ // TODO change remember to some kind of enable field persistentStatePlugin({ // TODO change remember to some kind of enable field

View file

@ -15,10 +15,17 @@
</button> </button>
</div> </div>
</div> </div>
<div class="card bg-dark">
<div class="card-body">
<input type="text" class="form-control" v-model="newTemplateName" placeholder="New Template Name">
<button class="btn btn-success" @click="createMessageTemplateAndReset()" ref="createButton">Create</button>
</div>
</div>
</ul> </ul>
<h3 class="text-center">Message Template Variables</h3> <h3 class="text-center">Message Template Variables</h3>
<p> <p>
<span v-for="(variable, key) in messageTemplateVariables" :key="key" class="badge badge-primary" style="margin: 5px;"> <span v-for="(variable, key) in messageTemplateVariables" :key="key" class="badge badge-primary"
style="margin: 5px;">
{{ variable }} {{ variable }}
</span> </span>
</p> </p>
@ -35,11 +42,12 @@ export default {
data() { data() {
return { return {
messageTemplatesIntermediate: [], messageTemplatesIntermediate: [],
newTemplateName: '',
}; };
}, },
computed: mapState(['messageTemplates', 'messageTemplateVariables']), computed: mapState(['messageTemplates', 'messageTemplateVariables']),
methods: { methods: {
...mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables', 'updateMessageTemplate']), ...mapActions(['fetchMessageTemplates', 'fetchMessageTemplateVariables', 'updateMessageTemplate', 'createMessageTemplate']),
formatText(value) { formatText(value) {
return value.replace(/{{(.+?)}}/g, (match, key) => { return value.replace(/{{(.+?)}}/g, (match, key) => {
return `<span class="text-primary">{{${key}}}</span>`; return `<span class="text-primary">{{${key}}}</span>`;
@ -60,6 +68,12 @@ export default {
this.messageTemplatesIntermediate.find(template => template.id === id).message = this.messageTemplatesIntermediate.find(template => template.id === id).message =
this.messageTemplates.find(template => template.id === id).message; this.messageTemplates.find(template => template.id === id).message;
}, },
async createMessageTemplateAndReset() {
this.$refs.createButton.disabled = true;
await this.createMessageTemplate(this.newTemplateName);
this.newTemplateName = '';
this.$refs.createButton.disabled = false;
},
}, },
mounted() { mounted() {
this.fetchMessageTemplates().then(() => { this.fetchMessageTemplates().then(() => {