Ejemplo n.º 1
0
// 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
}
Ejemplo n.º 2
0
// Controller for path sort form.
func SortPathForm(w *wrapper.Wrapper) {
	var parentid string
	if len(w.APIParams) > 0 {
		parentid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	p, err := paths.LoadPath(parentid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Path not found to sort for %s by %s.", parentid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("This element was not found", "Error", w)
		w.Serve()
		return
	} else {
		if len(p.Elements) > 0 {
			w.SetPayload("elements", p.Elements)
		} else {
			services.AddMessage("This has no elements assigned yet.", "Error", w)
		}
		w.SetTemplate("admin/element_sorter.html")
		w.Serve()
		return
	}
}
Ejemplo n.º 3
0
// Controller for adding existing element to path form submission.
func AddExistingPathSubmit(w *wrapper.Wrapper) {
	parentid := w.APIParams[0]
	var post map[string]string
	err := form.GetValidFormData(w, &post)
	if err != nil {
		return
	}
	var parent paths.Path
	parent, err = paths.LoadPath(parentid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to loap parent element  by %s : %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Could not load parent element.", "Error", w)
		w.Serve()
		return
	}
	parent.Elements = append(parent.Elements, post["element"])
	err = parent.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to save parent element  by %s : %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Could not save parent element.", "Error", w)
		w.Serve()
		return
	}
	dynamic := services.Dynamic{
		Target:     "centereditor",
		Controller: "admin/path_elements",
		Template:   "admin/path_elements.html",
		Id:         parentid,
	}
	services.SetDynamic(dynamic, w)
	services.AddMessage("You have added an existing element.", "Success", w)
	w.Serve()
}
Ejemplo n.º 4
0
// Controller for path sort submission.
func SortPathSubmit(w *wrapper.Wrapper) {
	var parentid string
	if len(w.APIParams) > 0 {
		parentid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	pes := paths.NewPathElements()
	err := json.NewDecoder(w.Request.Body).Decode(&pes)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to marshall elements %s by %s: %s", parentid, w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to save elements.", "Error", w)
		w.Serve()
		return
	}
	pe, err := paths.LoadPath(parentid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Path not found to sort for %s by %s.", parentid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("This path was not found", "Error", w)
		w.Serve()
		return
	}
	pe.PathElements = pes
	err = pe.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to save path %s by %s : %s", parentid, w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Could not save path.", "Error", w)
		w.Serve()
		return
	}
	dynamic := services.Dynamic{
		Target:     "centereditor",
		Controller: "admin/path_elements",
		Template:   "admin/path_elements.html",
		Id:         w.APIParams[1],
	}
	services.SetDynamic(dynamic, w)
	services.AddMessage("You elements have been updated.", "Success", w)
	w.Serve()
	return
}
Ejemplo n.º 5
0
// Controller for adding children to path.
func AddPathChild(w *wrapper.Wrapper) {
	parentid := w.APIParams[0]
	e := elements.NewElement()
	e.Title = "New Element"
	err := e.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to create new element  by %s : %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Could not create a new element.", "Error", w)
		w.Serve()
		return
	}
	var parent paths.Path
	parent, err = paths.LoadPath(parentid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to loap path  by %s : %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Could not load parent path.", "Error", w)
		w.Serve()
		return
	}
	parent.Elements = append(parent.Elements, e.MongoId.Hex())
	err = parent.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to save path by %s : %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Could not add child element.", "Error", w)
		w.Serve()
		return
	}
	dynamic := services.Dynamic{
		Target:     "centereditor",
		Controller: "admin/path_elements",
		Template:   "admin/path_elements.html",
		Id:         parentid,
	}
	services.SetDynamic(dynamic, w)
	services.AddMessage("You have added a new element.", "Success", w)
	w.Serve()
	return
}
Ejemplo n.º 6
0
// Controller to handle path editor form submissions.
func PathEditorSubmit(w *wrapper.Wrapper) {
	pathid := w.APIParams[0]
	var path paths.Path
	var err error
	if pathid != "new" {
		path, err = paths.LoadPath(pathid, w)
		if err != nil {
			errmessage := fmt.Sprintf("Unable to save path %s by %s: %s", pathid,
				w.Request.Host, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
			services.AddMessage("There was a problem saving your path.", "Error", w)
			w.Serve()
			return
		}
	}
	err = form.GetValidFormData(w, &path)
	if err != nil {
		return
	}
	err = path.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to save path %s by %s: %s", pathid,
			w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was a problem saving your path.", "Error", w)
		w.Serve()
		return
	}
	services.AddMessage("Your path was saved.", "Success", w)
	dynamic := services.Dynamic{
		Target:     "pathbar",
		Controller: "admin/paths",
		Template:   "admin/path_list.html",
	}
	services.SetDynamic(dynamic, w)
	w.Serve()
	return

}
Ejemplo n.º 7
0
// Retrieve a list of elements in a path for content editor.
func PathElements(w *wrapper.Wrapper) {
	if len(w.APIParams) == 0 {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	pathid := w.APIParams[0]
	p, err := paths.LoadPath(pathid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Path not found to edit for %s by %s ", pathid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("This path was not found", "Error", w)
		w.Serve()
	} else {
		w.SetPayload("path", p)
		if len(p.Elements) == 0 {
			services.AddMessage("This path has no elements.", "Info", w)
		}
		w.Serve()
	}

}