Skip to content

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

5.8 KB
Raw Blame
{{ define "campaign-form" -}}
{{- $root := .Root -}}
{{- $isNew := .IsNew -}}
{{- $canManage := .CanManage -}}
{{- $canSend := .CanSend -}}
{{- $submit := "onSave" -}}{{ if $isNew }}{{ $submit = "onCreate" }}{{ end }}
<div class="page-content content">
	<form @submit.prevent="{{ $submit }}">
		<section>
			<fieldset class="card">
				<legend>{{ $root.L.Tc "globals.terms.campaign" 1 }}</legend>
				<label data-field>
					{{ $root.L.T "globals.fields.name" }}
					<input name="name" maxlength="200" x-model="form.name" :disabled="!canEdit" autofocus required />
				</label>

				<label data-field>
					{{ $root.L.T "globals.fields.subject" }}
					<input name="subject" maxlength="5000" x-model="form.subject" :disabled="!canEdit" required />
				</label>

				<label data-field>
					{{ $root.L.T "globals.terms.tags" }}
					<ot-taginput x-model="form.tags" :disabled="!canEdit"><input placeholder="{{ $root.L.T "globals.terms.tags" }}" maxlength="200" /></ot-taginput>
				</label>
			</fieldset>

			<fieldset class="card">
				<legend>{{ $root.L.T "globals.terms.lists" }}</legend>
				{{ template "list-selector" dict "Root" $root "Model" "form.lists" "ListID" "campaign-lists" "Placeholder" "campaigns.sendToLists" "Disabled" "!canEdit" }}
			</fieldset>

			<fieldset class="card">
				<legend>{{ $root.L.Tc "globals.terms.messenger" 1 }}</legend>
				<div data-field>
					<label for="campaign-from-email">{{ $root.L.T "globals.fields.fromAddress" }}</label>
					<input id="campaign-from-email" name="from_email" list="campaign-from-emails" maxlength="2000" x-model="form.from_email" :disabled="!canEdit" placeholder="{{ $root.L.T "campaigns.fromAddressPlaceholder" }}" required />
					<datalist id="campaign-from-emails">
						{{- range $root.ConfigJS.FromEmails }}<option value="{{ . }}"></option>{{ end }}
					</datalist>
				</div>

				<label data-field for="messenger">
					{{ $root.L.Tc "globals.terms.messenger" 1 }}
					<select id="messenger" name="messenger" x-model="form.messenger" :disabled="!canEdit" required>
						{{- range $root.ConfigJS.Messengers }}<option value="{{ . }}">{{ . }}</option>{{ end }}
					</select>
				</label>

				<label data-field for="content_type">
					{{ $root.L.T "globals.fields.format" }}
					<select id="content_type" name="content_type" x-model="form.content_type" {{ if not $isNew }}disabled{{ else }}:disabled="!canEdit"{{ end }}>
						<option value="richtext">{{ $root.L.T "editor.contentType.richtext" }}</option>
						<option value="html">{{ $root.L.T "editor.contentType.html" }}</option>
						<option value="markdown">{{ $root.L.T "editor.contentType.markdown" }}</option>
						<option value="plain">{{ $root.L.T "editor.contentType.plain" }}</option>
						<option value="visual">{{ $root.L.T "editor.contentType.visual" }}</option>
					</select>
				</label>
			</fieldset>

			<fieldset class="card">
				<legend>{{ $root.L.T "campaigns.schedule" }}</legend>
				<div class="row">
					<div class="col-6">
						<label data-field>
							<input type="checkbox" role="switch" x-model="form.sendLater" @change="onToggleSendLater" :disabled="!canEdit" /> {{ $root.L.T "campaigns.sendLater" }}
						</label>

						<template x-if="form.sendLater">
							<label data-field>
								{{ $root.L.T "globals.fields.dateAndTime" }}
								<input type="datetime-local" name="send_at" x-model="form.sendAtLocal" :disabled="!canEdit" />
							</label>
						</template>
					</div>
					{{- if and (not $isNew) $canSend }}
						<div class="col-6 col-end hstack justify-end">
							<button type="button" data-variant="primary" x-cloak x-show="canSchedule" @click="onStart">{{ Icon "clock" }} {{ $root.L.T "campaigns.schedule" }}</button>
							<button type="button" class="outline" data-variant="danger" x-cloak x-show="canUnSchedule" @click="onUnschedule">{{ Icon "clock" }} {{ $root.L.T "globals.buttons.unschedule" }}</button>
						</div>
					{{- end }}
				</div>
			</fieldset>

			<fieldset class="card">
				<legend>{{ $root.L.T "globals.fields.customHeaders" }}</legend>
				<label data-field>
					<input type="checkbox" role="switch" x-model="isHeadersVisible" :disabled="!canEdit" /> {{ $root.L.T "globals.fields.customHeaders" }}
				</label>

				<template x-if="isHeadersVisible">
					<label data-field>
						<textarea name="headers" x-model="form.headersStr" :disabled="!canEdit" placeholder='[{"X-Custom": "value"}]'></textarea>
						<small data-hint>{{ $root.L.T "campaigns.customHeadersHelp" }}</small>
					</label>
				</template>
			</fieldset>
		</section>
		{{- if $isNew }}
			<footer class="hstack justify-end mt-6">
				<button type="submit" data-variant="primary" :disabled="isLoading('campaigns')" data-spinner="small" :aria-busy="isLoading('campaigns')">{{ $root.L.T "globals.buttons.continue" }}</button>
			</footer>
		{{- end }}
	</form>

	{{- if not $isNew }}
		<footer class="hstack justify-between mt-6">
			<div class="hstack gap-1">
				<button type="button" class="small" data-variant="secondary" title="{{ $root.L.T "globals.messages.clickToCopy" }}" aria-label="{{ $root.L.T "globals.fields.id" }}" @click="copyToClipboard(form.id)">
					<strong>{{ $root.L.T "globals.fields.id" }}</strong> <span x-text="form.id"></span>
				</button>
				<button type="button" class="small" data-variant="secondary" title="{{ $root.L.T "globals.messages.clickToCopy" }}" aria-label="{{ $root.L.T "globals.fields.uuid" }}" @click="copyToClipboard(form.uuid)">
					<strong>{{ $root.L.T "globals.fields.uuid" }}</strong> <span x-text="form.uuid"></span>
				</button>
			</div>
			{{- if $canSend }}
				<div class="hstack justify-end gap-1">
					<template x-if="canStart">
						<button type="button" data-variant="primary" @click="onStart">{{ Icon "send" }} {{ $root.L.T "campaigns.start" }}</button>
					</template>
				</div>
			{{- end }}
		</footer>
	{{- end }}
</div>
{{- end }}