コード例 #1
0
ファイル: children.go プロジェクト: ultimatums/mongolar
// Controller for adding existing element to wrapper element form submission.
func AddExistingWrapperSubmit(w *wrapper.Wrapper) {
	parentid := w.APIParams[0]
	var post map[string]string
	err := form.GetValidFormData(w, &post)
	if err != nil {
		return
	}
	var parent elements.WrapperElement
	parent, err = elements.LoadWrapperElement(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:     parentid,
		Controller: "admin/element",
		Template:   "admin/element.html",
		Id:         parentid,
	}
	services.SetDynamic(dynamic, w)
	services.AddMessage("You have added an existing element.", "Success", w)
	w.Serve()
}
コード例 #2
0
ファイル: children.go プロジェクト: ultimatums/mongolar
// Controller for adding children to wrapper element.
func AddWrapperChild(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 elements.WrapperElement
	parent, err = elements.LoadWrapperElement(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, e.MongoId.Hex())
	err = parent.Save(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
	}
	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()
	return

}