// Package admin desrcibes the admin view containing references to // various managers and editors package admin import ( "bytes" "html/template" "github.com/nilslice/cms/content" "github.com/nilslice/cms/system/db" ) var startAdminHTML = ` {{ .Logo }}
` var mainAdminHTML = `
{{ if .Subview}}
{{ .Subview }}
{{ end }}` var endAdminHTML = `
` type admin struct { Logo string Types map[string]func() interface{} Subview template.HTML } // Admin ... func Admin(view []byte) ([]byte, error) { cfg, err := db.Config("name") if err != nil { return nil, err } if cfg == nil { cfg = []byte("") } a := admin{ Logo: string(cfg), Types: content.Types, Subview: template.HTML(view), } buf := &bytes.Buffer{} html := startAdminHTML + mainAdminHTML + endAdminHTML tmpl := template.Must(template.New("admin").Parse(html)) err = tmpl.Execute(buf, a) if err != nil { return nil, err } return buf.Bytes(), nil } var initAdminHTML = `
Welcome!
You need to initialize your system by filling out the form below. All of this information can be updated later on, but you will not be able to start without first completing this step.
Configuration
Admin Details
` // Init ... func Init() ([]byte, error) { html := startAdminHTML + initAdminHTML + endAdminHTML cfg, err := db.Config("name") if err != nil { return nil, err } if cfg == nil { cfg = []byte("") } a := admin{ Logo: string(cfg), } buf := &bytes.Buffer{} tmpl := template.Must(template.New("init").Parse(html)) err = tmpl.Execute(buf, a) if err != nil { return nil, err } return buf.Bytes(), nil } var loginAdminHTML = `
Welcome!
Please log in to the system using your email address and password.
` // Login ... func Login() ([]byte, error) { html := startAdminHTML + loginAdminHTML + endAdminHTML cfg, err := db.Config("name") if err != nil { return nil, err } if cfg == nil { cfg = []byte("") } a := admin{ Logo: string(cfg), } buf := &bytes.Buffer{} tmpl := template.Must(template.New("login").Parse(html)) err = tmpl.Execute(buf, a) if err != nil { return nil, err } return buf.Bytes(), nil }