// Controller to present path editor form func PathEditorForm(w *wrapper.Wrapper) { pathid := w.APIParams[0] f := form.NewForm() f.AddText("title", "text").AddLabel("Title").Required() f.AddText("path", "text").AddLabel("Path").Required() f.AddText("template", "text").AddLabel("Template").Required() f.AddCheckBox("wildcard").AddLabel("Wildcard") ops := []map[string]string{ map[string]string{"name": "published", "value": "published"}, map[string]string{"name": "unpublished", "value": "unpublished"}, } f.AddRadio("status", ops).AddLabel("Status").Required() f.AddText("id", "text").Hidden() var p paths.Path var err error if pathid != "new" { p, err = paths.LoadPath(pathid, w) if err != nil { errmessage := fmt.Sprintf("Could not retrieve path %s by %s: %s", w.APIParams[0], w.Request.Host, err.Error()) w.SiteConfig.Logger.Error(errmessage) services.AddMessage("Error retrieving path information.", "Error", w) w.Serve() return } } else { p = paths.NewPath() } f.FormData = p f.Register(w) w.SetTemplate("admin/form.html") w.SetPayload("form", f) w.Serve() return }
// The controller function to retrieve elements ids from the path func PathValues(w *wrapper.Wrapper) { // Request is never url based so we can Never cache this request. // TODO: move no caching into a reusable function. w.Writer.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate") w.Writer.Header().Add("Pragma", "no-cache") w.Writer.Header().Add("Expires", "0") p := paths.NewPath() u := w.Request.Header.Get("CurrentPath") if u == "" { http.Error(w.Writer, "Forbidden", 403) w.Serve() return } qp, err := p.PathMatch(u, "published", w) if err != nil { if err.Error() == "not found" { if "/"+w.SiteConfig.FourOFour != u { services.Redirect("/"+w.SiteConfig.FourOFour, w) w.Serve() return } else { services.AddMessage("There was a problem with the system.", "Error", w) w.Serve() return } } } var v []elements.Element for _, eid := range p.Elements { e := elements.NewElement() err = elements.GetById(eid, &e, w) if err != nil { errmessage := fmt.Sprintf("Content not found %s : %s", eid, err.Error()) w.SiteConfig.Logger.Error(errmessage) } else { v = append(v, e) } } w.SetPayload("mongolar_slug", qp) w.SetContent(v) w.SetTemplate(p.Template) w.Serve() return }