Exemplo n.º 1
0
// The controller function for Values found directly in the controller values of the element
func WrapperValues(w *wrapper.Wrapper) {
	var wrapid string
	if len(w.APIParams) > 0 {
		wrapid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	e, err := elements.LoadWrapperElement(wrapid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Content not found %s : %s", wrapid, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was a problem loading some content on your page.", "Error", w)
		w.Serve()
		return
	}
	var v []elements.Element
	for _, id := range e.Elements {
		e := elements.NewElement()
		err = elements.GetById(id, &e, w)
		if err != nil {
			errmessage := fmt.Sprintf("Content not found %s : %s", id, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
		} else {
			v = append(v, e)
		}
	}
	w.SetDynamicId(e.DynamicId)
	w.SetContent(v)
	w.Serve()
}
Exemplo n.º 2
0
// Controller to render an element in content editor
func Element(w *wrapper.Wrapper) {
	e := elements.NewElement()
	var id string
	if len(w.APIParams) == 0 {
		http.Error(w.Writer, "Forbidden", 403)
		return
	} else {
		id = w.APIParams[0]
	}
	err := elements.GetById(id, &e, w)
	if err != nil {
		errmessage := fmt.Sprintf("Element not found to edit for %s by %s.", id, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("This element was not found", "Error", w)
	} else {
		w.SetPayload("mongolarid", e.MongoId.Hex())
		w.SetPayload("title", e.Title)
		w.SetPayload("mongolartype", e.Controller)
		w.SetDynamicId(e.MongoId.Hex())
		if e.Controller == "wrapper" {
			we, err := elements.LoadWrapperElement(id, w)
			if err != nil {
				errmessage := fmt.Sprintf("Element not found to edit for %s by %s.", id, w.Request.Host)
				w.SiteConfig.Logger.Error(errmessage)
				services.AddMessage("This element was not found", "Error", w)
			}
			w.SetPayload("elements", we.Elements)
		}
		if e.Controller == "slug" {
			we, err := elements.LoadSlugElement(id, w)
			if err != nil {
				errmessage := fmt.Sprintf("Element not found to edit for %s by %s.", id, w.Request.Host)
				w.SiteConfig.Logger.Error(errmessage)
				services.AddMessage("This element was not found", "Error", w)
			}
			w.SetPayload("elements", we.Slugs)
		}
	}
	w.Serve()
}