Ejemplo n.º 1
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.º 2
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.º 3
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

}