mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
Basic new
This commit is contained in:
172
controllers/almanach_new.go
Normal file
172
controllers/almanach_new.go
Normal file
@@ -0,0 +1,172 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
const (
|
||||
URL_ALMANACH_NEW = "/almanach-new/"
|
||||
URL_ALMANACH_NEW_SAVE = "save"
|
||||
)
|
||||
|
||||
func init() {
|
||||
anp := &AlmanachNewPage{
|
||||
StaticPage: pagemodels.StaticPage{
|
||||
Name: pagemodels.P_ALMANACH_NEW_NAME,
|
||||
URL: URL_ALMANACH_NEW,
|
||||
Template: TEMPLATE_ALMANACH_EDIT,
|
||||
Layout: pagemodels.LAYOUT_LOGIN_PAGES,
|
||||
},
|
||||
}
|
||||
app.Register(anp)
|
||||
}
|
||||
|
||||
type AlmanachNewPage struct {
|
||||
pagemodels.StaticPage
|
||||
}
|
||||
|
||||
func (p *AlmanachNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
rg := router.Group(URL_ALMANACH_NEW)
|
||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||
rg.GET("", p.GET(engine, app))
|
||||
rg.POST(URL_ALMANACH_NEW_SAVE, p.POSTSave(engine, app))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *AlmanachNewPage) GET(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
data := make(map[string]any)
|
||||
|
||||
entry, err := newEmptyEntry(app)
|
||||
if err != nil {
|
||||
return engine.Response500(e, err, data)
|
||||
}
|
||||
|
||||
filters := NewBeitraegeFilterParameters(e)
|
||||
result := &AlmanachEditResult{
|
||||
User: nil,
|
||||
AlmanachResult: AlmanachResult{
|
||||
Entry: entry,
|
||||
Places: []*dbmodels.Place{},
|
||||
Series: []*dbmodels.Series{},
|
||||
Contents: []*dbmodels.Content{},
|
||||
Items: []*dbmodels.Item{},
|
||||
Agents: map[string]*dbmodels.Agent{},
|
||||
EntriesSeries: map[string]*dbmodels.REntriesSeries{},
|
||||
EntriesAgents: []*dbmodels.REntriesAgents{},
|
||||
ContentsAgents: map[string][]*dbmodels.RContentsAgents{},
|
||||
Types: []string{},
|
||||
HasScans: false,
|
||||
},
|
||||
Prev: nil,
|
||||
Next: nil,
|
||||
}
|
||||
|
||||
data["result"] = result
|
||||
data["filters"] = filters
|
||||
data["csrf_token"] = req.Session().Token
|
||||
data["item_types"] = dbmodels.ITEM_TYPE_VALUES
|
||||
data["agent_relations"] = dbmodels.AGENT_RELATIONS
|
||||
data["series_relations"] = dbmodels.SERIES_RELATIONS
|
||||
data["is_new"] = true
|
||||
|
||||
abbrs, err := pagemodels.GetAbks(app)
|
||||
if err == nil {
|
||||
data["abbrs"] = abbrs
|
||||
}
|
||||
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *AlmanachNewPage) POSTSave(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
|
||||
payload := almanachEditPayload{}
|
||||
if err := e.BindBody(&payload); err != nil {
|
||||
return e.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": "Ungültige Formulardaten.",
|
||||
})
|
||||
}
|
||||
|
||||
if err := req.CheckCSRF(payload.CSRFToken); err != nil {
|
||||
return e.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
if err := payload.Validate(); err != nil {
|
||||
return e.JSON(http.StatusBadRequest, map[string]any{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
var entry *dbmodels.Entry
|
||||
user := req.User()
|
||||
if err := app.RunInTransaction(func(tx core.App) error {
|
||||
collection, err := tx.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newEntry := dbmodels.NewEntry(core.NewRecord(collection))
|
||||
nextID, err := nextEntryMusenalmID(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newEntry.SetMusenalmID(nextID)
|
||||
|
||||
if err := applyEntryChanges(tx, newEntry, &payload, user); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := applyItemsChanges(tx, newEntry, &payload); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := applySeriesRelations(tx, newEntry, &payload); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := applyAgentRelations(tx, newEntry, &payload); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entry = newEntry
|
||||
return nil
|
||||
}); err != nil {
|
||||
app.Logger().Error("Failed to create almanach entry", "error", err)
|
||||
return e.JSON(http.StatusInternalServerError, map[string]any{
|
||||
"error": "Speichern fehlgeschlagen.",
|
||||
})
|
||||
}
|
||||
|
||||
redirect := "/"
|
||||
if entry != nil {
|
||||
redirect = "/almanach/" + strconv.Itoa(entry.MusenalmID()) + "/edit?saved_message=" + url.QueryEscape("Änderungen gespeichert.")
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, map[string]any{
|
||||
"success": true,
|
||||
"redirect": redirect,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func newEmptyEntry(app core.App) (*dbmodels.Entry, error) {
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
entry := dbmodels.NewEntry(core.NewRecord(collection))
|
||||
entry.SetEditState("Unknown")
|
||||
return entry, nil
|
||||
}
|
||||
54
controllers/musenalm_id.go
Normal file
54
controllers/musenalm_id.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func nextEntryMusenalmID(app core.App) (int, error) {
|
||||
var entry dbmodels.Entry
|
||||
err := app.RecordQuery(dbmodels.ENTRIES_TABLE).
|
||||
OrderBy(dbmodels.MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&entry)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 1, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return entry.MusenalmID() + 1, nil
|
||||
}
|
||||
|
||||
func nextSeriesMusenalmID(app core.App) (int, error) {
|
||||
var series dbmodels.Series
|
||||
err := app.RecordQuery(dbmodels.SERIES_TABLE).
|
||||
OrderBy(dbmodels.MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&series)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 1, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return series.MusenalmID() + 1, nil
|
||||
}
|
||||
|
||||
func nextAgentMusenalmID(app core.App) (int, error) {
|
||||
var agent dbmodels.Agent
|
||||
err := app.RecordQuery(dbmodels.AGENTS_TABLE).
|
||||
OrderBy(dbmodels.MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&agent)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 1, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return agent.MusenalmID() + 1, nil
|
||||
}
|
||||
@@ -247,6 +247,23 @@ type personEditForm struct {
|
||||
Comment string `form:"edit_comment"`
|
||||
}
|
||||
|
||||
func applyPersonForm(agent *dbmodels.Agent, formdata personEditForm, name string, status string, user *dbmodels.FixedUser) {
|
||||
agent.SetName(name)
|
||||
agent.SetPseudonyms(strings.TrimSpace(formdata.Pseudonyms))
|
||||
agent.SetBiographicalData(strings.TrimSpace(formdata.BiographicalData))
|
||||
agent.SetProfession(strings.TrimSpace(formdata.Profession))
|
||||
agent.SetReferences(strings.TrimSpace(formdata.References))
|
||||
agent.SetAnnotation(strings.TrimSpace(formdata.Annotation))
|
||||
agent.SetURI(strings.TrimSpace(formdata.URI))
|
||||
agent.SetCorporateBody(formdata.CorporateBody)
|
||||
agent.SetFictional(formdata.Fictional)
|
||||
agent.SetEditState(status)
|
||||
agent.SetComment(strings.TrimSpace(formdata.Comment))
|
||||
if user != nil {
|
||||
agent.SetEditor(user.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PersonEditPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
id := e.Request.PathValue("id")
|
||||
@@ -288,20 +305,7 @@ func (p *PersonEditPage) POST(engine *templating.Engine, app core.App) HandleFun
|
||||
|
||||
user := req.User()
|
||||
if err := app.RunInTransaction(func(tx core.App) error {
|
||||
agent.SetName(name)
|
||||
agent.SetPseudonyms(strings.TrimSpace(formdata.Pseudonyms))
|
||||
agent.SetBiographicalData(strings.TrimSpace(formdata.BiographicalData))
|
||||
agent.SetProfession(strings.TrimSpace(formdata.Profession))
|
||||
agent.SetReferences(strings.TrimSpace(formdata.References))
|
||||
agent.SetAnnotation(strings.TrimSpace(formdata.Annotation))
|
||||
agent.SetURI(strings.TrimSpace(formdata.URI))
|
||||
agent.SetCorporateBody(formdata.CorporateBody)
|
||||
agent.SetFictional(formdata.Fictional)
|
||||
agent.SetEditState(status)
|
||||
agent.SetComment(strings.TrimSpace(formdata.Comment))
|
||||
if user != nil {
|
||||
agent.SetEditor(user.Id)
|
||||
}
|
||||
applyPersonForm(agent, formdata, name, status, user)
|
||||
return tx.Save(agent)
|
||||
}); err != nil {
|
||||
app.Logger().Error("Failed to save agent", "agent_id", agent.Id, "error", err)
|
||||
|
||||
144
controllers/person_new.go
Normal file
144
controllers/person_new.go
Normal file
@@ -0,0 +1,144 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
const (
|
||||
URL_PERSONEN_NEW = "/personen/new/"
|
||||
)
|
||||
|
||||
func init() {
|
||||
pnp := &PersonNewPage{
|
||||
StaticPage: pagemodels.StaticPage{
|
||||
Name: pagemodels.P_PERSON_NEW_NAME,
|
||||
URL: URL_PERSONEN_NEW,
|
||||
Template: TEMPLATE_PERSON_EDIT,
|
||||
Layout: pagemodels.LAYOUT_LOGIN_PAGES,
|
||||
},
|
||||
}
|
||||
app.Register(pnp)
|
||||
}
|
||||
|
||||
type PersonNewPage struct {
|
||||
pagemodels.StaticPage
|
||||
}
|
||||
|
||||
func (p *PersonNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
rg := router.Group(URL_PERSONEN_NEW)
|
||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||
rg.GET("", p.GET(engine, app))
|
||||
rg.POST("", p.POST(engine, app))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PersonNewPage) GET(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
return p.renderPage(engine, app, e, req, "")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PersonNewPage) renderPage(engine *templating.Engine, app core.App, e *core.RequestEvent, req *templating.Request, message string) error {
|
||||
data := make(map[string]any)
|
||||
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.AGENTS_TABLE)
|
||||
if err != nil {
|
||||
return engine.Response500(e, err, data)
|
||||
}
|
||||
agent := dbmodels.NewAgent(core.NewRecord(collection))
|
||||
agent.SetEditState("Unknown")
|
||||
|
||||
result := &PersonEditResult{
|
||||
Agent: agent,
|
||||
User: nil,
|
||||
Prev: nil,
|
||||
Next: nil,
|
||||
Entries: []*dbmodels.Entry{},
|
||||
EntryTypes: map[string][]string{},
|
||||
Contents: []*dbmodels.Content{},
|
||||
ContentEntries: map[string]*dbmodels.Entry{},
|
||||
ContentTypes: map[string][]string{},
|
||||
}
|
||||
|
||||
data["result"] = result
|
||||
data["csrf_token"] = req.Session().Token
|
||||
data["is_new"] = true
|
||||
if message != "" {
|
||||
data["error"] = message
|
||||
}
|
||||
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
}
|
||||
|
||||
func (p *PersonNewPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
|
||||
formdata := personEditForm{}
|
||||
if err := e.BindBody(&formdata); err != nil {
|
||||
return p.renderPage(engine, app, e, req, "Formulardaten ungültig.")
|
||||
}
|
||||
|
||||
if err := req.CheckCSRF(formdata.CSRFToken); err != nil {
|
||||
return p.renderPage(engine, app, e, req, err.Error())
|
||||
}
|
||||
|
||||
name := strings.TrimSpace(formdata.Name)
|
||||
if name == "" {
|
||||
return p.renderPage(engine, app, e, req, "Name ist erforderlich.")
|
||||
}
|
||||
|
||||
status := strings.TrimSpace(formdata.Status)
|
||||
if status == "" || !slices.Contains(dbmodels.EDITORSTATE_VALUES, status) {
|
||||
return p.renderPage(engine, app, e, req, "Ungültiger Status.")
|
||||
}
|
||||
|
||||
var createdAgent *dbmodels.Agent
|
||||
user := req.User()
|
||||
if err := app.RunInTransaction(func(tx core.App) error {
|
||||
collection, err := tx.FindCollectionByNameOrId(dbmodels.AGENTS_TABLE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
agent := dbmodels.NewAgent(core.NewRecord(collection))
|
||||
nextID, err := nextAgentMusenalmID(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
agent.SetMusenalmID(nextID)
|
||||
applyPersonForm(agent, formdata, name, status, user)
|
||||
if err := tx.Save(agent); err != nil {
|
||||
return err
|
||||
}
|
||||
createdAgent = agent
|
||||
return nil
|
||||
}); err != nil {
|
||||
app.Logger().Error("Failed to create agent", "error", err)
|
||||
return p.renderPage(engine, app, e, req, "Speichern fehlgeschlagen.")
|
||||
}
|
||||
|
||||
if createdAgent == nil {
|
||||
return p.renderPage(engine, app, e, req, "Speichern fehlgeschlagen.")
|
||||
}
|
||||
|
||||
redirect := fmt.Sprintf(
|
||||
"/person/%s/edit?saved_message=%s",
|
||||
createdAgent.Id,
|
||||
url.QueryEscape("Änderungen gespeichert."),
|
||||
)
|
||||
return e.Redirect(http.StatusSeeOther, redirect)
|
||||
}
|
||||
}
|
||||
@@ -344,6 +344,19 @@ type reiheEditForm struct {
|
||||
Comment string `form:"edit_comment"`
|
||||
}
|
||||
|
||||
func applySeriesForm(series *dbmodels.Series, formdata reiheEditForm, title string, status string, user *dbmodels.FixedUser) {
|
||||
series.SetTitle(title)
|
||||
series.SetPseudonyms(strings.TrimSpace(formdata.Pseudonyms))
|
||||
series.SetAnnotation(strings.TrimSpace(formdata.Annotation))
|
||||
series.SetReferences(strings.TrimSpace(formdata.References))
|
||||
series.SetFrequency(strings.TrimSpace(formdata.Frequency))
|
||||
series.SetEditState(status)
|
||||
series.SetComment(strings.TrimSpace(formdata.Comment))
|
||||
if user != nil {
|
||||
series.SetEditor(user.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ReiheEditPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
id := e.Request.PathValue("id")
|
||||
@@ -385,16 +398,7 @@ func (p *ReiheEditPage) POST(engine *templating.Engine, app core.App) HandleFunc
|
||||
|
||||
user := req.User()
|
||||
if err := app.RunInTransaction(func(tx core.App) error {
|
||||
series.SetTitle(title)
|
||||
series.SetPseudonyms(strings.TrimSpace(formdata.Pseudonyms))
|
||||
series.SetAnnotation(strings.TrimSpace(formdata.Annotation))
|
||||
series.SetReferences(strings.TrimSpace(formdata.References))
|
||||
series.SetFrequency(strings.TrimSpace(formdata.Frequency))
|
||||
series.SetEditState(status)
|
||||
series.SetComment(strings.TrimSpace(formdata.Comment))
|
||||
if user != nil {
|
||||
series.SetEditor(user.Id)
|
||||
}
|
||||
applySeriesForm(series, formdata, title, status, user)
|
||||
return tx.Save(series)
|
||||
}); err != nil {
|
||||
app.Logger().Error("Failed to save series", "series_id", series.Id, "error", err)
|
||||
|
||||
144
controllers/reihe_new.go
Normal file
144
controllers/reihe_new.go
Normal file
@@ -0,0 +1,144 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
const (
|
||||
URL_REIHEN_NEW = "/reihen/new/"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rnp := &ReiheNewPage{
|
||||
StaticPage: pagemodels.StaticPage{
|
||||
Name: pagemodels.P_REIHE_NEW_NAME,
|
||||
URL: URL_REIHEN_NEW,
|
||||
Template: TEMPLATE_REIHE_EDIT,
|
||||
Layout: pagemodels.LAYOUT_LOGIN_PAGES,
|
||||
},
|
||||
}
|
||||
app.Register(rnp)
|
||||
}
|
||||
|
||||
type ReiheNewPage struct {
|
||||
pagemodels.StaticPage
|
||||
}
|
||||
|
||||
func (p *ReiheNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
rg := router.Group(URL_REIHEN_NEW)
|
||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||
rg.GET("", p.GET(engine, app))
|
||||
rg.POST("", p.POST(engine, app))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ReiheNewPage) GET(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
return p.renderPage(engine, app, e, req, "")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ReiheNewPage) renderPage(engine *templating.Engine, app core.App, e *core.RequestEvent, req *templating.Request, message string) error {
|
||||
data := make(map[string]any)
|
||||
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.SERIES_TABLE)
|
||||
if err != nil {
|
||||
return engine.Response500(e, err, data)
|
||||
}
|
||||
series := dbmodels.NewSeries(core.NewRecord(collection))
|
||||
series.SetEditState("Unknown")
|
||||
|
||||
result := &ReiheEditResult{
|
||||
Series: series,
|
||||
User: nil,
|
||||
Prev: nil,
|
||||
Next: nil,
|
||||
Entries: []*dbmodels.Entry{},
|
||||
Contents: []*dbmodels.Content{},
|
||||
ContentEntries: map[string]*dbmodels.Entry{},
|
||||
ContentTypes: map[string][]string{},
|
||||
PreferredEntries: []*dbmodels.Entry{},
|
||||
}
|
||||
|
||||
data["result"] = result
|
||||
data["csrf_token"] = req.Session().Token
|
||||
data["is_new"] = true
|
||||
if message != "" {
|
||||
data["error"] = message
|
||||
}
|
||||
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
}
|
||||
|
||||
func (p *ReiheNewPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
|
||||
formdata := reiheEditForm{}
|
||||
if err := e.BindBody(&formdata); err != nil {
|
||||
return p.renderPage(engine, app, e, req, "Formulardaten ungültig.")
|
||||
}
|
||||
|
||||
if err := req.CheckCSRF(formdata.CSRFToken); err != nil {
|
||||
return p.renderPage(engine, app, e, req, err.Error())
|
||||
}
|
||||
|
||||
title := strings.TrimSpace(formdata.Title)
|
||||
if title == "" {
|
||||
return p.renderPage(engine, app, e, req, "Reihentitel ist erforderlich.")
|
||||
}
|
||||
|
||||
status := strings.TrimSpace(formdata.Status)
|
||||
if status == "" || !slices.Contains(dbmodels.EDITORSTATE_VALUES, status) {
|
||||
return p.renderPage(engine, app, e, req, "Ungültiger Status.")
|
||||
}
|
||||
|
||||
var createdSeries *dbmodels.Series
|
||||
user := req.User()
|
||||
if err := app.RunInTransaction(func(tx core.App) error {
|
||||
collection, err := tx.FindCollectionByNameOrId(dbmodels.SERIES_TABLE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
series := dbmodels.NewSeries(core.NewRecord(collection))
|
||||
nextID, err := nextSeriesMusenalmID(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
series.SetMusenalmID(nextID)
|
||||
applySeriesForm(series, formdata, title, status, user)
|
||||
if err := tx.Save(series); err != nil {
|
||||
return err
|
||||
}
|
||||
createdSeries = series
|
||||
return nil
|
||||
}); err != nil {
|
||||
app.Logger().Error("Failed to create series", "error", err)
|
||||
return p.renderPage(engine, app, e, req, "Speichern fehlgeschlagen.")
|
||||
}
|
||||
|
||||
if createdSeries == nil {
|
||||
return p.renderPage(engine, app, e, req, "Speichern fehlgeschlagen.")
|
||||
}
|
||||
|
||||
redirect := fmt.Sprintf(
|
||||
"/reihe/%d/edit?saved_message=%s",
|
||||
createdSeries.MusenalmID(),
|
||||
url.QueryEscape("Änderungen gespeichert."),
|
||||
)
|
||||
return e.Redirect(http.StatusSeeOther, redirect)
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,9 @@ const (
|
||||
P_USER_MGMT_NAME = "user_management"
|
||||
|
||||
P_ALMANACH_EDIT_NAME = "almanach_edit"
|
||||
P_ALMANACH_NEW_NAME = "almanach_new"
|
||||
P_REIHE_EDIT_NAME = "reihe_edit"
|
||||
P_REIHE_NEW_NAME = "reihe_new"
|
||||
P_PERSON_EDIT_NAME = "person_edit"
|
||||
P_PERSON_NEW_NAME = "person_new"
|
||||
)
|
||||
|
||||
@@ -2593,6 +2593,10 @@ class Gt extends HTMLElement {
|
||||
const n = (s == null ? void 0 : s.error) || `Speichern fehlgeschlagen (${i.status}).`;
|
||||
throw new Error(n);
|
||||
}
|
||||
if (s != null && s.redirect) {
|
||||
window.location.assign(s.redirect);
|
||||
return;
|
||||
}
|
||||
await this._reloadForm((s == null ? void 0 : s.message) || "Änderungen gespeichert."), this._clearStatus();
|
||||
} catch (i) {
|
||||
this._showStatus(i instanceof Error ? i.message : "Speichern fehlgeschlagen.", "error");
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -22,7 +22,17 @@ type AlmanachResult struct {
|
||||
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
||||
<div class="flex flex-row w-full justify-between">
|
||||
<div class="flex flex-col justify-end-safe flex-2/5">
|
||||
<h1 class="text-2xl w-full font-bold text-slate-900 mb-4">{{ $model.result.Entry.PreferredTitle }}</h1>
|
||||
<h1 class="text-2xl w-full font-bold text-slate-900 mb-4">
|
||||
{{- if $model.is_new -}}
|
||||
Neuer Almanach
|
||||
{{- else -}}
|
||||
{{- $model.result.Entry.PreferredTitle -}}
|
||||
{{- end -}}
|
||||
{{- if $model.is_new -}}
|
||||
<span class="ml-2 text-sm font-semibold text-amber-700 bg-amber-100 px-2 py-0.5 rounded-xs align-middle">Neu</span>
|
||||
{{- end -}}
|
||||
</h1>
|
||||
{{- if not $model.is_new -}}
|
||||
<div class="flex flex-row gap-x-3">
|
||||
<div>
|
||||
<a
|
||||
@@ -62,7 +72,9 @@ type AlmanachResult struct {
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
{{- if not $model.is_new -}}
|
||||
<div class="flex flex-row" id="almanach-header-data">
|
||||
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||
<div class="">
|
||||
@@ -94,6 +106,7 @@ type AlmanachResult struct {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -105,10 +118,12 @@ type AlmanachResult struct {
|
||||
x-target="changealmanachform user-message almanach-header-data"
|
||||
hx-boost="false"
|
||||
method="POST"
|
||||
data-save-endpoint="/almanach/{{ $model.result.Entry.MusenalmID }}/edit/save"
|
||||
data-delete-endpoint="/almanach/{{ $model.result.Entry.MusenalmID }}/edit/delete">
|
||||
data-save-endpoint="{{ if $model.is_new }}/almanach-new/save{{ else }}/almanach/{{ $model.result.Entry.MusenalmID }}/edit/save{{ end }}"
|
||||
{{- if not $model.is_new -}}
|
||||
data-delete-endpoint="/almanach/{{ $model.result.Entry.MusenalmID }}/edit/delete"
|
||||
{{- end -}}>
|
||||
<input type="hidden" name="csrf_token" value="{{ $model.csrf_token }}" />
|
||||
<input type="hidden" name="last_edited" value="{{ $model.result.Entry.Updated }}" />
|
||||
<input type="hidden" name="last_edited" value="{{ if not $model.is_new }}{{ $model.result.Entry.Updated }}{{ end }}" />
|
||||
|
||||
<div class="flex gap-8">
|
||||
<!-- Left Column -->
|
||||
@@ -246,7 +261,7 @@ type AlmanachResult struct {
|
||||
<div class="flex gap-4">
|
||||
<div class="flex-1 inputwrapper">
|
||||
<label for="year" class="inputlabel">Jahr</label>
|
||||
<input type="number" name="year" id="year" class="inputinput" placeholder="" autocomplete="off" value="{{ $model.result.Entry.Year }}" />
|
||||
<input type="number" name="year" id="year" class="inputinput" placeholder="" autocomplete="off" value="{{ if not $model.is_new }}{{ $model.result.Entry.Year }}{{ end }}" />
|
||||
</div>
|
||||
|
||||
<div class="flex-1 inputwrapper">
|
||||
@@ -889,10 +904,11 @@ type AlmanachResult struct {
|
||||
<div class="w-full flex items-end justify-between gap-4 mt-6 flex-wrap">
|
||||
<p id="almanach-save-feedback" class="text-sm text-gray-600" aria-live="polite"></p>
|
||||
<div class="flex items-center gap-3 self-end flex-wrap">
|
||||
<a href="/almanach/{{ $model.result.Entry.MusenalmID }}" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<a href="{{ if $model.is_new }}/suche/baende{{ else }}/almanach/{{ $model.result.Entry.MusenalmID }}{{ end }}" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-close-line"></i>
|
||||
<span>Abbrechen</span>
|
||||
</a>
|
||||
{{- if not $model.is_new -}}
|
||||
<button type="button" class="resetbutton w-40 flex items-center gap-2 justify-center" data-role="almanach-reset">
|
||||
<i class="ri-loop-left-line"></i>
|
||||
<span>Reset</span>
|
||||
@@ -904,12 +920,14 @@ type AlmanachResult struct {
|
||||
<i class="ri-delete-bin-line"></i>
|
||||
<span>Eintrag löschen</span>
|
||||
</button>
|
||||
{{- end -}}
|
||||
<button type="button" class="submitbutton w-40 flex items-center gap-2 justify-center" data-role="almanach-save">
|
||||
<i class="ri-save-line"></i>
|
||||
<span>Speichern</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{{- if not $model.is_new -}}
|
||||
<dialog data-role="almanach-delete-dialog" class="fixed inset-0 m-auto rounded-md border border-slate-200 p-0 shadow-xl backdrop:bg-black/40">
|
||||
<div class="p-5 w-[22rem]">
|
||||
<div class="text-base font-bold text-gray-900">Eintrag löschen?</div>
|
||||
@@ -928,6 +946,7 @@ type AlmanachResult struct {
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
{{- end -}}
|
||||
</form>
|
||||
</div>
|
||||
</almanach-edit-page>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{{ $model := . }}
|
||||
<title>
|
||||
{{ if $model.result }}
|
||||
{{ if $model.is_new }}
|
||||
Neuer Almanach - Musenalm
|
||||
{{ else if $model.result }}
|
||||
Bearbeiten: {{ $model.result.Entry.PreferredTitle }} - Musenalm
|
||||
{{ else }}
|
||||
Neuer Almanach - Musenalm
|
||||
|
||||
@@ -5,7 +5,17 @@
|
||||
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
||||
<div class="flex flex-row w-full justify-between">
|
||||
<div class="flex flex-col justify-end-safe flex-2/5">
|
||||
<h1 class="text-2xl w-full font-bold text-slate-900 mb-4">{{ $agent.Name }}</h1>
|
||||
<h1 class="text-2xl w-full font-bold text-slate-900 mb-4">
|
||||
{{- if $model.is_new -}}
|
||||
Neue Person
|
||||
{{- else -}}
|
||||
{{- $agent.Name -}}
|
||||
{{- end -}}
|
||||
{{- if $model.is_new -}}
|
||||
<span class="ml-2 text-sm font-semibold text-amber-700 bg-amber-100 px-2 py-0.5 rounded-xs align-middle">Neu</span>
|
||||
{{- end -}}
|
||||
</h1>
|
||||
{{- if not $model.is_new -}}
|
||||
<div class="flex flex-row gap-x-3">
|
||||
<div>
|
||||
<a
|
||||
@@ -21,7 +31,9 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
{{- if not $model.is_new -}}
|
||||
<div class="flex flex-row" id="person-header-data">
|
||||
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||
<div class="">
|
||||
@@ -78,6 +90,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -87,9 +100,9 @@
|
||||
class="w-full dbform"
|
||||
id="changepersonform"
|
||||
method="POST"
|
||||
action="/person/{{ $agent.Id }}/edit">
|
||||
action="{{ if $model.is_new }}/personen/new/{{ else }}/person/{{ $agent.Id }}/edit{{ end }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ $model.csrf_token }}" />
|
||||
<input type="hidden" name="last_edited" value="{{ $agent.Updated }}" />
|
||||
<input type="hidden" name="last_edited" value="{{ if not $model.is_new }}{{ $agent.Updated }}{{ end }}" />
|
||||
|
||||
<div class="flex gap-8">
|
||||
<div class="flex-1 flex flex-col gap-4">
|
||||
@@ -236,14 +249,16 @@
|
||||
<div class="w-full flex items-end justify-between gap-4 mt-6 flex-wrap">
|
||||
<p id="person-save-feedback" class="text-sm text-gray-600" aria-live="polite"></p>
|
||||
<div class="flex items-center gap-3 self-end flex-wrap">
|
||||
<a href="/person/{{ $agent.Id }}" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<a href="{{ if $model.is_new }}/personen/{{ else }}/person/{{ $agent.Id }}{{ end }}" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-close-line"></i>
|
||||
<span>Abbrechen</span>
|
||||
</a>
|
||||
{{- if not $model.is_new -}}
|
||||
<a href="/person/{{ $agent.Id }}/edit" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-loop-left-line"></i>
|
||||
<span>Reset</span>
|
||||
</a>
|
||||
{{- end -}}
|
||||
<button type="submit" class="submitbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-save-line"></i>
|
||||
<span>Speichern</span>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{{ $model := . }}
|
||||
<title>
|
||||
{{- if $model.result -}}
|
||||
{{- if $model.is_new -}}
|
||||
Neue Person - Musenalm
|
||||
{{- else if $model.result -}}
|
||||
Bearbeiten: {{ $model.result.Agent.Name }} - Musenalm
|
||||
{{- else -}}
|
||||
Person bearbeiten - Musenalm
|
||||
|
||||
@@ -21,4 +21,12 @@
|
||||
</span>
|
||||
<span x-show="search"> Suche · Alle Personen & Körperschaften </span>
|
||||
</h1>
|
||||
{{- if (IsAdminOrEditor $model.request.user) -}}
|
||||
<div class="ml-24 -mt-4">
|
||||
<a href="/personen/new/" class="inline-flex items-center gap-2 text-sm font-bold text-gray-700 hover:text-slate-950 no-underline">
|
||||
<i class="ri-add-line"></i>
|
||||
<span>Neu</span>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,17 @@
|
||||
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
||||
<div class="flex flex-row w-full justify-between">
|
||||
<div class="flex flex-col justify-end-safe flex-2/5">
|
||||
<h1 class="text-2xl w-full font-bold text-slate-900 mb-4">{{ $series.Title }}</h1>
|
||||
<h1 class="text-2xl w-full font-bold text-slate-900 mb-4">
|
||||
{{- if $model.is_new -}}
|
||||
Neue Reihe
|
||||
{{- else -}}
|
||||
{{- $series.Title -}}
|
||||
{{- end -}}
|
||||
{{- if $model.is_new -}}
|
||||
<span class="ml-2 text-sm font-semibold text-amber-700 bg-amber-100 px-2 py-0.5 rounded-xs align-middle">Neu</span>
|
||||
{{- end -}}
|
||||
</h1>
|
||||
{{- if not $model.is_new -}}
|
||||
<div class="flex flex-row gap-x-3">
|
||||
<div>
|
||||
<a
|
||||
@@ -21,7 +31,9 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
{{- if not $model.is_new -}}
|
||||
<div class="flex flex-row" id="series-header-data">
|
||||
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||
<div class="">
|
||||
@@ -78,6 +90,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -87,10 +100,12 @@
|
||||
class="w-full dbform"
|
||||
id="changeseriesform"
|
||||
method="POST"
|
||||
action="/reihe/{{ $series.MusenalmID }}/edit"
|
||||
data-delete-endpoint="/reihe/{{ $series.MusenalmID }}/edit/delete">
|
||||
action="{{ if $model.is_new }}/reihen/new/{{ else }}/reihe/{{ $series.MusenalmID }}/edit{{ end }}"
|
||||
{{- if not $model.is_new -}}
|
||||
data-delete-endpoint="/reihe/{{ $series.MusenalmID }}/edit/delete"
|
||||
{{- end -}}>
|
||||
<input type="hidden" name="csrf_token" value="{{ $model.csrf_token }}" />
|
||||
<input type="hidden" name="last_edited" value="{{ $series.Updated }}" />
|
||||
<input type="hidden" name="last_edited" value="{{ if not $model.is_new }}{{ $series.Updated }}{{ end }}" />
|
||||
|
||||
<div class="flex gap-8">
|
||||
<div class="flex-1 flex flex-col gap-4">
|
||||
@@ -205,10 +220,11 @@
|
||||
<div class="w-full flex items-end justify-between gap-4 mt-6 flex-wrap">
|
||||
<p id="series-save-feedback" class="text-sm text-gray-600" aria-live="polite"></p>
|
||||
<div class="flex items-center gap-3 self-end flex-wrap">
|
||||
<a href="/reihe/{{ $series.MusenalmID }}" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<a href="{{ if $model.is_new }}/reihen/{{ else }}/reihe/{{ $series.MusenalmID }}{{ end }}" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-close-line"></i>
|
||||
<span>Abbrechen</span>
|
||||
</a>
|
||||
{{- if not $model.is_new -}}
|
||||
<a href="/reihe/{{ $series.MusenalmID }}/edit" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-loop-left-line"></i>
|
||||
<span>Reset</span>
|
||||
@@ -220,6 +236,7 @@
|
||||
<i class="ri-delete-bin-line"></i>
|
||||
<span>Reihe löschen</span>
|
||||
</button>
|
||||
{{- end -}}
|
||||
<button type="submit" class="submitbutton w-40 flex items-center gap-2 justify-center">
|
||||
<i class="ri-save-line"></i>
|
||||
<span>Speichern</span>
|
||||
@@ -228,6 +245,7 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{{- if not $model.is_new -}}
|
||||
<dialog data-role="edit-delete-dialog" class="fixed inset-0 m-auto rounded-md border border-slate-200 p-0 shadow-xl backdrop:bg-black/40">
|
||||
<div class="p-5 w-[26rem]">
|
||||
<div class="text-base font-bold text-gray-900">Reihe löschen?</div>
|
||||
@@ -260,4 +278,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
{{- end -}}
|
||||
</edit-page>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{{ $model := . }}
|
||||
<title>
|
||||
{{- if $model.result -}}
|
||||
{{- if $model.is_new -}}
|
||||
Neue Reihe - Musenalm
|
||||
{{- else if $model.result -}}
|
||||
Bearbeiten: {{ $model.result.Series.Title }} - Musenalm
|
||||
{{- else -}}
|
||||
Reihe bearbeiten - Musenalm
|
||||
|
||||
@@ -47,6 +47,14 @@
|
||||
<!-- INFO: 2. Header -->
|
||||
<div id="pageheading" class="headingcontainer">
|
||||
<h1 class="heading">Bände nach Reihentiteln</h1>
|
||||
{{- if (IsAdminOrEditor $model.request.user) -}}
|
||||
<div class="mt-2">
|
||||
<a href="/reihen/new/" class="inline-flex items-center gap-2 text-sm font-bold text-gray-700 hover:text-slate-950 no-underline">
|
||||
<i class="ri-add-line"></i>
|
||||
<span>Neu</span>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{ template "notifier" $model }}
|
||||
|
||||
{{ if not (or .search .hidden) }}
|
||||
|
||||
@@ -68,6 +68,14 @@
|
||||
|
||||
<div id="searchcontrol" class="container-normal">
|
||||
{{- template "_heading" $model.parameters -}}
|
||||
{{- if (IsAdminOrEditor $model.request.user) -}}
|
||||
<div class="mt-2">
|
||||
<a href="/almanach-new/" class="inline-flex items-center gap-2 text-sm font-bold text-gray-700 hover:text-slate-950 no-underline">
|
||||
<i class="ri-add-line"></i>
|
||||
<span>Neu</span>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
<div id="searchform" class="border-l border-zinc-300 px-8 py-10 relative">
|
||||
{{- if not $model.parameters.Extended -}}
|
||||
{{- template "_musenalmidbox" Arr $model.parameters.AlmString "baende" -}}
|
||||
|
||||
@@ -199,6 +199,11 @@ export class AlmanachEditPage extends HTMLElement {
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (data?.redirect) {
|
||||
window.location.assign(data.redirect);
|
||||
return;
|
||||
}
|
||||
|
||||
await this._reloadForm(data?.message || "Änderungen gespeichert.");
|
||||
this._clearStatus();
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user