factored out the need for amsterdam_pageTitle by having FrameTitle be a separate bit of metadata in AmContext
This commit is contained in:
@@ -46,6 +46,7 @@ type AmContext interface {
|
||||
FormFieldInt(string) (int, error)
|
||||
FormFieldIsSet(string) bool
|
||||
FormFile(string) (*multipart.FileHeader, error)
|
||||
FrameTitle() string
|
||||
Globals() *database.Globals
|
||||
GlobalFlags() *util.OptionSet
|
||||
HasParameter(string) bool
|
||||
@@ -59,6 +60,7 @@ type AmContext interface {
|
||||
ReplaceUser(*database.User)
|
||||
SaveSession() error
|
||||
SetCommunityContext(string) error
|
||||
SetFrameTitle(string)
|
||||
SetHeader(string, string)
|
||||
SetLeftMenu(string)
|
||||
SetLoginCookie(string)
|
||||
@@ -85,6 +87,7 @@ type AmContext interface {
|
||||
type amContext struct {
|
||||
echoContext echo.Context
|
||||
rendervars jet.VarMap
|
||||
frameTitle string
|
||||
outputType string
|
||||
session AmSession
|
||||
globals *database.Globals
|
||||
@@ -219,6 +222,11 @@ func (c *amContext) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
return c.echoContext.FormFile(name)
|
||||
}
|
||||
|
||||
// FrameTitle returns the frame title.
|
||||
func (c *amContext) FrameTitle() string {
|
||||
return c.frameTitle
|
||||
}
|
||||
|
||||
// Globals returns a reference to the database globals.
|
||||
func (c *amContext) Globals() *database.Globals {
|
||||
return c.globals
|
||||
@@ -343,6 +351,11 @@ func (c *amContext) SetCommunityContext(param string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetFrameTitle sets the frame title for the output.
|
||||
func (c *amContext) SetFrameTitle(s string) {
|
||||
c.frameTitle = s
|
||||
}
|
||||
|
||||
// SetHeader sets a header on the output.
|
||||
func (c *amContext) SetHeader(key, value string) {
|
||||
c.echoContext.Response().Header().Set(key, value)
|
||||
@@ -457,6 +470,7 @@ func newContext(ctxt echo.Context) (*amContext, error) {
|
||||
if rc == nil {
|
||||
rc = &amContext{
|
||||
rendervars: make(jet.VarMap),
|
||||
frameTitle: "",
|
||||
outputType: "",
|
||||
}
|
||||
}
|
||||
@@ -531,6 +545,7 @@ func contextRecycler(incoming chan *amContext, done chan bool) {
|
||||
for c := range incoming {
|
||||
c.echoContext = nil
|
||||
c.rendervars = make(jet.VarMap)
|
||||
c.frameTitle = ""
|
||||
c.outputType = ""
|
||||
c.session = nil
|
||||
c.globals = nil
|
||||
|
||||
+1
-1
@@ -318,7 +318,7 @@ func (d *Dialog) Render(ctxt AmContext) (string, any) {
|
||||
}
|
||||
ctxt.VarMap().Set("amsterdam_required", required)
|
||||
ctxt.VarMap().Set("amsterdam_dialog", d)
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", d.Title)
|
||||
ctxt.SetFrameTitle(d.Title)
|
||||
if strings.Contains(d.Options, "suppresslogin") {
|
||||
ctxt.VarMap().Set("amsterdam_suppressLogin", true)
|
||||
}
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ func (mb *MessageBox) Render(ctxt AmContext) (string, any) {
|
||||
}
|
||||
ctxt.SetSession("mbconfirm."+mb.def.Id, nonce)
|
||||
}
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", mb.def.Title)
|
||||
ctxt.SetFrameTitle(mb.def.Title)
|
||||
ctxt.VarMap().Set("tone", mb.def.Tone)
|
||||
ctxt.VarMap().Set("destructive", mb.def.Destructive)
|
||||
ctxt.VarMap().Set("message", mb.message)
|
||||
|
||||
+6
-2
@@ -68,12 +68,12 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
||||
if httprc < 400 {
|
||||
httprc = http.StatusInternalServerError
|
||||
}
|
||||
amctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error")
|
||||
amctxt.SetFrameTitle("Internal Server Error")
|
||||
amctxt.VarMap().Set("error", message)
|
||||
command = "framed"
|
||||
data = "error.jet"
|
||||
case "ipban":
|
||||
amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned")
|
||||
amctxt.SetFrameTitle("IP Address Banned")
|
||||
amctxt.VarMap().Set("message", data)
|
||||
httprc = http.StatusForbidden
|
||||
command = "framed"
|
||||
@@ -92,6 +92,10 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
||||
case "template":
|
||||
err = ctxt.Render(httprc, data.(string), amctxt)
|
||||
case "framed":
|
||||
if amctxt.FrameTitle() == "" {
|
||||
ctxt.Logger().Errorf("*** NO FRAME TITLE set for path %s", amctxt.URLPath())
|
||||
amctxt.SetFrameTitle("<<< NO FRAME TITLE >>>")
|
||||
}
|
||||
amctxt.VarMap().Set("amsterdam_innerPage", data)
|
||||
menus := make([]*MenuDefinition, 2)
|
||||
switch amctxt.LeftMenu() {
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ amsterdam_pageTitle | raw }} - {{ GlobalConfig.Site.Title }}</title>
|
||||
<title>{{ .FrameTitle() | raw }} - {{ GlobalConfig.Site.Title }}</title>
|
||||
<link rel="icon" href="/img/builtin/AmsterdamIcon32.png" type="image/png" />
|
||||
<link rel="shortcut icon" href="/img/builtin/AmsterdamIcon32.ico" />
|
||||
{{ if isset(amsterdam_genRefresh) && GlobalConfig.Site.TopRefresh > 0 }}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<div class="bg-{{ tone }}-600 px-6 py-4">
|
||||
<h1 class="text-white text-2xl font-bold text-center flex items-center justify-center gap-3">
|
||||
{{ if destructive }}<span class="text-3xl">⚠️</span>{{ end }}
|
||||
{{ amsterdam_pageTitle }}
|
||||
{{ .FrameTitle() | raw }}
|
||||
{{ if destructive }}<span class="text-3xl">⚠️</span>{{ end }}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user