2020-06-06 20:03:55 +02:00
|
|
|
<template>
|
|
|
|
<section>
|
|
|
|
<form @submit.prevent="onSubmit">
|
|
|
|
<div class="modal-card content template-modal-content" style="width: auto">
|
|
|
|
<header class="modal-card-head">
|
|
|
|
<b-button @click="previewTemplate"
|
|
|
|
class="is-pulled-right" type="is-primary"
|
|
|
|
icon-left="file-find-outline">Preview</b-button>
|
|
|
|
|
|
|
|
<h4 v-if="isEditing">{{ data.name }}</h4>
|
|
|
|
<h4 v-else>New template</h4>
|
|
|
|
</header>
|
|
|
|
<section expanded class="modal-card-body">
|
2020-07-26 16:13:43 +02:00
|
|
|
<b-field label="Name" label-position="on-border">
|
2020-06-06 20:03:55 +02:00
|
|
|
<b-input :maxlength="200" :ref="'focus'" v-model="form.name"
|
|
|
|
placeholder="Name" required></b-input>
|
|
|
|
</b-field>
|
|
|
|
|
2020-07-26 16:13:43 +02:00
|
|
|
<b-field label="Raw HTML" label-position="on-border">
|
2020-06-06 20:03:55 +02:00
|
|
|
<b-input v-model="form.body" type="textarea" required />
|
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<p class="is-size-7">
|
|
|
|
The placeholder <code>{{ egPlaceholder }}</code>
|
|
|
|
should appear in the template.
|
|
|
|
<a target="_blank" href="https://listmonk.app/docs/templating">Learn more.</a>
|
|
|
|
</p>
|
|
|
|
</section>
|
|
|
|
<footer class="modal-card-foot has-text-right">
|
|
|
|
<b-button @click="$parent.close()">Close</b-button>
|
|
|
|
<b-button native-type="submit" type="is-primary"
|
|
|
|
:loading="loading.templates">Save</b-button>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<campaign-preview v-if="previewItem"
|
|
|
|
type='template'
|
|
|
|
:title="previewItem.name"
|
|
|
|
:body="form.body"
|
|
|
|
@close="closePreview"></campaign-preview>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { mapState } from 'vuex';
|
|
|
|
import CampaignPreview from '../components/CampaignPreview.vue';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
2020-07-04 19:38:34 +02:00
|
|
|
components: {
|
|
|
|
CampaignPreview,
|
|
|
|
},
|
2020-06-06 20:03:55 +02:00
|
|
|
|
|
|
|
props: {
|
|
|
|
data: Object,
|
|
|
|
isEditing: null,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
// Binds form input values.
|
|
|
|
form: {
|
|
|
|
name: '',
|
|
|
|
type: '',
|
|
|
|
optin: '',
|
|
|
|
},
|
|
|
|
previewItem: null,
|
|
|
|
egPlaceholder: '{{ template "content" . }}',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
previewTemplate() {
|
|
|
|
this.previewItem = this.data;
|
|
|
|
},
|
|
|
|
|
|
|
|
closePreview() {
|
|
|
|
this.previewItem = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
if (this.isEditing) {
|
|
|
|
this.updateTemplate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.createTemplate();
|
|
|
|
},
|
|
|
|
|
|
|
|
createTemplate() {
|
|
|
|
const data = {
|
|
|
|
id: this.data.id,
|
|
|
|
name: this.form.name,
|
|
|
|
body: this.form.body,
|
|
|
|
};
|
|
|
|
|
2020-07-09 19:59:59 +02:00
|
|
|
this.$api.createTemplate(data).then((d) => {
|
2020-06-06 20:03:55 +02:00
|
|
|
this.$emit('finished');
|
|
|
|
this.$parent.close();
|
|
|
|
this.$buefy.toast.open({
|
2020-07-09 19:59:59 +02:00
|
|
|
message: `'${d.name}' created`,
|
2020-06-06 20:03:55 +02:00
|
|
|
type: 'is-success',
|
|
|
|
queue: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTemplate() {
|
|
|
|
const data = {
|
|
|
|
id: this.data.id,
|
|
|
|
name: this.form.name,
|
|
|
|
body: this.form.body,
|
|
|
|
};
|
|
|
|
|
2020-07-09 19:59:59 +02:00
|
|
|
this.$api.updateTemplate(data).then((d) => {
|
2020-06-06 20:03:55 +02:00
|
|
|
this.$emit('finished');
|
|
|
|
this.$parent.close();
|
|
|
|
this.$buefy.toast.open({
|
2020-07-09 19:59:59 +02:00
|
|
|
message: `'${d.name}' updated`,
|
2020-06-06 20:03:55 +02:00
|
|
|
type: 'is-success',
|
|
|
|
queue: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['loading']),
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.form = { ...this.$props.data };
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.focus.focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|