Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

6.3 KB
Raw Blame
{{ define "admin-templates" -}}
{{ template "admin-header" . }}
{{ template "breadcrumbs" dict "Root" . "Current" .Data.Title "Parents" (list (dict "Label" (.L.T "globals.terms.campaigns") "URL" (URI "/admin/campaigns") "CanLink" (.Data.Can "campaigns:get" "campaigns:get_all"))) }}
{{- $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-4">
			<h1 class="page-title">
				{{ .L.T "globals.terms.templates" }}
				<span>({{ len $d.Templates }})</span>
				{{- if $d.Type }}
					{{- $label := $d.Type }}
					{{- if eq $d.Type "tx" }}{{ $label = .L.Tc "globals.terms.tx" 1 }}
					{{- else if eq $d.Type "campaign_visual" }}{{ $label = .L.T "editor.contentType.visual" }}
					{{- else if eq $d.Type "campaign" }}{{ $label = .L.Tc "globals.terms.campaign" 1 }}{{ end }}
					{{ template "filter-badge" dict "Label" $label "Class" "enum" "URL" ($d.Page.FilterURL $base "type") }}
				{{- end }}
			</h1>
		</div>
		<div class="col-8 hstack justify-end buttons">
			<form method="get" action="{{ URI "/admin/templates" }}" class="search-form">
				{{- $d.Page.FormFields "query" -}}
				<fieldset class="group">
					<input name="query" aria-label="{{ .L.T "globals.buttons.search" }}" data-testid="query" placeholder="{{ .L.T "globals.buttons.search" }}" value="{{ $d.Page.Query }}" autofocus />
					<button type="submit" class="outline external" data-testid="btn-query" aria-label="{{ .L.T "globals.buttons.search" }}">{{ Icon "search" }}</button>
				</fieldset>
			</form>
			{{- if $canManage }}
				<a href="{{ $base }}/new" class="button" data-variant="primary" data-testid="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>{{ $d.Page.SortLink $base "name" (.L.T "globals.fields.name") }}</th>
						<th>{{ $d.Page.SortLink $base "type" (.L.T "globals.fields.type") }}</th>
						<th>{{ $d.Page.SortLink $base "created_at" (.L.T "globals.fields.createdAt") }}</th>
						<th class="actions align-right"></th>
					</tr>
				</thead>
				<tbody>
					{{- range $d.Templates }}
						<tr data-testid="template-row" data-id="{{ .ID }}">
							<td>
								{{- $kind := "campaign-template" -}}
								{{- if eq .Type "tx" }}{{ $kind = "tx-template" }}{{ else if eq .Type "campaign_visual" }}{{ $kind = "campaign-visual-template" }}{{ end -}}
								<div class="avatar">
									{{ template "avatar-icon" dict "Kind" $kind "Name" .Name "Href" (printf "%s/%d" $base .ID) "Title" (printf "%s %s" ($.L.T "globals.buttons.view") .Name) }}
									<div class="avatar-label">
										<a href="{{ $base }}/{{ .ID }}" class="unstyled {{ if .IsDefault }}default{{ end }}" data-testid="btn-edit">{{ .Name }}</a>
										{{ if .IsDefault }}{{ Badge ($.L.T "globals.terms.default") }}{{ end }}
										{{- if eq .Type "tx" }}<p class="text-light">{{ .Subject }}</p>{{ end }}
									</div>
								</div>
							</td>
							<td>
								<div class="hstack">
									{{- if eq .Type "tx" }}
										<a href="{{ $base }}?{{ $d.Page.Encode "type" }}&type={{ .Type }}" title="{{ $.L.T "globals.buttons.filter" }} {{ $.L.Tc "globals.terms.tx" 1 }}">{{ Badge (list (Icon "terminal") ($.L.Tc "globals.terms.tx" 1)) "enum" }}</a>
									{{- else }}
										<a href="{{ $base }}?{{ $d.Page.Encode "type" }}&type={{ .Type }}" title="{{ $.L.T "globals.buttons.filter" }} {{ $.L.Tc "globals.terms.campaign" 1 }}">{{ Badge (list (Icon "send") ($.L.Tc "globals.terms.campaign" 1)) "enum" }}</a>
										{{- if eq .Type "campaign_visual" }}
											<a href="{{ $base }}?{{ $d.Page.Encode "type" }}&type={{ .Type }}" title="{{ $.L.T "globals.buttons.filter" }} {{ $.L.T "editor.contentType.visual" }}">{{ Badge (list (Icon "eye") ($.L.T "editor.contentType.visual")) "enum" }}</a>
										{{- else }}
											<a href="{{ $base }}?{{ $d.Page.Encode "type" }}&type={{ .Type }}" title="{{ $.L.T "globals.buttons.filter" }} HTML">{{ Badge (list (Icon "code") "HTML") "enum" }}</a>
										{{- end }}
									{{- end }}
								</div>
							</td>
							<td class="date-stack" data-label="{{ $.L.T "globals.fields.createdAt" }}">{{ NiceDate .CreatedAt }}</td>
							<td class="actions align-right">
								<ot-dropdown>
									<button popovertarget="tpl-actions-{{ .ID }}" type="button" class="ghost more 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-testid="btn-preview" @click.prevent="onPreview({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "eye" }} {{ $.L.T "globals.buttons.preview" }}</button>
										<hr />
										<a href="{{ $base }}/{{ .ID }}" role="menuitem" class="button ghost" data-testid="btn-edit">{{ Icon "edit-2" }} {{ $.L.T "globals.buttons.edit" }}</a>
										{{- if $canManage }}
											<button type="button" role="menuitem" class="ghost" data-testid="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-testid="btn-set-default" :disabled="isLoading('templates')" @click.prevent="onSetDefault({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "check-circle" }} {{ $.L.T "globals.buttons.setDefault" }}</button>
											{{- end }}
											{{- if not .IsDefault }}
												<hr />
												<button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="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 }}
						{{ template "empty-state" 6 }}
					{{- 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 }}