mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 18:45:31 +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"`
|
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 {
|
func (p *PersonEditPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||||
return func(e *core.RequestEvent) error {
|
return func(e *core.RequestEvent) error {
|
||||||
id := e.Request.PathValue("id")
|
id := e.Request.PathValue("id")
|
||||||
@@ -288,20 +305,7 @@ func (p *PersonEditPage) POST(engine *templating.Engine, app core.App) HandleFun
|
|||||||
|
|
||||||
user := req.User()
|
user := req.User()
|
||||||
if err := app.RunInTransaction(func(tx core.App) error {
|
if err := app.RunInTransaction(func(tx core.App) error {
|
||||||
agent.SetName(name)
|
applyPersonForm(agent, formdata, name, status, user)
|
||||||
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)
|
|
||||||
}
|
|
||||||
return tx.Save(agent)
|
return tx.Save(agent)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
app.Logger().Error("Failed to save agent", "agent_id", agent.Id, "error", err)
|
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"`
|
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 {
|
func (p *ReiheEditPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||||
return func(e *core.RequestEvent) error {
|
return func(e *core.RequestEvent) error {
|
||||||
id := e.Request.PathValue("id")
|
id := e.Request.PathValue("id")
|
||||||
@@ -385,16 +398,7 @@ func (p *ReiheEditPage) POST(engine *templating.Engine, app core.App) HandleFunc
|
|||||||
|
|
||||||
user := req.User()
|
user := req.User()
|
||||||
if err := app.RunInTransaction(func(tx core.App) error {
|
if err := app.RunInTransaction(func(tx core.App) error {
|
||||||
series.SetTitle(title)
|
applySeriesForm(series, formdata, title, status, user)
|
||||||
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)
|
|
||||||
}
|
|
||||||
return tx.Save(series)
|
return tx.Save(series)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
app.Logger().Error("Failed to save series", "series_id", series.Id, "error", err)
|
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_USER_MGMT_NAME = "user_management"
|
||||||
|
|
||||||
P_ALMANACH_EDIT_NAME = "almanach_edit"
|
P_ALMANACH_EDIT_NAME = "almanach_edit"
|
||||||
|
P_ALMANACH_NEW_NAME = "almanach_new"
|
||||||
P_REIHE_EDIT_NAME = "reihe_edit"
|
P_REIHE_EDIT_NAME = "reihe_edit"
|
||||||
|
P_REIHE_NEW_NAME = "reihe_new"
|
||||||
P_PERSON_EDIT_NAME = "person_edit"
|
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}).`;
|
const n = (s == null ? void 0 : s.error) || `Speichern fehlgeschlagen (${i.status}).`;
|
||||||
throw new Error(n);
|
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();
|
await this._reloadForm((s == null ? void 0 : s.message) || "Änderungen gespeichert."), this._clearStatus();
|
||||||
} catch (i) {
|
} catch (i) {
|
||||||
this._showStatus(i instanceof Error ? i.message : "Speichern fehlgeschlagen.", "error");
|
this._showStatus(i instanceof Error ? i.message : "Speichern fehlgeschlagen.", "error");
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -22,47 +22,59 @@ type AlmanachResult struct {
|
|||||||
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
<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-row w-full justify-between">
|
||||||
<div class="flex flex-col justify-end-safe flex-2/5">
|
<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">
|
||||||
<div class="flex flex-row gap-x-3">
|
{{- if $model.is_new -}}
|
||||||
<div>
|
Neuer Almanach
|
||||||
<a
|
{{- else -}}
|
||||||
href="/almanach/{{ $model.result.Entry.MusenalmID }}"
|
{{- $model.result.Entry.PreferredTitle -}}
|
||||||
class="text-gray-700
|
{{- end -}}
|
||||||
hover:text-slate-950 block no-underline">
|
{{- if $model.is_new -}}
|
||||||
<i class="ri-eye-line"></i> Anschauen
|
<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>
|
||||||
</a>
|
{{- end -}}
|
||||||
</div>
|
</h1>
|
||||||
·
|
{{- if not $model.is_new -}}
|
||||||
<div class="flex flex-row">
|
<div class="flex flex-row gap-x-3">
|
||||||
{{- if $model.result.Prev -}}
|
<div>
|
||||||
<div>
|
<a
|
||||||
<a href="/almanach/{{ $model.result.Prev.MusenalmID }}/edit" class="text-gray-700 hover:text-slate-950 no-underline block ">
|
href="/almanach/{{ $model.result.Entry.MusenalmID }}"
|
||||||
<i class="ri-arrow-left-s-line"></i>
|
class="text-gray-700
|
||||||
</a>
|
hover:text-slate-950 block no-underline">
|
||||||
</div>
|
<i class="ri-eye-line"></i> Anschauen
|
||||||
{{- end -}}
|
</a>
|
||||||
<div class="px-1.5 py-0.5 rounded-xs bg-gray-200 w-fit font-bold">
|
|
||||||
{{ $model.result.Entry.MusenalmID }}
|
|
||||||
<tool-tip position="right" class="!inline">
|
|
||||||
<div class="data-tip">Die Alm-Nr ist Teil der URL und wird automatisch vergeben.</div>
|
|
||||||
<i class="ri-information-line"></i>
|
|
||||||
</tool-tip>
|
|
||||||
</div>
|
</div>
|
||||||
{{- if $model.result.Next -}}
|
·
|
||||||
<div>
|
<div class="flex flex-row">
|
||||||
<a href="/almanach/{{ $model.result.Next.MusenalmID }}/edit" class="text-gray-700 hover:text-slate-950 block no-underline"><i class="ri-arrow-right-s-line"></i></a>
|
{{- if $model.result.Prev -}}
|
||||||
|
<div>
|
||||||
|
<a href="/almanach/{{ $model.result.Prev.MusenalmID }}/edit" class="text-gray-700 hover:text-slate-950 no-underline block ">
|
||||||
|
<i class="ri-arrow-left-s-line"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{- end -}}
|
||||||
|
<div class="px-1.5 py-0.5 rounded-xs bg-gray-200 w-fit font-bold">
|
||||||
|
{{ $model.result.Entry.MusenalmID }}
|
||||||
|
<tool-tip position="right" class="!inline">
|
||||||
|
<div class="data-tip">Die Alm-Nr ist Teil der URL und wird automatisch vergeben.</div>
|
||||||
|
<i class="ri-information-line"></i>
|
||||||
|
</tool-tip>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- if $model.result.Next -}}
|
||||||
|
<div>
|
||||||
|
<a href="/almanach/{{ $model.result.Next.MusenalmID }}/edit" class="text-gray-700 hover:text-slate-950 block no-underline"><i class="ri-arrow-right-s-line"></i></a>
|
||||||
|
</div>
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
·
|
||||||
|
<div>
|
||||||
|
<a href="/almanach/{{- $model.result.Entry.MusenalmID -}}/edit" class="text-gray-700
|
||||||
|
no-underline hover:text-slate-950 block ">
|
||||||
|
<i class="ri-loop-left-line"></i> Reset
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
·
|
{{- end -}}
|
||||||
<div>
|
|
||||||
<a href="/almanach/{{- $model.result.Entry.MusenalmID -}}/edit" class="text-gray-700
|
|
||||||
no-underline hover:text-slate-950 block ">
|
|
||||||
<i class="ri-loop-left-line"></i> Reset
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{{- if not $model.is_new -}}
|
||||||
<div class="flex flex-row" id="almanach-header-data">
|
<div class="flex flex-row" id="almanach-header-data">
|
||||||
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||||
<div class="">
|
<div class="">
|
||||||
@@ -94,6 +106,7 @@ type AlmanachResult struct {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -105,10 +118,12 @@ type AlmanachResult struct {
|
|||||||
x-target="changealmanachform user-message almanach-header-data"
|
x-target="changealmanachform user-message almanach-header-data"
|
||||||
hx-boost="false"
|
hx-boost="false"
|
||||||
method="POST"
|
method="POST"
|
||||||
data-save-endpoint="/almanach/{{ $model.result.Entry.MusenalmID }}/edit/save"
|
data-save-endpoint="{{ if $model.is_new }}/almanach-new/save{{ else }}/almanach/{{ $model.result.Entry.MusenalmID }}/edit/save{{ end }}"
|
||||||
data-delete-endpoint="/almanach/{{ $model.result.Entry.MusenalmID }}/edit/delete">
|
{{- 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="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">
|
<div class="flex gap-8">
|
||||||
<!-- Left Column -->
|
<!-- Left Column -->
|
||||||
@@ -246,7 +261,7 @@ type AlmanachResult struct {
|
|||||||
<div class="flex gap-4">
|
<div class="flex gap-4">
|
||||||
<div class="flex-1 inputwrapper">
|
<div class="flex-1 inputwrapper">
|
||||||
<label for="year" class="inputlabel">Jahr</label>
|
<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>
|
||||||
|
|
||||||
<div class="flex-1 inputwrapper">
|
<div class="flex-1 inputwrapper">
|
||||||
@@ -889,45 +904,49 @@ type AlmanachResult struct {
|
|||||||
<div class="w-full flex items-end justify-between gap-4 mt-6 flex-wrap">
|
<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>
|
<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">
|
<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>
|
<i class="ri-close-line"></i>
|
||||||
<span>Abbrechen</span>
|
<span>Abbrechen</span>
|
||||||
</a>
|
</a>
|
||||||
<button type="button" class="resetbutton w-40 flex items-center gap-2 justify-center" data-role="almanach-reset">
|
{{- if not $model.is_new -}}
|
||||||
<i class="ri-loop-left-line"></i>
|
<button type="button" class="resetbutton w-40 flex items-center gap-2 justify-center" data-role="almanach-reset">
|
||||||
<span>Reset</span>
|
<i class="ri-loop-left-line"></i>
|
||||||
</button>
|
<span>Reset</span>
|
||||||
<button
|
</button>
|
||||||
type="button"
|
<button
|
||||||
class="resetbutton w-40 flex items-center gap-2 justify-center bg-red-50 text-red-800 hover:bg-red-100 hover:text-red-900"
|
type="button"
|
||||||
data-role="almanach-delete">
|
class="resetbutton w-40 flex items-center gap-2 justify-center bg-red-50 text-red-800 hover:bg-red-100 hover:text-red-900"
|
||||||
<i class="ri-delete-bin-line"></i>
|
data-role="almanach-delete">
|
||||||
<span>Eintrag löschen</span>
|
<i class="ri-delete-bin-line"></i>
|
||||||
</button>
|
<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">
|
<button type="button" class="submitbutton w-40 flex items-center gap-2 justify-center" data-role="almanach-save">
|
||||||
<i class="ri-save-line"></i>
|
<i class="ri-save-line"></i>
|
||||||
<span>Speichern</span>
|
<span>Speichern</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<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">
|
{{- if not $model.is_new -}}
|
||||||
<div class="p-5 w-[22rem]">
|
<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="text-base font-bold text-gray-900">Eintrag löschen?</div>
|
<div class="p-5 w-[22rem]">
|
||||||
<div class="text-sm font-bold text-gray-900 mt-1">{{ $model.result.Entry.PreferredTitle }}</div>
|
<div class="text-base font-bold text-gray-900">Eintrag löschen?</div>
|
||||||
<p class="text-sm text-gray-700 mt-2">
|
<div class="text-sm font-bold text-gray-900 mt-1">{{ $model.result.Entry.PreferredTitle }}</div>
|
||||||
Der Eintrag wird dauerhaft gelöscht. Verknüpfungen, Exemplare und Inhalte werden entfernt.
|
<p class="text-sm text-gray-700 mt-2">
|
||||||
</p>
|
Der Eintrag wird dauerhaft gelöscht. Verknüpfungen, Exemplare und Inhalte werden entfernt.
|
||||||
<div class="flex items-center justify-end gap-3 mt-4">
|
</p>
|
||||||
<button type="button" class="resetbutton w-auto px-3 py-1 text-sm" data-role="almanach-delete-cancel">Abbrechen</button>
|
<div class="flex items-center justify-end gap-3 mt-4">
|
||||||
<button
|
<button type="button" class="resetbutton w-auto px-3 py-1 text-sm" data-role="almanach-delete-cancel">Abbrechen</button>
|
||||||
type="button"
|
<button
|
||||||
class="submitbutton w-auto bg-red-700 hover:bg-red-800 px-3 py-1 text-sm"
|
type="button"
|
||||||
data-role="almanach-delete-confirm">
|
class="submitbutton w-auto bg-red-700 hover:bg-red-800 px-3 py-1 text-sm"
|
||||||
Löschen
|
data-role="almanach-delete-confirm">
|
||||||
</button>
|
Löschen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</dialog>
|
||||||
</dialog>
|
{{- end -}}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</almanach-edit-page>
|
</almanach-edit-page>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{{ $model := . }}
|
{{ $model := . }}
|
||||||
<title>
|
<title>
|
||||||
{{ if $model.result }}
|
{{ if $model.is_new }}
|
||||||
|
Neuer Almanach - Musenalm
|
||||||
|
{{ else if $model.result }}
|
||||||
Bearbeiten: {{ $model.result.Entry.PreferredTitle }} - Musenalm
|
Bearbeiten: {{ $model.result.Entry.PreferredTitle }} - Musenalm
|
||||||
{{ else }}
|
{{ else }}
|
||||||
Neuer Almanach - Musenalm
|
Neuer Almanach - Musenalm
|
||||||
|
|||||||
@@ -5,23 +5,35 @@
|
|||||||
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
<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-row w-full justify-between">
|
||||||
<div class="flex flex-col justify-end-safe flex-2/5">
|
<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">
|
||||||
<div class="flex flex-row gap-x-3">
|
{{- if $model.is_new -}}
|
||||||
<div>
|
Neue Person
|
||||||
<a
|
{{- else -}}
|
||||||
href="/person/{{ $agent.Id }}"
|
{{- $agent.Name -}}
|
||||||
class="text-gray-700 hover:text-slate-950 block no-underline">
|
{{- end -}}
|
||||||
<i class="ri-eye-line"></i> Anschauen
|
{{- if $model.is_new -}}
|
||||||
</a>
|
<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
|
||||||
|
href="/person/{{ $agent.Id }}"
|
||||||
|
class="text-gray-700 hover:text-slate-950 block no-underline">
|
||||||
|
<i class="ri-eye-line"></i> Anschauen
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
·
|
||||||
|
<div>
|
||||||
|
<a href="/person/{{ $agent.Id }}/edit" class="text-gray-700 no-underline hover:text-slate-950 block">
|
||||||
|
<i class="ri-loop-left-line"></i> Reset
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
·
|
{{- end -}}
|
||||||
<div>
|
|
||||||
<a href="/person/{{ $agent.Id }}/edit" class="text-gray-700 no-underline hover:text-slate-950 block">
|
|
||||||
<i class="ri-loop-left-line"></i> Reset
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{{- if not $model.is_new -}}
|
||||||
<div class="flex flex-row" id="person-header-data">
|
<div class="flex flex-row" id="person-header-data">
|
||||||
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||||
<div class="">
|
<div class="">
|
||||||
@@ -78,6 +90,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -87,9 +100,9 @@
|
|||||||
class="w-full dbform"
|
class="w-full dbform"
|
||||||
id="changepersonform"
|
id="changepersonform"
|
||||||
method="POST"
|
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="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 gap-8">
|
||||||
<div class="flex-1 flex flex-col gap-4">
|
<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">
|
<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>
|
<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">
|
<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>
|
<i class="ri-close-line"></i>
|
||||||
<span>Abbrechen</span>
|
<span>Abbrechen</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="/person/{{ $agent.Id }}/edit" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
{{- if not $model.is_new -}}
|
||||||
<i class="ri-loop-left-line"></i>
|
<a href="/person/{{ $agent.Id }}/edit" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||||
<span>Reset</span>
|
<i class="ri-loop-left-line"></i>
|
||||||
</a>
|
<span>Reset</span>
|
||||||
|
</a>
|
||||||
|
{{- end -}}
|
||||||
<button type="submit" class="submitbutton w-40 flex items-center gap-2 justify-center">
|
<button type="submit" class="submitbutton w-40 flex items-center gap-2 justify-center">
|
||||||
<i class="ri-save-line"></i>
|
<i class="ri-save-line"></i>
|
||||||
<span>Speichern</span>
|
<span>Speichern</span>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{{ $model := . }}
|
{{ $model := . }}
|
||||||
<title>
|
<title>
|
||||||
{{- if $model.result -}}
|
{{- if $model.is_new -}}
|
||||||
|
Neue Person - Musenalm
|
||||||
|
{{- else if $model.result -}}
|
||||||
Bearbeiten: {{ $model.result.Agent.Name }} - Musenalm
|
Bearbeiten: {{ $model.result.Agent.Name }} - Musenalm
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
Person bearbeiten - Musenalm
|
Person bearbeiten - Musenalm
|
||||||
|
|||||||
@@ -21,4 +21,12 @@
|
|||||||
</span>
|
</span>
|
||||||
<span x-show="search"> Suche · Alle Personen & Körperschaften </span>
|
<span x-show="search"> Suche · Alle Personen & Körperschaften </span>
|
||||||
</h1>
|
</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>
|
</div>
|
||||||
|
|||||||
@@ -5,23 +5,35 @@
|
|||||||
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
<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-row w-full justify-between">
|
||||||
<div class="flex flex-col justify-end-safe flex-2/5">
|
<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">
|
||||||
<div class="flex flex-row gap-x-3">
|
{{- if $model.is_new -}}
|
||||||
<div>
|
Neue Reihe
|
||||||
<a
|
{{- else -}}
|
||||||
href="/reihe/{{ $series.MusenalmID }}"
|
{{- $series.Title -}}
|
||||||
class="text-gray-700 hover:text-slate-950 block no-underline">
|
{{- end -}}
|
||||||
<i class="ri-eye-line"></i> Anschauen
|
{{- if $model.is_new -}}
|
||||||
</a>
|
<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
|
||||||
|
href="/reihe/{{ $series.MusenalmID }}"
|
||||||
|
class="text-gray-700 hover:text-slate-950 block no-underline">
|
||||||
|
<i class="ri-eye-line"></i> Anschauen
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
·
|
||||||
|
<div>
|
||||||
|
<a href="/reihe/{{ $series.MusenalmID }}/edit" class="text-gray-700 no-underline hover:text-slate-950 block">
|
||||||
|
<i class="ri-loop-left-line"></i> Reset
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
·
|
{{- end -}}
|
||||||
<div>
|
|
||||||
<a href="/reihe/{{ $series.MusenalmID }}/edit" class="text-gray-700 no-underline hover:text-slate-950 block">
|
|
||||||
<i class="ri-loop-left-line"></i> Reset
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{{- if not $model.is_new -}}
|
||||||
<div class="flex flex-row" id="series-header-data">
|
<div class="flex flex-row" id="series-header-data">
|
||||||
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||||
<div class="">
|
<div class="">
|
||||||
@@ -78,6 +90,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -87,10 +100,12 @@
|
|||||||
class="w-full dbform"
|
class="w-full dbform"
|
||||||
id="changeseriesform"
|
id="changeseriesform"
|
||||||
method="POST"
|
method="POST"
|
||||||
action="/reihe/{{ $series.MusenalmID }}/edit"
|
action="{{ if $model.is_new }}/reihen/new/{{ else }}/reihe/{{ $series.MusenalmID }}/edit{{ end }}"
|
||||||
data-delete-endpoint="/reihe/{{ $series.MusenalmID }}/edit/delete">
|
{{- 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="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 gap-8">
|
||||||
<div class="flex-1 flex flex-col gap-4">
|
<div class="flex-1 flex flex-col gap-4">
|
||||||
@@ -205,21 +220,23 @@
|
|||||||
<div class="w-full flex items-end justify-between gap-4 mt-6 flex-wrap">
|
<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>
|
<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">
|
<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>
|
<i class="ri-close-line"></i>
|
||||||
<span>Abbrechen</span>
|
<span>Abbrechen</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="/reihe/{{ $series.MusenalmID }}/edit" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
{{- if not $model.is_new -}}
|
||||||
<i class="ri-loop-left-line"></i>
|
<a href="/reihe/{{ $series.MusenalmID }}/edit" class="resetbutton w-40 flex items-center gap-2 justify-center">
|
||||||
<span>Reset</span>
|
<i class="ri-loop-left-line"></i>
|
||||||
</a>
|
<span>Reset</span>
|
||||||
<button
|
</a>
|
||||||
type="button"
|
<button
|
||||||
class="resetbutton w-40 flex items-center gap-2 justify-center bg-red-50 text-red-800 hover:bg-red-100 hover:text-red-900"
|
type="button"
|
||||||
data-role="edit-delete">
|
class="resetbutton w-40 flex items-center gap-2 justify-center bg-red-50 text-red-800 hover:bg-red-100 hover:text-red-900"
|
||||||
<i class="ri-delete-bin-line"></i>
|
data-role="edit-delete">
|
||||||
<span>Reihe löschen</span>
|
<i class="ri-delete-bin-line"></i>
|
||||||
</button>
|
<span>Reihe löschen</span>
|
||||||
|
</button>
|
||||||
|
{{- end -}}
|
||||||
<button type="submit" class="submitbutton w-40 flex items-center gap-2 justify-center">
|
<button type="submit" class="submitbutton w-40 flex items-center gap-2 justify-center">
|
||||||
<i class="ri-save-line"></i>
|
<i class="ri-save-line"></i>
|
||||||
<span>Speichern</span>
|
<span>Speichern</span>
|
||||||
@@ -228,36 +245,38 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<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">
|
{{- if not $model.is_new -}}
|
||||||
<div class="p-5 w-[26rem]">
|
<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="text-base font-bold text-gray-900">Reihe löschen?</div>
|
<div class="p-5 w-[26rem]">
|
||||||
<div class="text-sm font-bold text-gray-900 mt-1">{{ $series.Title }}</div>
|
<div class="text-base font-bold text-gray-900">Reihe löschen?</div>
|
||||||
<p class="text-sm text-gray-700 mt-2">
|
<div class="text-sm font-bold text-gray-900 mt-1">{{ $series.Title }}</div>
|
||||||
Alle Bände, Inhalte und Verknüpfungen der bevorzugten Reihentitel werden gelöscht.
|
<p class="text-sm text-gray-700 mt-2">
|
||||||
</p>
|
Alle Bände, Inhalte und Verknüpfungen der bevorzugten Reihentitel werden gelöscht.
|
||||||
<div class="mt-3">
|
</p>
|
||||||
<div class="text-sm font-semibold text-gray-700">Betroffene Bände</div>
|
<div class="mt-3">
|
||||||
<div class="mt-2 max-h-40 overflow-auto pr-1">
|
<div class="text-sm font-semibold text-gray-700">Betroffene Bände</div>
|
||||||
{{- if $model.result.PreferredEntries -}}
|
<div class="mt-2 max-h-40 overflow-auto pr-1">
|
||||||
<ul class="flex flex-col gap-2 pl-0 pr-0 m-0 list-none">
|
{{- if $model.result.PreferredEntries -}}
|
||||||
{{- range $entry := $model.result.PreferredEntries -}}
|
<ul class="flex flex-col gap-2 pl-0 pr-0 m-0 list-none">
|
||||||
<li class="flex items-baseline justify-between gap-3 ml-0 pl-0 text-sm text-gray-700">
|
{{- range $entry := $model.result.PreferredEntries -}}
|
||||||
<span>{{ $entry.PreferredTitle }}</span>
|
<li class="flex items-baseline justify-between gap-3 ml-0 pl-0 text-sm text-gray-700">
|
||||||
<span class="text-xs text-gray-500">{{ $entry.Year }}</span>
|
<span>{{ $entry.PreferredTitle }}</span>
|
||||||
</li>
|
<span class="text-xs text-gray-500">{{ $entry.Year }}</span>
|
||||||
{{- end -}}
|
</li>
|
||||||
</ul>
|
{{- end -}}
|
||||||
{{- else -}}
|
</ul>
|
||||||
<div class="italic text-gray-500">Keine Bände betroffen.</div>
|
{{- else -}}
|
||||||
{{- end -}}
|
<div class="italic text-gray-500">Keine Bände betroffen.</div>
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-end gap-3 mt-4">
|
||||||
|
<button type="button" class="resetbutton w-auto px-3 py-1 text-sm" data-role="edit-delete-cancel">Abbrechen</button>
|
||||||
|
<button type="button" class="submitbutton w-auto bg-red-700 hover:bg-red-800 px-3 py-1 text-sm" data-role="edit-delete-confirm">
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center justify-end gap-3 mt-4">
|
</dialog>
|
||||||
<button type="button" class="resetbutton w-auto px-3 py-1 text-sm" data-role="edit-delete-cancel">Abbrechen</button>
|
{{- end -}}
|
||||||
<button type="button" class="submitbutton w-auto bg-red-700 hover:bg-red-800 px-3 py-1 text-sm" data-role="edit-delete-confirm">
|
|
||||||
Löschen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</dialog>
|
|
||||||
</edit-page>
|
</edit-page>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{{ $model := . }}
|
{{ $model := . }}
|
||||||
<title>
|
<title>
|
||||||
{{- if $model.result -}}
|
{{- if $model.is_new -}}
|
||||||
|
Neue Reihe - Musenalm
|
||||||
|
{{- else if $model.result -}}
|
||||||
Bearbeiten: {{ $model.result.Series.Title }} - Musenalm
|
Bearbeiten: {{ $model.result.Series.Title }} - Musenalm
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
Reihe bearbeiten - Musenalm
|
Reihe bearbeiten - Musenalm
|
||||||
|
|||||||
@@ -47,6 +47,14 @@
|
|||||||
<!-- INFO: 2. Header -->
|
<!-- INFO: 2. Header -->
|
||||||
<div id="pageheading" class="headingcontainer">
|
<div id="pageheading" class="headingcontainer">
|
||||||
<h1 class="heading">Bände nach Reihentiteln</h1>
|
<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 }}
|
{{ template "notifier" $model }}
|
||||||
|
|
||||||
{{ if not (or .search .hidden) }}
|
{{ if not (or .search .hidden) }}
|
||||||
|
|||||||
@@ -68,6 +68,14 @@
|
|||||||
|
|
||||||
<div id="searchcontrol" class="container-normal">
|
<div id="searchcontrol" class="container-normal">
|
||||||
{{- template "_heading" $model.parameters -}}
|
{{- 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">
|
<div id="searchform" class="border-l border-zinc-300 px-8 py-10 relative">
|
||||||
{{- if not $model.parameters.Extended -}}
|
{{- if not $model.parameters.Extended -}}
|
||||||
{{- template "_musenalmidbox" Arr $model.parameters.AlmString "baende" -}}
|
{{- template "_musenalmidbox" Arr $model.parameters.AlmString "baende" -}}
|
||||||
|
|||||||
@@ -199,6 +199,11 @@ export class AlmanachEditPage extends HTMLElement {
|
|||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data?.redirect) {
|
||||||
|
window.location.assign(data.redirect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this._reloadForm(data?.message || "Änderungen gespeichert.");
|
await this._reloadForm(data?.message || "Änderungen gespeichert.");
|
||||||
this._clearStatus();
|
this._clearStatus();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user