Ejemplo n.º 1
0
func SlugUrlEditorSubmit(w *wrapper.Wrapper) {
	slugid := w.APIParams[0]
	post := make(map[string]string)
	err := form.GetValidFormData(w, &post)
	if err != nil {
		return
	}
	vals := make(map[string]string)
	for id, slug := range post {
		if bson.IsObjectIdHex(id) {
			vals[slug] = id
		}
	}
	var e elements.SlugElement
	e, err = elements.LoadSlugElement(slugid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Element not found to edit for %s by %s", slugid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to load parent slug", "Error", w)
		w.Serve()
		return
	}
	e.Slugs = vals
	err = e.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Slugs not saved %s by %s", w.APIParams[0], w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to save slug values.", "Error", w)
		w.Serve()
		return
	}
	services.AddMessage("Slug values updated.", "Success", w)
	w.Serve()
	return
}
Ejemplo n.º 2
0
func AddSlugChild(w *wrapper.Wrapper) {
	parentid := w.APIParams[0]
	e := elements.NewElement()
	e.Title = "New Element"
	e.Controller = "content"
	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 elements.SlugElement
	parent, err = elements.LoadSlugElement(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
	}
	if parent.Slugs == nil {
		slug := map[string]string{e.MongoId.Hex(): e.MongoId.Hex()}
		parent.Slugs = slug
	} else {
		parent.Slugs[e.MongoId.Hex()] = e.MongoId.Hex()
	}
	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:     parentid,
		Controller: "admin/element",
		Template:   "admin/element.html",
		Id:         parentid,
	}
	services.SetDynamic(dynamic, w)
	services.AddMessage("You have added a new element.", "Success", w)
	w.Serve()

}