High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
SSR: Port all templates pages.
Kailash Nadhcbcd83c73041
diff --git a/cmd/handlers.go b/cmd/handlers.goindex f8fd26c8..50462439 100644--- a/cmd/handlers.go+++ b/cmd/handlers.go@@ -82,6 +82,9 @@ func initHTTPHandlers(e *echo.Echo, a *App) {g.GET(path.Join(uriAdmin, "/campaigns/new"), a.ViewNewCampaign)g.GET(path.Join(uriAdmin, "/campaigns/:id"), hasID(a.ViewCampaign))g.GET(path.Join(uriAdmin, "/campaigns/:id/:tab"), hasID(a.ViewCampaign))+ g.GET(path.Join(uriAdmin, "/templates"), a.ViewTemplates)+ g.GET(path.Join(uriAdmin, "/templates/new"), a.ViewNewTemplate)+ g.GET(path.Join(uriAdmin, "/templates/:id"), hasID(a.ViewTemplate))g.GET(path.Join(uriAdmin, "/subscribers/import"), a.ViewImport)g.GET(path.Join(uriAdmin, "/subscribers/bounces"), a.ViewBounces)g.GET(path.Join(uriAdmin, "/subscribers"), a.ViewSubscribers)diff --git a/cmd/templates.go b/cmd/templates.goindex 7d06fa15..b0a85ac9 100644--- a/cmd/templates.go+++ b/cmd/templates.go@@ -31,6 +31,63 @@ var (regexpTplTag = regexp.MustCompile(`{{(\s+)?template\s+?"content"(\s+)?\.(\s+)?}}`))+// templatesView is the admin page view for the templates list page.+type templatesView struct {+ adminView++ Templates []models.Template+}++// templateView is the admin page view for creating/editing a single template.+type templateView struct {+ adminView++ IsNew bool+ Template models.Template+}++// ViewTemplates renders the HTML list view for templates.+func (a *App) ViewTemplates(c echo.Context) error {+ out, err := a.core.GetTemplates("", true)+ if err != nil {+ return err+ }++ data := templatesView{+ adminView: newAdminView(c, a.i18n.T("globals.terms.templates"), "", "campaigns.templates"),+ Templates: out,+ }++ return c.Render(http.StatusOK, "admin-templates", data)+}++// ViewNewTemplate renders the new template page.+func (a *App) ViewNewTemplate(c echo.Context) error {+ data := templateView{+ adminView: newAdminView(c, a.i18n.T("templates.newTemplate"), "", "campaigns.templates"),+ IsNew: true,+ Template: models.Template{Type: models.TemplateTypeCampaign},+ }++ return c.Render(http.StatusOK, "admin-template", data)+}++// ViewTemplate renders the single-page editor for an existing template.+func (a *App) ViewTemplate(c echo.Context) error {+ id := getID(c)+ out, err := a.core.GetTemplate(id, false)+ if err != nil {+ return err+ }++ data := templateView{+ adminView: newAdminView(c, out.Name, "", "campaigns.templates"),+ Template: out,+ }++ return c.Render(http.StatusOK, "admin-template", data)+}+// GetTemplate handles the retrieval of a templatefunc (a *App) GetTemplate(c echo.Context) error {// If no_body is true, blank out the body of the template from the response.diff --git a/frontend-vue/src/router/index.js b/frontend-vue/src/router/index.jsindex e21f2f95..df05a611 100644--- a/frontend-vue/src/router/index.js+++ b/frontend-vue/src/router/index.js@@ -17,12 +17,6 @@ const routes = [meta: { title: '' },component: () => import('../views/Dashboard.vue'),},- {- path: '/campaigns/templates',- name: 'templates',- meta: { title: 'globals.terms.templates', group: 'campaigns' },- component: () => import('../views/Templates.vue'),- },{path: '/campaigns/analytics',name: 'campaignAnalytics',diff --git a/frontend-vue/src/views/TemplateForm.vue b/frontend-vue/src/views/TemplateForm.vuedeleted file mode 100644index f7ba7401..00000000--- a/frontend-vue/src/views/TemplateForm.vue+++ /dev/null@@ -1,204 +0,0 @@-<template>- <section>- <form @submit.prevent="onSubmit">- <div class="dialog-card content template-modal-content" style="width: auto">- <header class="dialog-head">- <button type="button" @click="onTogglePreview" class="align-right" data-variant="primary">- {{ $t('templates.preview') }} (F9)- </button>-- <template v-if="isEditing">- <h4>{{ data.name }}</h4>- <p class="text-light text-7 ">- {{ $t('globals.fields.id') }}: <span data-cy="id"><copy-text :text="`${data.id}`" /></span>- </p>- </template>- <h4 v-else>- {{ $t('templates.newTemplate') }}- </h4>- </header>- <section class="dialog-body mb-0 pb-0">- <div class="row">- <div class="col-9">- <b-field :label="$t('globals.fields.name')">- <input aria-label="field" :maxlength="200" :ref="'focus'" v-model="form.name" name="name"- :placeholder="$t('globals.fields.name')" required>- </b-field>- </div>- <div class="col-3">- <b-field :label="$t('globals.fields.type')">- <select aria-label="field" v-model="form.type" :disabled="isEditing">- <option value="campaign">- {{ $tc('templates.typeCampaignHTML') }}- </option>- <option value="campaign_visual">- {{ $tc('templates.typeCampaignVisual') }}- </option>- <option value="tx">- {{ $tc('templates.typeTransactional') }}- </option>- </select>- </b-field>- </div>- </div>- <div class="row" v-if="form.type === 'tx'">- <div class="col-12">- <b-field :label="$t('templates.subject')">- <input aria-label="field" :maxlength="200" :ref="'focus'" v-model="form.subject" name="name"- :placeholder="$t('templates.subject')" required>- </b-field>- </div>- </div>-- <template v-if="form.body !== null">- <b-field v-if="form.type === 'campaign_visual'" class="mb-1">- <visual-editor v-if="form.type === 'campaign_visual'" name="body" :source="form.bodySource"- @change="onChangeVisualEditor" height="70vh" />- </b-field>-- <b-field v-else :label="$t('templates.rawHTML')">- <code-editor lang="html" v-model="form.body" name="body" />- </b-field>- </template>-- <p class="text-7">- <template v-if="form.type === 'campaign'">- {{ $t('templates.placeholderHelp', { placeholder: egPlaceholder }) }}- </template>- <a target="_blank" rel="noopener noreferer" href="https://listmonk.app/docs/templating">- {{ $t('globals.buttons.learnMore') }}- </a>- </p>- </section>- <footer class="dialog-foot align-right">- <button type="button" class="outline" @click="$parent.close()">- {{ $t('globals.buttons.close') }}- </button>- <button v-if="$can('templates:manage')" type="submit" data-variant="primary" :loading="loading.templates">- {{ $t('globals.buttons.save') }}- </button>- </footer>- </div>- </form>- <campaign-preview v-if="previewItem" is-post type="template" :title="previewItem.name"- :template-type="previewItem.type" :body="form.body" @close="onTogglePreview" />- </section>-</template>--<script>-import Vue from 'vue';-import { mapState } from 'vuex';-import CampaignPreview from '../components/CampaignPreview.vue';-import CodeEditor from '../components/CodeEditor.vue';-import VisualEditor from '../components/VisualEditor.vue';-import CopyText from '../components/CopyText.vue';--export default Vue.extend({- components: {- CampaignPreview,- CopyText,- 'code-editor': CodeEditor,- 'visual-editor': VisualEditor,- },-- props: {- data: { type: Object, default: () => { } },- isEditing: { type: Boolean, default: false },- },-- data() {- return {- // Binds form input values.- form: {- name: '',- subject: '',- type: 'campaign',- optin: '',- body: null,- bodySource: null,- },- previewItem: null,- egPlaceholder: '{{ template "content" . }}',- };- },-- methods: {- onTogglePreview() {- this.previewItem = !this.previewItem ? this.form : null;- },-- onPreviewShortcut(e) {- if (e.key === 'F9') {- this.onTogglePreview();- e.preventDefault();- }- },-- onSubmit() {- if (this.isEditing) {- this.updateTemplate();- return;- }-- this.createTemplate();- },-- createTemplate() {- const data = {- id: this.data.id,- name: this.form.name,- type: this.form.type,- subject: this.form.subject,- body: this.form.body,- body_source: this.form.bodySource,- };-- this.$api.createTemplate(data).then((d) => {- this.$emit('finished');- this.$parent.close();- this.$utils.toast(this.$t('globals.messages.created', { name: d.name }));- });- },-- updateTemplate() {- const data = {- id: this.data.id,- name: this.form.name,- type: this.form.type,- subject: this.form.subject,- body: this.form.body,- body_source: this.form.bodySource,- };-- this.$api.updateTemplate(data).then((d) => {- this.$emit('finished');- this.$parent.close();- this.$utils.toast(`'${d.name}' updated`);- });- },-- onChangeVisualEditor({ source, body }) {- this.form.body = body;- this.form.bodySource = source;- },- },-- computed: {- ...mapState(['loading']),- },-- mounted() {- this.form = { ...this.$props.data };-- this.$nextTick(() => {- this.$refs.focus.focus();- });-- window.addEventListener('keydown', this.onPreviewShortcut);- },-- beforeDestroy() {- window.removeEventListener('keydown', this.onPreviewShortcut);- },-});-</script>diff --git a/frontend-vue/src/views/Templates.vue b/frontend-vue/src/views/Templates.vuedeleted file mode 100644index 5184d07c..00000000--- a/frontend-vue/src/views/Templates.vue+++ /dev/null@@ -1,223 +0,0 @@-<template>- <section class="templates">- <header class="row page-header">- <div class="col-8">- <h1>- {{ $t('globals.terms.templates') }}- <span v-if="templates.length > 0">({{ templates.length }})</span>- </h1>- </div>- <div class="col-4 col-end align-right">- <b-field v-if="$can('templates:manage')">- <button type="button" data-variant="primary" class="btn-new" @click="showNewForm">- <b-icon icon="plus" />- {{ $t('globals.buttons.new') }}- </button>- </b-field>- </div>- </header>-- <div class="card page-content">- <b-table :data="templates" :hoverable="true" :loading="loading.templates" default-sort="createdAt">- <b-table-column v-slot="props" field="name" :label="$t('globals.fields.name')" :td-attrs="$utils.tdID"- sortable>- <a href="#" @click.prevent="showEditForm(props.row)">- {{ props.row.name }}- </a>- <span v-if="props.row.isDefault" class="badge secondary">- {{ $t('templates.default') }}- </span>-- <p class="text-light text-7" v-if="props.row.type === 'tx'">- {{ props.row.subject }}- </p>- </b-table-column>-- <b-table-column v-slot="props" field="type" :label="$t('globals.fields.type')" sortable>- <b-tag v-if="props.row.type === 'campaign'" :type="props.row.type" :data-cy="`type-${props.row.type}`">- {{ $tc('templates.typeCampaignHTML') }}- </b-tag>- <b-tag v-else-if="props.row.type === 'campaign_visual'" :type="props.row.type"- :data-cy="`type-${props.row.type}`">- {{ $tc('templates.typeCampaignVisual') }}- </b-tag>- <b-tag v-else :type="props.row.type" :data-cy="`type-${props.row.type}`">- {{ $tc('templates.typeTransactional') }}- </b-tag>- </b-table-column>-- <b-table-column v-slot="props" field="id" :label="$t('globals.fields.id')" sortable>- {{ props.row.id }}- </b-table-column>-- <b-table-column v-slot="props" field="createdAt" :label="$t('globals.fields.createdAt')" sortable>- {{ $utils.niceDate(props.row.createdAt) }}- </b-table-column>-- <b-table-column v-slot="props" field="updatedAt" :label="$t('globals.fields.updatedAt')" sortable>- {{ $utils.niceDate(props.row.updatedAt) }}- </b-table-column>-- <b-table-column v-slot="props" cell-class="actions" align="right">- <div>- <a href="#" @click.prevent="previewTemplate(props.row)" data-cy="btn-preview"- :aria-label="$t('templates.preview')">-- <b-icon icon="file-find-outline" />-- </a>- <a href="#" @click.prevent="showEditForm(props.row)" data-cy="btn-edit"- :aria-label="$t('globals.buttons.edit')">-- <b-icon icon="pencil-outline" />-- </a>- <a href="#" @click.prevent="$utils.prompt(`Clone template`,- { placeholder: 'Name', value: `Copy of ${props.row.name}` },- (name) => cloneTemplate(name, props.row))" data-cy="btn-clone" :aria-label="$t('globals.buttons.clone')">-- <b-icon icon="file-multiple-outline" />-- </a>- <a v-if="!props.row.isDefault && props.row.type === 'campaign'" href="#"- @click.prevent="$utils.confirm(null, () => makeTemplateDefault(props.row))" data-cy="btn-set-default"- :aria-label="$t('templates.makeDefault')">-- <b-icon icon="check-circle-outline" />-- </a>- <span v-else class="a text-lighter">- <b-icon icon="check-circle-outline" />- </span>-- <a v-if="!props.row.isDefault" href="#"- @click.prevent="$utils.confirm(null, () => deleteTemplate(props.row))" data-cy="btn-delete"- :aria-label="$t('globals.buttons.delete')">-- <b-icon icon="trash-can-outline" />-- </a>- <span v-else class="a text-lighter">- <b-icon icon="trash-can-outline" />- </span>- </div>- </b-table-column>-- <template #empty v-if="!loading.templates">- <empty-placeholder />- </template>- </b-table>-- <!-- Add / edit form modal -->- <b-modal :active.sync="isFormVisible" :width="1200" :can-cancel="false" class="template-modal">- <template-form :data="curItem" :is-editing="isEditing" @finished="formFinished" />- </b-modal>-- <campaign-preview v-if="previewItem" type="template" :id="previewItem.id" :template-type="previewItem.type"- :title="previewItem.name" @close="closePreview" />- </div>- </section>-</template>--<script>-import Vue from 'vue';-import { mapState } from 'vuex';-import CampaignPreview from '../components/CampaignPreview.vue';-import EmptyPlaceholder from '../components/EmptyPlaceholder.vue';--import TemplateForm from './TemplateForm.vue';--export default Vue.extend({- components: {- CampaignPreview,- TemplateForm,- EmptyPlaceholder,- },-- data() {- return {- curItem: null,- isEditing: false,- isFormVisible: false,- previewItem: null,- };- },-- methods: {- fetchTemplates() {- this.$api.getTemplates();- },-- // Show the edit form.- showEditForm(data) {- this.curItem = data;- this.isFormVisible = true;- this.isEditing = true;- },-- // Show the new form.- showNewForm() {- this.curItem = { type: 'campaign' };- this.isFormVisible = true;- this.isEditing = false;- },-- formFinished() {- this.$api.getTemplates();- },-- previewTemplate(c) {- this.previewItem = c;- },-- closePreview() {- this.previewItem = null;- },-- cloneTemplate(name, t) {- const data = {- name,- type: t.type,- subject: t.subject,- body: t.body,- body_source: t.bodySource,- };- this.$api.createTemplate(data).then((d) => {- this.$api.getTemplates();- this.$emit('finished');- this.$utils.toast(`'${d.name}' created`);- });- },-- makeTemplateDefault(tpl) {- this.$api.makeTemplateDefault(tpl.id).then(() => {- this.$api.getTemplates();- this.$utils.toast(this.$t('globals.messages.created', { name: tpl.name }));- });- },-- deleteTemplate(tpl) {- this.$api.deleteTemplate(tpl.id).then(() => {- this.$api.getTemplates();- this.$utils.toast(this.$t('globals.messages.deleted', { name: tpl.name }));- });- },- },-- computed: {- ...mapState(['templates', 'loading']),- },-- created() {- this.$root.$on('page.refresh', this.fetchTemplates);- },-- destroyed() {- this.$root.$off('page.refresh', this.fetchTemplates);- },-- mounted() {- this.$api.getTemplates();- },-});-</script>diff --git a/static/admin/partials/template-preview.html b/static/admin/partials/template-preview.htmlnew file mode 100644index 00000000..04aa84c2--- /dev/null+++ b/static/admin/partials/template-preview.html@@ -0,0 +1,19 @@+{{ define "template-preview" -}}+<dialog class="preview-modal" x-ref="previewDialog" @close="onPreviewClose">+ <div class="dialog-card">+ <header class="dialog-head hstack justify-between">+ <h4 class="dialog-title" x-text="preview.title"></h4>+ </header>+ <section class="dialog-body preview" :aria-busy="preview.loading">+ <form method="post" x-ref="previewForm" :action="preview.url" target="template-preview-frame">+ <input type="hidden" name="template_type" :value="preview.templateType" />+ <input type="hidden" name="body" :value="preview.body" />+ </form>+ <iframe id="iframe" name="template-preview-frame" x-ref="previewFrame" title="{{ .L.T "templates.preview" }}" @load="preview.loading = false"></iframe>+ </section>+ <footer class="dialog-foot align-right">+ <button type="button" class="outline" autofocus @click="$refs.previewDialog.close()">{{ .L.T "globals.buttons.close" }}</button>+ </footer>+ </div>+</dialog>+{{- end }}diff --git a/static/admin/src/css/style.css b/static/admin/src/css/style.cssindex 18637742..dfe4890d 100644--- a/static/admin/src/css/style.css+++ b/static/admin/src/css/style.css@@ -1027,9 +1027,9 @@ section.analytics {.preview-modal {padding: 0;- position: relative;- min-width: 1100px;- max-width: 960px;+ position: fixed;+ width: 100%;+ max-width: 1100px;max-height: calc(100vh - 40px);.dialog-body {@@ -1150,6 +1150,26 @@ section.campaign {}}+/* Template editor. */+section.templates {+ .editor-body {+ margin-block: var(--space-3);+ }++ visual-editor {+ display: block;+ border: 1px solid var(--border);+ border-radius: var(--radius-small);+ width: 100%;+ }++ visual-editor iframe {+ border: 0;+ width: 100%;+ min-height: 65vh;+ }+}+.forms {code-editor {font-size: var(--text-8);diff --git a/static/admin/src/js/views/templates.js b/static/admin/src/js/views/templates.jsnew file mode 100644index 00000000..07083a94--- /dev/null+++ b/static/admin/src/js/views/templates.js@@ -0,0 +1,135 @@+import {+ api,+ urls,+ i18n,+} from '../main.js';+import * as u from '../utils.js';++// previewMixin provides the shared state + handlers for the template-preview dialog.+function previewMixin() {+ return {+ preview: {+ title: '', url: '', templateType: '', body: '', loading: true,+ },++ // Preview a saved template by id (GET into the iframe).+ onPreview(id, name) {+ this.preview = {+ title: name, url: `${urls.api}/templates/${id}/preview`, templateType: '', body: '', loading: true,+ };+ this.$refs.previewDialog.showModal();+ this.$nextTick(() => { this.$refs.previewFrame.src = this.preview.url; });+ },++ onPreviewClose() {+ this.$refs.previewFrame.removeAttribute('src');+ this.preview.loading = true;+ },+ };+}++// templatesView is the templates list page component.+function templatesView() {+ return {+ ...previewMixin(),++ // Clone a template by fetching its full body and creating a copy.+ async onClone(id, name) {+ const newName = window.prompt(i18n.t('globals.fields.name'), i18n.ts('campaigns.copyOf', { name }));+ if (!newName) {+ return;+ }++ const t = await api('templates', `/templates/${id}`);+ const data = await api('templates', '/templates', 'POST', {+ name: newName,+ type: t.type,+ subject: t.subject,+ body: t.body,+ body_source: t.body_source,+ });+ u.reload({ message: i18n.ts('globals.messages.created', { name: data.name }) });+ },++ async onSetDefault(id, name) {+ if (!(await u.confirm())) {+ return;+ }+ await api('templates', `/templates/${id}/default`, 'PUT');+ u.reload({ message: i18n.ts('globals.messages.created', { name }) });+ },++ async onDelete(id, name) {+ if (!(await u.confirm(i18n.t('globals.messages.confirm')))) {+ return;+ }+ await api('templates', `/templates/${id}`, 'DELETE');+ u.reload({ message: i18n.ts('globals.messages.deleted', { name }) });+ },+ };+}++// templateForm is the add/edit template form page component.+function templateForm(tpl, isNew) {+ const t = tpl || {};++ return {+ ...previewMixin(),+ isNew,++ form: {+ id: t.id || null,+ name: t.name || '',+ type: t.type || 'campaign',+ subject: t.subject || '',+ body: t.body || '',+ body_source: t.body_source || null,+ },++ // Preview the current (unsaved) body by POSTing it to the preview endpoint.+ onPreviewBody() {+ this.preview = {+ title: this.form.name, url: `${urls.api}/templates/preview`, templateType: this.form.type, body: this.form.body || '', loading: true,+ };+ this.$refs.previewDialog.showModal();+ this.$nextTick(() => this.$refs.previewForm.submit());+ },++ onSaveShortcut() {+ this.onSubmit();+ },++ onSubmit() {+ if (this.isNew) {+ this.createTemplate();+ } else {+ this.updateTemplate();+ }+ },++ _payload() {+ return {+ name: this.form.name,+ type: this.form.type,+ subject: this.form.subject,+ body: this.form.body,+ body_source: this.form.body_source,+ };+ },++ async createTemplate() {+ const data = await api('templates', '/templates', 'POST', this._payload());+ u.redirect(`${urls.admin}/templates`, { message: i18n.ts('globals.messages.created', { name: data.name }) });+ },++ async updateTemplate() {+ const data = await api('templates', `/templates/${this.form.id}`, 'PUT', this._payload());+ u.reload({ message: i18n.ts('globals.messages.updated', { name: data.name }) });+ },+ };+}++document.addEventListener('alpine:init', () => {+ window.Alpine.data('templatesView', templatesView);+ window.Alpine.data('templateForm', templateForm);+}, { once: true });diff --git a/static/admin/views/template.html b/static/admin/views/template.htmlnew file mode 100644index 00000000..aa99207c--- /dev/null+++ b/static/admin/views/template.html@@ -0,0 +1,90 @@+{{ define "admin-template" -}}+{{ template "admin-header" . }}+{{- $d := .Data -}}+{{- $t := $d.Template -}}+{{- $isNew := $d.IsNew -}}+{{- $base := URI "/admin/templates" -}}+{{- $canManage := $d.Can "templates:manage" -}}++<script>+ const _tpl = {{ ToJSON $t }};+</script>++<section class="templates" x-data="templateForm(_tpl, {{ $isNew }})"+ @keydown.ctrl.s.window.prevent="onSaveShortcut" @keydown.meta.s.window.prevent="onSaveShortcut"+ @keydown.window.prevent.f9="onPreviewBody">+ <header class="row page-header">+ <div class="col-6">+ <div class="hstack gap-1">+ <a href="{{ $base }}" class="back" aria-label="{{ .L.T "globals.buttons.back" }}">{{ Icon "chevron-left" }}</a>+ <h1 class="page-title">+ {{- if $isNew }}{{ .L.T "templates.newTemplate" }}{{ else }}{{ $t.Name }}{{ end -}}+ </h1>+ {{- if and (not $isNew) $t.IsDefault }}<span class="badge enum" data-variant="secondary">{{ .L.T "templates.default" }}</span>{{ end }}+ </div>+ </div>+ <div class="col-6 col-end hstack justify-end">+ <button type="button" class="outline" data-cy="btn-preview" @click="onPreviewBody" aria-keyshortcuts="F9">{{ Icon "eye" }} {{ .L.T "templates.preview" }}</button>+ {{- if $canManage }}+ <button type="button" data-variant="primary" data-cy="btn-save" @click="onSubmit" :disabled="isLoading('templates')" :aria-busy="isLoading('templates')">{{ Icon "save" }} {{ .L.T "globals.buttons.save" }}</button>+ {{- end }}+ </div>+ </header>++ <form @submit.prevent="onSubmit">+ <div class="card page-content content">+ <section class="dialog-body">+ <div class="row">+ <div class="col-9">+ <label data-field>+ {{ .L.T "globals.fields.name" }}+ <input name="name" maxlength="200" autofocus required x-model="form.name" placeholder="{{ .L.T "globals.fields.name" }}" />+ </label>+ </div>+ <div class="col-3">+ <label data-field>+ {{ .L.T "globals.fields.type" }}+ <select name="type" x-model="form.type" {{ if not $isNew }}disabled{{ end }}>+ <option value="campaign">{{ .L.Tc "templates.typeCampaignHTML" 1 }}</option>+ <option value="campaign_visual">{{ .L.Tc "templates.typeCampaignVisual" 1 }}</option>+ <option value="tx">{{ .L.Tc "templates.typeTransactional" 1 }}</option>+ </select>+ </label>+ </div>+ </div>++ <template x-if="form.type === 'tx'">+ <label data-field>+ {{ .L.T "templates.subject" }}+ <input name="subject" maxlength="200" x-model="form.subject" placeholder="{{ .L.T "templates.subject" }}" />+ </label>+ </template>++ <div class="editor-body">+ <template x-if="form.type === 'campaign_visual'">+ <visual-editor base="{{ URI "/admin/static/email-builder" }}" @editor-change="form.body = $event.detail.body; form.body_source = $event.detail.source"><textarea>{{ $t.BodySource.String }}</textarea></visual-editor>+ </template>+ <template x-if="form.type !== 'campaign_visual'">+ <code-editor lang="html" @input="form.body = $event.target.value"><textarea>{{ $t.Body }}</textarea></code-editor>+ </template>+ </div>++ <p class="text-7 text-light mt-2">+ <template x-if="form.type === 'campaign'">+ <span>{{ .L.Ts "templates.placeholderHelp" "placeholder" "{{ template \"content\" . }}" }}</span>+ </template>+ <a href="https://listmonk.app/docs/templating" target="_blank" rel="noopener noreferrer">{{ Icon "link-2" }} {{ .L.T "globals.buttons.learnMore" }}</a>+ </p>+ </section>+ </div>+ </form>++ {{ template "template-preview" . }}+</section>++<script type="module" src="{{ URI "/admin/static/js/views/templates.js" }}?v={{ .AssetVersion }}" defer></script>+<script type="module" src="{{ URI "/admin/static/js/code-editor.js" }}?v={{ .AssetVersion }}" defer></script>+<script type="module" src="{{ URI "/admin/static/js/visual-editor.js" }}?v={{ .AssetVersion }}" defer></script>++{{ template "admin-footer" . -}}+{{ end }}diff --git a/static/admin/views/templates.html b/static/admin/views/templates.htmlnew file mode 100644index 00000000..c8c2d11e--- /dev/null+++ b/static/admin/views/templates.html@@ -0,0 +1,96 @@+{{ define "admin-templates" -}}+{{ template "admin-header" . }}+{{- $d := .Data -}}+{{- $base := URI "/admin/templates" -}}+{{- $canManage := $d.Can "templates:manage" -}}++<section class="templates" x-data="templatesView">+ <header class="row page-header">+ <div class="col-6">+ <h1 class="page-title">+ {{ .L.T "globals.terms.templates" }}+ <span>({{ len $d.Templates }})</span>+ </h1>+ </div>+ <div class="col-6 col-end align-right hstack justify-end">+ {{- if $canManage }}+ <a href="{{ $base }}/new" class="button" data-variant="primary" data-cy="btn-new">+ {{ Icon "plus" }} {{ .L.T "globals.buttons.new" }}+ </a>+ {{- end }}+ </div>+ </header>++ <div class="card page-content has-table">+ <div class="table-wrapper">+ <table>+ <thead>+ <tr>+ <th class="cy-name">{{ .L.T "globals.fields.name" }}</th>+ <th class="cy-type">{{ .L.T "globals.fields.type" }}</th>+ <th class="cy-id">{{ .L.T "globals.fields.id" }}</th>+ <th class="cy-created_at">{{ .L.T "globals.fields.createdAt" }}</th>+ <th class="actions align-right"></th>+ </tr>+ </thead>+ <tbody>+ {{- range $d.Templates }}+ <tr data-id="{{ .ID }}">+ <td>+ <a href="{{ $base }}/{{ .ID }}" data-cy="btn-edit">{{ .Name }}</a>+ {{ if .IsDefault }}<span class="badge">{{ $.L.T "templates.default" }}</span>{{ end }}+ {{- if eq .Type "tx" }}<p class="text-light text-7">{{ .Subject }}</p>{{ end }}+ </td>+ <td>+ <div class="hstack">+ {{- if eq .Type "tx" }}+ <span class="badge enum tx" data-cy="type-tx">{{ $.L.Tc "globals.terms.tx" 1 }}</span>+ {{- else }}+ <span class="badge enum campaign" data-cy="type-campaign">{{ $.L.Tc "globals.terms.campaign" 1 }}</span>+ {{- if eq .Type "campaign_visual" }}+ <span class="badge enum" data-variant="secondary" data-cy="type-campaign_visual">{{ $.L.T "campaigns.visual" }}</span>+ {{- else }}+ <span class="badge enum" data-variant="secondary" data-cy="format-html">HTML</span>+ {{- end }}+ {{- end }}+ </div>+ </td>+ <td>{{ .ID }}</td>+ <td class="date-stack">{{ NiceDate .CreatedAt }}</td>+ <td class="actions align-right">+ <ot-dropdown>+ <button popovertarget="tpl-actions-{{ .ID }}" type="button" class="ghost small icon" aria-label="{{ $.L.T "globals.buttons.more" }}">+ {{ Icon "more-vertical" }}+ </button>+ <menu popover id="tpl-actions-{{ .ID }}">+ <button type="button" role="menuitem" class="ghost" data-cy="btn-preview" @click.prevent="onPreview({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "eye" }} {{ $.L.T "templates.preview" }}</button>+ <a href="{{ $base }}/{{ .ID }}" role="menuitem" class="button ghost" data-cy="btn-edit">{{ Icon "edit-2" }} {{ $.L.T "globals.buttons.edit" }}</a>+ {{- if $canManage }}+ <button type="button" role="menuitem" class="ghost" data-cy="btn-clone" @click.prevent="onClone({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "copy" }} {{ $.L.T "globals.buttons.clone" }}</button>+ {{- if and (not .IsDefault) (eq .Type "campaign") }}+ <button type="button" role="menuitem" class="ghost" data-cy="btn-set-default" :disabled="isLoading('templates')" @click.prevent="onSetDefault({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "check-circle" }} {{ $.L.T "templates.makeDefault" }}</button>+ {{- end }}+ {{- if not .IsDefault }}+ <hr />+ <button type="button" role="menuitem" class="ghost" data-variant="danger" data-cy="btn-delete" :disabled="isLoading('templates')" @click.prevent="onDelete({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "trash-2" }} {{ $.L.T "globals.buttons.delete" }}</button>+ {{- end }}+ {{- end }}+ </menu>+ </ot-dropdown>+ </td>+ </tr>+ {{- else }}+ <tr><td colspan="6" class="align-center text-light">{{ .L.T "globals.messages.emptyState" }}</td></tr>+ {{- end }}+ </tbody>+ </table>+ </div>+ </div>++ {{ template "template-preview" . }}+</section>++<script type="module" src="{{ URI "/admin/static/js/views/templates.js" }}?v={{ .AssetVersion }}" defer></script>++{{ template "admin-footer" . -}}+{{ end }}