Skip to content

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

Make subscriber and list new/edit form a standalone page instead of dialog.

Kailash Nadhcc8abd0d7429
diff --git a/VERSION b/VERSION
index 4df4b1dc..d18077c2 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1 @@
-$Format:%h$
-$Format:%D$
+v7.0.0
diff --git a/cmd/handlers.go b/cmd/handlers.go
index 03ce7c29..81ceec64 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -74,6 +74,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
g.GET(path.Join(uriAdmin, "/custom.js"), serveCustomAppearance("admin.custom_js"))
g.GET(uriAdmin, a.ViewDashboard)
g.GET(path.Join(uriAdmin, "/lists"), a.ViewLists)
+ g.GET(path.Join(uriAdmin, "/lists/new"), a.ViewNewList)
g.GET(path.Join(uriAdmin, "/lists/:id"), hasID(a.ViewList))
g.GET(path.Join(uriAdmin, "/lists/forms"), a.ViewForms)
g.GET(path.Join(uriAdmin, "/campaigns"), a.ViewCampaigns)
@@ -92,6 +93,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
g.POST(path.Join(uriAdmin, "/subscribers"), a.ViewSubscribers)
g.GET(path.Join(uriAdmin, "/subscribers/lists/:id"), hasID(a.ViewSubscribers))
g.POST(path.Join(uriAdmin, "/subscribers/lists/:id"), hasID(a.ViewSubscribers))
+ g.GET(path.Join(uriAdmin, "/subscribers/new"), a.ViewNewSubscriber)
g.GET(path.Join(uriAdmin, "/subscribers/:id"), hasID(a.ViewSubscriber))
g.GET(path.Join(uriAdmin, "/subscribers/:id/lists"), hasID(a.ViewSubscriber))
g.GET(path.Join(uriAdmin, "/subscribers/:id/bounces"), hasID(a.ViewSubscriberBounces))
diff --git a/cmd/lists.go b/cmd/lists.go
index 3d03526b..ada3407b 100644
--- a/cmd/lists.go
+++ b/cmd/lists.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"net/http"
"strings"
@@ -34,7 +35,8 @@ type listsView struct {
type listView struct {
adminView
- List models.List
+ IsNew bool
+ List models.List
}
// publicListForm is the minimal list representation used by the forms view.
@@ -83,6 +85,16 @@ func (a *App) ViewLists(c echo.Context) error {
return c.Render(http.StatusOK, "admin-lists", data)
}
+// ViewNewList renders the new list page.
+func (a *App) ViewNewList(c echo.Context) error {
+ data := listView{
+ adminView: newAdminView(c, fmt.Sprintf("%s / %s", a.i18n.T("lists.newList"), a.i18n.T("globals.terms.lists")), "", "lists.all"),
+ IsNew: true,
+ }
+
+ return c.Render(http.StatusOK, "admin-list", data)
+}
+
// ViewList renders the HTML view for editing a list.
func (a *App) ViewList(c echo.Context) error {
user := auth.GetUser(c)
diff --git a/cmd/roles.go b/cmd/roles.go
index da9d09c4..efd6e7ba 100644
--- a/cmd/roles.go
+++ b/cmd/roles.go
@@ -38,7 +38,7 @@ type permGroup struct {
type roleFormView struct {
adminView
- IsEditing bool
+ IsNew bool
Role any
PermGroups []permGroup
AllLists []models.List
@@ -101,8 +101,8 @@ func (a *App) ViewUserRole(c echo.Context) error {
}
var (
- role auth.Role
- isEditing bool
+ role auth.Role
+ isNew = true
)
if c.Get("id") != nil {
r, err := a.core.GetRole(getID(c))
@@ -110,7 +110,7 @@ func (a *App) ViewUserRole(c echo.Context) error {
return err
}
role = r
- isEditing = true
+ isNew = false
}
groups, err := a.parsePermGroups()
@@ -119,14 +119,14 @@ func (a *App) ViewUserRole(c echo.Context) error {
}
title := a.i18n.T("users.newUserRole")
- if isEditing {
+ if !isNew {
title = role.Name.String
}
title += " / " + a.i18n.T("users.userRoles")
data := roleFormView{
adminView: newAdminView(c, title, "", "users.user-roles"),
- IsEditing: isEditing,
+ IsNew: isNew,
Role: role,
PermGroups: groups,
}
@@ -141,8 +141,8 @@ func (a *App) ViewListRole(c echo.Context) error {
}
var (
- role auth.ListRole
- isEditing bool
+ role auth.ListRole
+ isNew = true
)
if c.Get("id") != nil {
// There's no core getter for a single list role, so fetch all and pick the one.
@@ -162,7 +162,7 @@ func (a *App) ViewListRole(c echo.Context) error {
if !found {
return echo.NewHTTPError(http.StatusNotFound, a.i18n.Ts("globals.messages.notFound", "name", "{users.listRole}"))
}
- isEditing = true
+ isNew = false
}
// All lists for the list-permission selector.
@@ -172,14 +172,14 @@ func (a *App) ViewListRole(c echo.Context) error {
}
title := a.i18n.T("users.newListRole")
- if isEditing {
+ if !isNew {
title = role.Name.String
}
title += " / " + a.i18n.T("users.listRoles")
data := roleFormView{
adminView: newAdminView(c, title, "", "users.list-roles"),
- IsEditing: isEditing,
+ IsNew: isNew,
Role: role,
AllLists: lists,
}
diff --git a/cmd/subscribers.go b/cmd/subscribers.go
index 7666b3f1..aa2eea8c 100644
--- a/cmd/subscribers.go
+++ b/cmd/subscribers.go
@@ -81,6 +81,7 @@ type subscribersView struct {
type subscriberView struct {
adminView
+ IsNew bool
Tab string
Subscriber models.Subscriber
AllLists []models.List
@@ -144,6 +145,22 @@ func (a *App) ViewSubscribers(c echo.Context) error {
return c.Render(http.StatusOK, "admin-subscribers", data)
}
+// ViewNewSubscriber renders the new subscriber page.
+func (a *App) ViewNewSubscriber(c echo.Context) error {
+ allLists, err := a.getViewableLists(c)
+ if err != nil {
+ return err
+ }
+
+ data := subscriberView{
+ adminView: newAdminView(c, fmt.Sprintf("%s / %s", a.i18n.T("subscribers.newSubscriber"), a.i18n.T("globals.terms.subscribers")), "", "subscribers.all"),
+ IsNew: true,
+ AllLists: allLists,
+ }
+
+ return c.Render(http.StatusOK, "admin-subscriber", data)
+}
+
// ViewSubscriber renders the profile and subscriptions tabs of a subscriber.
func (a *App) ViewSubscriber(c echo.Context) error {
out, err := a.getViewSubscriber(c)
diff --git a/cmd/users.go b/cmd/users.go
index 4afd8975..a3656f5e 100644
--- a/cmd/users.go
+++ b/cmd/users.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"net/http"
"regexp"
"strconv"
@@ -48,7 +49,7 @@ type userView struct {
adminView
User auth.User
- IsEditing bool
+ IsNew bool
UserRoles []auth.Role
ListRoles []auth.ListRole
}
@@ -109,17 +110,18 @@ func (a *App) ViewUser(c echo.Context) error {
}
var (
- user auth.User
- isEditing bool
+ user auth.User
+ isNew = true
)
if c.Get("id") != nil {
out, err := a.core.GetUser(getID(c), "", "")
if err != nil {
return err
}
+
out.Password = null.String{}
user = out
- isEditing = true
+ isNew = false
}
// Roles for the role selectors.
@@ -129,15 +131,15 @@ func (a *App) ViewUser(c echo.Context) error {
}
title := a.i18n.T("users.newUser")
- if isEditing {
+ if !isNew {
title = user.Name
}
- title += " / " + a.i18n.T("globals.terms.users")
+ title = fmt.Sprintf("%s / %s", title, a.i18n.T("globals.terms.users"))
data := userView{
adminView: newAdminView(c, title, "", "users.users"),
User: user,
- IsEditing: isEditing,
+ IsNew: isNew,
UserRoles: userRoles,
ListRoles: listRoles,
}
diff --git a/static/admin/assets/js/views/lists.js b/static/admin/assets/js/views/lists.js
index 27a690fd..2093d4c7 100644
--- a/static/admin/assets/js/views/lists.js
+++ b/static/admin/assets/js/views/lists.js
@@ -1,6 +1,7 @@
import Alpine from 'alpinejs';
import {
api,
+ urls,
config,
i18n,
} from '../main.js';
@@ -29,22 +30,9 @@ function component(list = null) {
// ===============
// Event handlers.
- onOpenNew() {
- this._resetForm();
- this._openDialog();
- },
-
- onClose() {
- this.$refs.dialog.close();
- },
-
- onDialogClose() {
- this._resetForm();
- },
-
async onSubmitNew() {
const data = await api('lists.save', '/lists', 'POST', this._payload());
- u.reload({ message: i18n.ts('globals.messages.created', { name: data.name }) });
+ u.redirect(`${urls.admin}/lists`, { message: i18n.ts('globals.messages.created', { name: data.name }) });
},
async onSubmitUpdate() {
@@ -97,14 +85,6 @@ function component(list = null) {
// ===============
// Public functions.
- get isEditing() {
- return this.form.id !== null;
- },
-
- get dialogTitle() {
- return this.isEditing ? this.form.name : i18n.t('lists.newList');
- },
-
get isArchived() {
return this.form.status === 'archived';
},
@@ -115,15 +95,6 @@ function component(list = null) {
// ===============
// Private functions.
- _resetForm() {
- this.form = makeForm();
- },
-
- _openDialog() {
- this.$refs.dialog.showModal();
- this.$nextTick(() => this.$refs.name.focus());
- },
-
_payload() {
return {
name: this.form.name,
diff --git a/static/admin/assets/js/views/roles.js b/static/admin/assets/js/views/roles.js
index 768d9131..006501aa 100644
--- a/static/admin/assets/js/views/roles.js
+++ b/static/admin/assets/js/views/roles.js
@@ -46,7 +46,7 @@ function rolesView({ type = 'user' } = {}) {
}
// roleForm is the add/edit form page component (user or list roles).
-function roleForm({ type = 'user', isEditing = false, canManage = false } = {}) {
+function roleForm({ type = 'user', isNew = true, canManage = false } = {}) {
const role = window._role || {};
const permGroups = window._permGroups || [];
const allLists = window._lists || [];
@@ -81,11 +81,11 @@ function roleForm({ type = 'user', isEditing = false, canManage = false } = {})
return {
// The primordial super admin role (id 1) or lacking manage permission disables the form.
- disabled: !canManage || (isEditing && role.id === 1),
- form: isEditing ? fromRole() : { ...makeForm(), permissions: type === 'user' ? defaultUserPerms() : [] },
+ disabled: !canManage || (!isNew && role.id === 1),
+ form: !isNew ? fromRole() : { ...makeForm(), permissions: type === 'user' ? defaultUserPerms() : [] },
- get isEditing() {
- return isEditing;
+ get isNew() {
+ return isNew;
},
// Lists not yet added to the role.
@@ -126,7 +126,7 @@ function roleForm({ type = 'user', isEditing = false, canManage = false } = {})
if (this.disabled) {
return;
}
- if (this.isEditing) {
+ if (!this.isNew) {
this.updateRole();
} else {
this.createRole();
diff --git a/static/admin/assets/js/views/subscribers.js b/static/admin/assets/js/views/subscribers.js
index 9e4a54f4..9e5c0115 100644
--- a/static/admin/assets/js/views/subscribers.js
+++ b/static/admin/assets/js/views/subscribers.js
@@ -56,26 +56,13 @@ function component(sub = null) {
// ===============
// New / edit form.
- onOpenNew() {
- this.form = makeForm();
- this.$refs.dialog.showModal();
- },
-
- onClose() {
- this.$refs.dialog.close();
- },
-
- onDialogClose() {
- this.form = makeForm();
- },
-
async onSubmitNew() {
const payload = this._payload();
if (!payload) {
return;
}
const data = await api('subscribers.save', '/subscribers', 'POST', payload);
- u.reload({ message: i18n.ts('globals.messages.created', { name: data.email }) });
+ u.redirect(`${urls.admin}/subscribers`, { message: i18n.ts('globals.messages.created', { name: data.email }) });
},
async onSubmitUpdate() {
diff --git a/static/admin/assets/js/views/users.js b/static/admin/assets/js/views/users.js
index e6c5892b..a23570da 100644
--- a/static/admin/assets/js/views/users.js
+++ b/static/admin/assets/js/views/users.js
@@ -40,7 +40,7 @@ function usersView() {
}
// userForm is the add/edit form page component.
-function userForm({ isEditing = false, canSave = false } = {}) {
+function userForm({ isNew = true, canSave = false } = {}) {
const user = window._user || {};
const userRoles = window._userRoles || [];
@@ -70,19 +70,19 @@ function userForm({ isEditing = false, canSave = false } = {}) {
});
return {
- form: isEditing ? fromUser(user) : makeForm(),
+ form: !isNew ? fromUser(user) : makeForm(),
apiToken: null,
createdName: '',
- get isEditing() {
- return isEditing;
+ get isNew() {
+ return isNew;
},
onSubmit() {
if (!canSave || !this._validate()) {
return;
}
- if (isEditing) {
+ if (!isNew) {
this.updateUser();
} else {
this.createUser();
diff --git a/static/admin/partials/list-form.html b/static/admin/partials/list-form.html
index b72962c1..80109a9f 100644
--- a/static/admin/partials/list-form.html
+++ b/static/admin/partials/list-form.html
@@ -1,18 +1,10 @@
{{ define "list-form" -}}
{{- $root := .Root -}}
{{- $submit := .Submit -}}
-{{- $method := .Method -}}
-{{- $isDialog := eq $method "dialog" -}}
{{- $canSave := .CanSave -}}
-<form method="{{ $method }}" @submit.prevent="{{ $submit }}">
- <div class="{{ if $isDialog }}dialog-card content{{ else }}card page-content content{{ end }}">
- {{- if $isDialog }}
- <header class="dialog-head">
- <h4 class="dialog-title">{{ $root.L.T "globals.terms.new" }} {{ $root.L.T "globals.terms.list" }}</h4>
- </header>
- {{ end }}
-
- <section class="dialog-body">
+<form method="post" @submit.prevent="{{ $submit }}">
+ <div class="page-content content">
+ <section class="card">
<label data-field>
{{ $root.L.T "globals.fields.name" }}
<input name="name" maxlength="200" autofocus required x-model="form.name" />
@@ -51,31 +43,24 @@
<small data-hint>{{ $root.L.T "lists.archivedHelp" }}</small>
</label>
</section>
- {{- if $isDialog }}
- <footer class="dialog-foot hstack gap-3 justify-end">
- <button type="button" class="outline" @click="onClose">{{ $root.L.T "globals.buttons.close" }}</button>
- {{- if $canSave }}
- <button type="submit" data-variant="primary" data-testid="btn-save" data-spinner="small" :disabled="isLoading('lists.save')" :aria-busy="isLoading('lists.save')">{{ $root.L.T "globals.buttons.save" }}</button>
- {{- end }}
- </footer>
- {{- else }}
- <footer class="dialog-foot hstack justify-between mt-6">
- <div class="hstack gap-1">
+ <footer class="hstack justify-between mt-6">
+ <div class="hstack gap-1">
+ {{- if not .IsNew }}
<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>
- <div class="hstack gap-3 justify-end">
- <a href="{{ URI "/admin/lists" }}" class="button outline">{{ $root.L.T "globals.buttons.back" }}</a>
- {{- if $canSave }}
- <button type="submit" data-variant="primary" data-testid="btn-save" data-spinner="small" :disabled="isLoading('lists.save')" :aria-busy="isLoading('lists.save')">{{ $root.L.T "globals.buttons.save" }}</button>
- {{- end }}
- </div>
- </footer>
- {{- end }}
+ {{- end }}
+ </div>
+ <div class="hstack gap-3 justify-end">
+ <a href="{{ URI "/admin/lists" }}" class="button outline">{{ $root.L.T "globals.buttons.back" }}</a>
+ {{- if $canSave }}
+ <button type="submit" data-variant="primary" data-testid="btn-save" data-spinner="small" :disabled="isLoading('lists.save')" :aria-busy="isLoading('lists.save')">{{ $root.L.T "globals.buttons.save" }}</button>
+ {{- end }}
+ </div>
+ </footer>
</div>
</form>
{{- end }}
diff --git a/static/admin/partials/subscriber-form.html b/static/admin/partials/subscriber-form.html
index 9df3cdf9..5668a112 100644
--- a/static/admin/partials/subscriber-form.html
+++ b/static/admin/partials/subscriber-form.html
@@ -1,51 +1,39 @@
{{ define "subscriber-form" -}}
{{- $root := .Root -}}
{{- $submit := .Submit -}}
-{{- $method := .Method -}}
-{{- $isDialog := eq $method "dialog" -}}
{{- $canSave := .CanSave -}}
-<form method="{{ $method }}" @submit.prevent="{{ $submit }}">
- <div class="{{ if $isDialog }}dialog-card content{{ else }}card page-content content{{ end }}">
- {{- if $isDialog }}
- <header class="dialog-head">
- <h4 class="dialog-title">{{ $root.L.T "subscribers.newSubscriber" }}</h4>
- </header>
-
- <section class="dialog-body">
- {{ template "subscriber-fields" $root }}
+<form method="post" @submit.prevent="{{ $submit }}">
+ <div class="page-content content">
+ <section class="card">
+ {{ template "subscriber-fields" $root }}
+ {{- if .IsNew }}
{{ template "list-selector" dict "Root" $root "Model" "form.lists" "ListID" "form-lists" "Label" "subscribers.lists" "Placeholder" "subscribers.listsPlaceholder" }}
<label data-field :aria-disabled="!hasOptinList">
<input type="checkbox" x-model="form.preconfirm" data-testid="preconfirm" :disabled="!hasOptinList" /> {{ $root.L.T "subscribers.preconfirm" }}
<small data-hint>{{ $root.L.T "subscribers.preconfirmHelp" }}</small>
</label>
- {{ template "subscriber-attribs" $root }}
- </section>
- <footer class="dialog-foot hstack gap-3 justify-end">
- <button type="button" class="outline" @click="onClose">{{ $root.L.T "globals.buttons.close" }}</button>
- {{- if $canSave }}
- <button type="submit" data-variant="primary" data-testid="btn-save" :disabled="isLoading('subscribers.save')" :aria-busy="isLoading('subscribers.save')">{{ $root.L.T "globals.buttons.save" }}</button>
- {{- end }}
- </footer>
- {{- else }}
- {{ template "subscriber-fields" $root }}
+ {{- end }}
{{ template "subscriber-attribs" $root }}
- <footer class="dialog-foot hstack justify-between mt-6">
- <div class="hstack gap-1">
+ </section>
+
+ <footer class="hstack justify-between mt-6">
+ <div class="hstack gap-1">
+ {{- if not .IsNew }}
<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>
- <div class="hstack gap-3 justify-end">
- <a href="{{ URI "/admin/subscribers" }}" class="button outline">{{ $root.L.T "globals.buttons.back" }}</a>
- {{- if $canSave }}
- <button type="submit" data-variant="primary" data-testid="btn-save" :disabled="isLoading('subscribers.save')" :aria-busy="isLoading('subscribers.save')">{{ $root.L.T "globals.buttons.save" }}</button>
- {{- end }}
- </div>
- </footer>
- {{- end }}
+ {{- end }}
+ </div>
+ <div class="hstack gap-3 justify-end">
+ <a href="{{ URI "/admin/subscribers" }}" class="button outline">{{ $root.L.T "globals.buttons.back" }}</a>
+ {{- if $canSave }}
+ <button type="submit" data-variant="primary" data-testid="btn-save" :disabled="isLoading('subscribers.save')" :aria-busy="isLoading('subscribers.save')">{{ $root.L.T "globals.buttons.save" }}</button>
+ {{- end }}
+ </div>
+ </footer>
</div>
</form>
{{- end }}
diff --git a/static/admin/views/list-role.html b/static/admin/views/list-role.html
index 7554decf..7280c54f 100644
--- a/static/admin/views/list-role.html
+++ b/static/admin/views/list-role.html
@@ -8,12 +8,12 @@
window._role = {{ ToJSON $d.Role }};
window._lists = {{ ToJSON $d.AllLists }};
</script>
-<section class="roles" x-data="roleForm({ type: 'list', isEditing: {{ $d.IsEditing }}, canManage: {{ $canManage }} })">
+<section class="roles" x-data="roleForm({ type: 'list', isNew: {{ $d.IsNew }}, canManage: {{ $canManage }} })">
<header class="page-header">
<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 $d.IsEditing }}{{ $d.Role.Name.String }}{{ else }}{{ .L.T "users.newListRole" }}{{ end -}}
+ {{- if not $d.IsNew }}{{ $d.Role.Name.String }}{{ else }}{{ .L.T "users.newListRole" }}{{ end -}}
</h1>
</div>
</header>
@@ -70,7 +70,7 @@
<footer class="hstack justify-between mt-6">
<div class="hstack gap-3">
- {{- if $d.IsEditing }}
+ {{- if not $d.IsNew }}
<button type="button" class="small" data-variant="secondary" title="{{ .L.T "globals.messages.clickToCopy" }}" aria-label="{{ .L.T "globals.fields.id" }}" @click="copyToClipboard(form.id)">
<strong>{{ .L.T "globals.fields.id" }}</strong> <span x-text="form.id"></span>
</button>
diff --git a/static/admin/views/list.html b/static/admin/views/list.html
index e21beca9..eb8590df 100644
--- a/static/admin/views/list.html
+++ b/static/admin/views/list.html
@@ -2,17 +2,21 @@
{{ template "admin-header" . }}
{{- $d := .Data -}}
-<script>const _form = {{ ToJSON $d.List }};</script>
+<script>const _form = {{ if $d.IsNew }}null{{ else }}{{ ToJSON $d.List }}{{ end }};</script>
<section class="lists" x-data="listsView(_form)">
<header class="page-header">
<div class="hstack gap-1">
<a href="{{ URI "/admin/lists" }}" class="back" aria-label="{{ .L.T "globals.buttons.back" }}">{{ Icon "chevron-left" }}</a>
- {{ template "avatar" dict "Seed" (printf "%d" $d.List.ID) "Name" $d.List.Name }}
- <h1 class="page-title">{{ $d.List.Name }}</h1>
+ {{ if not $d.IsNew }}{{ template "avatar" dict "Seed" (printf "%d" $d.List.ID) "Name" $d.List.Name }}{{ end }}
+ <h1 class="page-title">{{ if $d.IsNew }}{{ .L.T "lists.newList" }}{{ else }}{{ $d.List.Name }}{{ end }}</h1>
</div>
</header>
- {{ template "list-form" dict "Root" . "Submit" "onSubmitUpdate" "Method" "post" "CanSave" ($d.CanManageList $d.List.ID) }}
+ {{ if $d.IsNew }}
+ {{ template "list-form" dict "Root" . "Submit" "onSubmitNew" "IsNew" true "CanSave" ($d.Can "lists:manage_all") }}
+ {{ else }}
+ {{ template "list-form" dict "Root" . "Submit" "onSubmitUpdate" "CanSave" ($d.CanManageList $d.List.ID) }}
+ {{ end }}
</section>
<script type="module" src="{{ URI "/admin/static/js/views/lists.js" }}?v={{ .AssetVersion }}" defer></script>
diff --git a/static/admin/views/lists.html b/static/admin/views/lists.html
index fc2dbc1e..3952f6de 100644
--- a/static/admin/views/lists.html
+++ b/static/admin/views/lists.html
@@ -37,9 +37,9 @@
</fieldset>
</form>
{{- if $d.Can "lists:manage_all" }}
- <button type="button" data-variant="primary" class="btn-new" data-testid="btn-new" @click="onOpenNew">
+ <a href="{{ URI "/admin/lists/new" }}" class="button" data-variant="primary" data-testid="btn-new">
{{ Icon "plus" }} {{ .L.T "globals.buttons.new" }}
- </button>
+ </a>
{{- end }}
</div>
</header>
@@ -186,9 +186,6 @@
</div>
</div>
- <dialog x-ref="dialog" @close="onDialogClose">
- {{ template "list-form" dict "Root" . "Submit" "onSubmitNew" "Method" "dialog" "CanSave" true }}
- </dialog>
</section>
<script type="module" src="{{ URI "/admin/static/js/views/lists.js" }}?v={{ .AssetVersion }}" defer></script>
diff --git a/static/admin/views/subscriber.html b/static/admin/views/subscriber.html
index 4e66b7e2..c3b0e929 100644
--- a/static/admin/views/subscriber.html
+++ b/static/admin/views/subscriber.html
@@ -6,17 +6,21 @@
<script>
window._lists = {{ ToJSON $d.AllLists }};
- const _sub = {{ ToJSON $sub }};
+ const _sub = {{ if $d.IsNew }}null{{ else }}{{ ToJSON $sub }}{{ end }};
</script>
<section class="subscribers" x-data="subscribersView(_sub)">
<header class="row page-header">
<div class="col-6">
<div class="hstack gap-1">
<a href="{{ URI "/admin/subscribers" }}" class="back" aria-label="{{ .L.T "globals.buttons.back" }}">{{ Icon "chevron-left" }}</a>
- {{ template "avatar" dict "Seed" (printf "%d" $sub.ID) "Name" (or $sub.Name $sub.Email) }}
+ {{ if not $d.IsNew }}{{ template "avatar" dict "Seed" (printf "%d" $sub.ID) "Name" (or $sub.Name $sub.Email) }}{{ end }}
<h1 class="page-title">
- {{ $sub.Email }}
- {{ if ne $sub.Status "enabled" }}{{ Badge (list (Dot) (.L.T (printf "subscribers.status.%s" $sub.Status))) (printf "status-%s" $sub.Status) }}{{ end }}
+ {{- if $d.IsNew }}
+ {{ .L.T "subscribers.newSubscriber" }}
+ {{- else }}
+ {{ $sub.Email }}
+ {{ if ne $sub.Status "enabled" }}{{ Badge (list (Dot) (.L.T (printf "subscribers.status.%s" $sub.Status))) (printf "status-%s" $sub.Status) }}{{ end }}
+ {{- end }}
</h1>
</div>
</div>
@@ -33,17 +37,21 @@
</div>
</header>
- <div role="tablist">
- <a role="tab" href="{{ $base }}" {{ if eq $d.Tab "profile" }}aria-selected="true"{{ end }}>{{ Icon "user" }} {{ .L.Tc "globals.terms.subscriber" 1 }}</a>
- <a role="tab" href="{{ $base }}/lists" {{ if eq $d.Tab "lists" }}aria-selected="true"{{ end }}>{{ Icon "list" }} {{ .L.Tc "globals.terms.lists" 2 }} ({{ len $sub.ParsedLists }})</a>
- <a role="tab" href="{{ $base }}/activity" {{ if eq $d.Tab "activity" }}aria-selected="true"{{ end }}>{{ Icon "activity" }} {{ .L.T "subscribers.activity" }}</a>
- {{- if $d.Can "bounces:get" }}
- <a role="tab" href="{{ $base }}/bounces" {{ if eq $d.Tab "bounces" }}aria-selected="true"{{ end }}>{{ Icon "corner-right-down" }} {{ .L.T "globals.terms.bounces" }}</a>
- {{- end }}
- </div>
+ {{- if not $d.IsNew }}
+ <div role="tablist">
+ <a role="tab" href="{{ $base }}" {{ if eq $d.Tab "profile" }}aria-selected="true"{{ end }}>{{ Icon "user" }} {{ .L.Tc "globals.terms.subscriber" 1 }}</a>
+ <a role="tab" href="{{ $base }}/lists" {{ if eq $d.Tab "lists" }}aria-selected="true"{{ end }}>{{ Icon "list" }} {{ .L.Tc "globals.terms.lists" 2 }} ({{ len $sub.ParsedLists }})</a>
+ <a role="tab" href="{{ $base }}/activity" {{ if eq $d.Tab "activity" }}aria-selected="true"{{ end }}>{{ Icon "activity" }} {{ .L.T "subscribers.activity" }}</a>
+ {{- if $d.Can "bounces:get" }}
+ <a role="tab" href="{{ $base }}/bounces" {{ if eq $d.Tab "bounces" }}aria-selected="true"{{ end }}>{{ Icon "corner-right-down" }} {{ .L.T "globals.terms.bounces" }}</a>
+ {{- end }}
+ </div>
+ {{- end }}
- {{- if eq $d.Tab "profile" }}
- {{ template "subscriber-form" dict "Root" . "Submit" "onSubmitUpdate" "Method" "post" "CanSave" ($d.Can "subscribers:manage") }}
+ {{- if $d.IsNew }}
+ {{ template "subscriber-form" dict "Root" . "Submit" "onSubmitNew" "IsNew" true "CanSave" ($d.Can "subscribers:manage") }}
+ {{- else if eq $d.Tab "profile" }}
+ {{ template "subscriber-form" dict "Root" . "Submit" "onSubmitUpdate" "CanSave" ($d.Can "subscribers:manage") }}
{{- else if eq $d.Tab "lists" }}
{{ template "subscriber-lists" dict "Root" . "CanSave" ($d.Can "subscribers:manage") }}
{{- else if eq $d.Tab "bounces" }}
diff --git a/static/admin/views/subscribers.html b/static/admin/views/subscribers.html
index e4772a54..941edd2e 100644
--- a/static/admin/views/subscribers.html
+++ b/static/admin/views/subscribers.html
@@ -55,9 +55,9 @@
</ot-dropdown>
</form>
{{- if $d.Can "subscribers:manage" }}
- <button type="button" data-variant="primary" class="btn-new" data-testid="btn-new" @click="onOpenNew">
+ <a href="{{ URI "/admin/subscribers/new" }}" class="button" data-variant="primary" data-testid="btn-new">
{{ Icon "plus" }} {{ .L.T "globals.buttons.new" }}
- </button>
+ </a>
{{- end }}
</div>
</header>
@@ -164,10 +164,6 @@
</div>
</div>
- <dialog x-ref="dialog" @close="onDialogClose">
- {{ template "subscriber-form" dict "Root" . "Submit" "onSubmitNew" "Method" "dialog" "CanSave" ($d.Can "subscribers:manage") }}
- </dialog>
-
<dialog x-ref="listDialog">
<form @submit.prevent="onSubmitManageLists">
<div class="dialog-card content">
diff --git a/static/admin/views/user-role.html b/static/admin/views/user-role.html
index 47d7ef92..6bb33b0d 100644
--- a/static/admin/views/user-role.html
+++ b/static/admin/views/user-role.html
@@ -8,12 +8,12 @@
window._role = {{ ToJSON $d.Role }};
window._permGroups = {{ ToJSON $d.PermGroups }};
</script>
-<section class="roles" x-data="roleForm({ type: 'user', isEditing: {{ $d.IsEditing }}, canManage: {{ $canManage }} })">
+<section class="roles" x-data="roleForm({ type: 'user', isNew: {{ $d.IsNew }}, canManage: {{ $canManage }} })">
<header class="page-header">
<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 $d.IsEditing }}{{ $d.Role.Name.String }}{{ else }}{{ .L.T "users.newUserRole" }}{{ end -}}
+ {{- if not $d.IsNew }}{{ $d.Role.Name.String }}{{ else }}{{ .L.T "users.newUserRole" }}{{ end -}}
</h1>
</div>
</header>
@@ -74,7 +74,7 @@
<footer class="hstack justify-between mt-6">
<div class="hstack gap-3">
- {{- if $d.IsEditing }}
+ {{- if not $d.IsNew }}
<button type="button" class="small" data-variant="secondary" title="{{ .L.T "globals.messages.clickToCopy" }}" aria-label="{{ .L.T "globals.fields.id" }}" @click="copyToClipboard(form.id)">
<strong>{{ .L.T "globals.fields.id" }}</strong> <span x-text="form.id"></span>
</button>
diff --git a/static/admin/views/user.html b/static/admin/views/user.html
index 0e6d9c58..f89d6b0b 100644
--- a/static/admin/views/user.html
+++ b/static/admin/views/user.html
@@ -8,15 +8,15 @@
window._user = {{ ToJSON $d.User }};
window._userRoles = {{ ToJSON $d.UserRoles }};
</script>
-<section class="users" x-data="userForm({ isEditing: {{ $d.IsEditing }}, canSave: {{ $canSave }} })">
+<section class="users" x-data="userForm({ isNew: {{ $d.IsNew }}, canSave: {{ $canSave }} })">
<header class="page-header">
<div class="hstack gap-1">
<a href="{{ $base }}" class="back" aria-label="{{ .L.T "globals.buttons.back" }}">{{ Icon "chevron-left" }}</a>
- {{- if $d.IsEditing }}{{ template "avatar" dict "Seed" (printf "%d" $d.User.ID) "Name" (or $d.User.Name $d.User.Username) "URL" $d.User.Avatar.String }}{{ end }}
+ {{- if not $d.IsNew }}{{ template "avatar" dict "Seed" (printf "%d" $d.User.ID) "Name" (or $d.User.Name $d.User.Username) "URL" $d.User.Avatar.String }}{{ end }}
<h1 class="page-title">
- {{- if $d.IsEditing }}{{ $d.User.Name }}{{ else }}{{ .L.T "users.newUser" }}{{ end -}}
+ {{- if not $d.IsNew }}{{ $d.User.Name }}{{ else }}{{ .L.T "users.newUser" }}{{ end -}}
</h1>
- {{- if and $d.IsEditing (eq $d.User.Status "disabled") }}{{ Badge (list (Dot) ($.L.T "users.status.disabled")) "enum status-disabled" }}{{ end }}
+ {{- if and (not $d.IsNew) (eq $d.User.Status "disabled") }}{{ Badge (list (Dot) ($.L.T "users.status.disabled")) "enum status-disabled" }}{{ end }}
</div>
</header>
@@ -27,7 +27,7 @@
<legend>{{ .L.T "users.profile" }}</legend>
<div data-field>
<label for="user-type">{{ .L.T "users.type" }}</label>
- <select name="type" id="user-type" autofocus x-model="form.type" :disabled="isEditing">
+ <select name="type" id="user-type" autofocus x-model="form.type" :disabled="!isNew">
<option value="user">{{ .L.T "users.type.user" }}</option>
<option value="api">{{ .L.T "users.type.api" }}</option>
</select>
@@ -68,11 +68,11 @@
</label>
<label data-field>
{{ .L.T "users.password" }}
- <input type="password" name="password" minlength="8" maxlength="200" autocomplete="new-password" :disabled="!form.password_login" :required="form.password_login && !isEditing" x-model="form.password" />
+ <input type="password" name="password" minlength="8" maxlength="200" autocomplete="new-password" :disabled="!form.password_login" :required="form.password_login && isNew" x-model="form.password" />
</label>
<label data-field>
{{ .L.T "users.passwordRepeat" }}
- <input type="password" name="password2" minlength="8" maxlength="200" autocomplete="new-password" :disabled="!form.password_login" :required="form.password_login && !isEditing && form.password" x-model="form.password2" />
+ <input type="password" name="password2" minlength="8" maxlength="200" autocomplete="new-password" :disabled="!form.password_login" :required="form.password_login && isNew && form.password" x-model="form.password2" />
</label>
</fieldset>
</template>
@@ -101,7 +101,7 @@
<footer class="hstack justify-between mt-6">
<div class="hstack gap-1">
- {{- if $d.IsEditing }}
+ {{- if not $d.IsNew }}
<button type="button" class="small" data-variant="secondary" title="{{ .L.T "globals.messages.clickToCopy" }}" aria-label="{{ .L.T "globals.fields.id" }}" @click="copyToClipboard(form.id)">
<strong>{{ .L.T "globals.fields.id" }}</strong> <span x-text="form.id"></span>
</button>
diff --git a/tests/specs/lists.spec.js b/tests/specs/lists.spec.js
index e8e55eb2..c9a99412 100644
--- a/tests/specs/lists.spec.js
+++ b/tests/specs/lists.spec.js
@@ -168,11 +168,12 @@ test.describe('Lists', () => {
await page.goto(LISTS);
await page.getByTestId('btn-new').click();
- const dialog = page.locator('dialog[open]');
- await fillListForm(dialog, {
+ await expect(page).toHaveURL(/\/admin\/lists\/new$/);
+ const form = page.locator('section.lists form');
+ await fillListForm(form, {
name, type: c.type, optin: c.optin, tag: `tag${n}`, description: `desc-${c.type}-${n}`,
});
- await withListAPI(page, 'POST', () => dialog.getByTestId('btn-save').click());
+ await withListAPI(page, 'POST', () => form.getByTestId('btn-save').click());
const row = listRow(page, name);
await expect(row).toBeVisible();
diff --git a/tests/specs/subscribers.spec.js b/tests/specs/subscribers.spec.js
index 03254dfb..2d4c0e20 100644
--- a/tests/specs/subscribers.spec.js
+++ b/tests/specs/subscribers.spec.js
@@ -190,13 +190,14 @@ test.describe('Subscribers: create, edit & delete', () => {
await page.goto(SUBSCRIBERS);
await page.getByTestId('btn-new').click();
- const dialog = page.locator('dialog[open]');
- await dialog.locator('input[name=email]').fill('[email protected]');
- await dialog.locator('input[name=name]').fill('Created');
- await selectList(dialog, 'Default list');
+ await expect(page).toHaveURL(/\/admin\/subscribers\/new$/);
+ const form = page.locator('section.subscribers form');
+ await form.locator('input[name=email]').fill('[email protected]');
+ await form.locator('input[name=name]').fill('Created');
+ await selectList(form, 'Default list');
await Promise.all([
page.waitForResponse((r) => /\/api\/subscribers$/.test(r.url()) && r.request().method() === 'POST'),
- dialog.getByTestId('btn-save').click(),
+ form.getByTestId('btn-save').click(),
]);
// The listing shows the new subscriber on the Default list.
@@ -211,16 +212,17 @@ test.describe('Subscribers: create, edit & delete', () => {
await page.goto(SUBSCRIBERS);
await page.getByTestId('btn-new').click();
- const dialog = page.locator('dialog[open]');
- await dialog.locator('input[name=email]').fill('[email protected]');
- await dialog.locator('input[name=name]').fill('Confirmed');
- await selectList(dialog, 'Opt-in list');
+ await expect(page).toHaveURL(/\/admin\/subscribers\/new$/);
+ const form = page.locator('section.subscribers form');
+ await form.locator('input[name=email]').fill('[email protected]');
+ await form.locator('input[name=name]').fill('Confirmed');
+ await selectList(form, 'Opt-in list');
// Pre-confirm only enables once a double opt-in list is picked.
- await expect(dialog.getByTestId('preconfirm')).toBeEnabled();
- await dialog.getByTestId('preconfirm').check();
+ await expect(form.getByTestId('preconfirm')).toBeEnabled();
+ await form.getByTestId('preconfirm').check();
await Promise.all([
page.waitForResponse((r) => /\/api\/subscribers$/.test(r.url()) && r.request().method() === 'POST'),
- dialog.getByTestId('btn-save').click(),
+ form.getByTestId('btn-save').click(),
]);
// The listing badge shows the Opt-in list subscription as confirmed.