Skip to content

Commit

Permalink
Add helper button on campaign UI to fill default archive meta JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 20, 2022
1 parent c52a067 commit 73bb608
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions frontend/src/views/Campaign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,25 @@
</div>
</b-field>

<b-field :label="$tc('globals.terms.template')" label-position="on-border">
<b-select :placeholder="$tc('globals.terms.template')" v-model="form.archiveTemplateId"
name="template" :disabled="!canArchive || !form.archive" required>
<template v-for="t in templates">
<option v-if="t.type === 'campaign'"
:value="t.id" :key="t.id">{{ t.name }}</option>
</template>
</b-select>
</b-field>
<div class="columns">
<div class="column is-8">
<b-field :label="$tc('globals.terms.template')" label-position="on-border">
<b-select :placeholder="$tc('globals.terms.template')"
v-model="form.archiveTemplateId" name="template"
:disabled="!canArchive || !form.archive" required>
<template v-for="t in templates">
<option v-if="t.type === 'campaign'"
:value="t.id" :key="t.id">{{ t.name }}</option>
</template>
</b-select>
</b-field>
</div>

<div class="column has-text-right">
<a v-if="!this.form.archiveMetaStr || this.form.archiveMetaStr === '{}'"
class="button" href="#" @click.prevent="onFillArchiveMeta">{}</a>
</div>
</div>
<b-field :label="$t('campaigns.archiveMeta')"
:message="$t('campaigns.archiveMetaHelp')" label-position="on-border">
<b-input v-model="form.archiveMetaStr" name="archive_meta" type="textarea"
Expand Down Expand Up @@ -331,6 +340,11 @@ export default Vue.extend({
}
},
onFillArchiveMeta() {
const archiveStr = `{"email": "[email protected]", "name": "${this.$t('globals.fields.name')}", "attribs": {}}`;
this.form.archiveMetaStr = this.$utils.getPref('campaign.archiveMetaStr') || JSON.stringify(JSON.parse(archiveStr), null, 4);
},
onSubmit(typ) {
// Validate custom JSON headers.
if (this.form.headersStr && this.form.headersStr !== '[]') {
Expand All @@ -356,11 +370,6 @@ export default Vue.extend({
this.form.archiveMeta = {};
}
// Cache the campaign archive metadata for the next one.
if (this.isEditing) {
this.$utils.setPref('campaign.archiveMetaStr', this.form.archiveMetaStr);
}
switch (typ) {
case 'create':
this.createCampaign();
Expand All @@ -387,11 +396,6 @@ export default Vue.extend({
content: { contentType: data.contentType, body: data.body },
};
if (this.form.archiveMetaStr === '{}') {
const archiveStr = `{"email": "[email protected]", "name": "${this.$t('globals.fields.name')}", "attribs": {}}`;
this.form.archiveMetaStr = this.$utils.getPref('campaign.archiveMetaStr') || JSON.stringify(JSON.parse(archiveStr), null, 4);
}
if (data.sendAt !== null) {
this.form.sendLater = true;
this.form.sendAtDate = dayjs(data.sendAt).toDate();
Expand Down

0 comments on commit 73bb608

Please sign in to comment.