本文整理匯總了Golang中github.com/mongolar/mongolar/wrapper.Wrapper.SetPayload方法的典型用法代碼示例。如果您正苦於以下問題:Golang Wrapper.SetPayload方法的具體用法?Golang Wrapper.SetPayload怎麽用?Golang Wrapper.SetPayload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mongolar/mongolar/wrapper.Wrapper
的用法示例。
在下文中一共展示了Wrapper.SetPayload方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SortPathForm
// 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
}
}
示例2: PathEditorForm
// 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
}
示例3: ContentEditorForm
// Controller for content editing form.
func ContentEditorForm(w *wrapper.Wrapper) {
elementid := w.APIParams[0]
e, err := elements.LoadContentElement(elementid, w)
if err != nil {
errmessage := fmt.Sprintf("Element not found to edit for %s by %s", elementid, w.Request.Host)
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("This element was not found", "Error", w)
w.Serve()
return
}
if e.ContentValues.Type == "" {
errmessage := fmt.Sprintf("No content type set for %s", elementid, w.Request.Host)
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("This element doesn't have a content type set. Set a content type to edit values.", "Error", w)
w.Serve()
return
}
var ct contenttypes.ContentType
ct, err = contenttypes.LoadContentTypeT(e.ContentValues.Type, w)
if err != nil {
errmessage := fmt.Sprintf("Unable to find content type %s : %s", e.ContentValues.Type, err.Error())
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("Unable to find content type.", "Error", w)
w.Serve()
return
}
f := form.NewForm()
f.Fields = ct.Form
f.FormData = e.ContentValues.Content
f.Register(w)
w.SetTemplate("admin/form.html")
w.SetPayload("form", f)
w.Serve()
return
}
示例4: SlugUrlEditorForm
func SlugUrlEditorForm(w *wrapper.Wrapper) {
slugid := w.APIParams[0]
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 slug parent", "Error", w)
w.Serve()
return
}
f := form.NewForm()
data := make(map[string]string)
for slug, id := range e.Slugs {
data[id] = slug
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)
services.AddMessage("There was a problem loading some slug elements.", "Error", w)
w.Serve()
return
}
f.AddText(id, "text").AddLabel(e.Title).Required()
}
f.FormData = data
f.Register(w)
w.SetTemplate("admin/form.html")
w.SetPayload("form", f)
w.Serve()
return
}
示例5: EditContentTypeForm
func EditContentTypeForm(w *wrapper.Wrapper) {
f := form.NewForm()
ct := new(ContentType)
if w.APIParams[0] != "new" {
c := w.DbSession.DB("").C("content_types")
i := bson.M{"_id": bson.ObjectIdHex(w.APIParams[0])}
err := c.Find(i).One(ct)
if err != nil {
errmessage := fmt.Sprintf("Content Type not found %s : %s", w.APIParams[0], err.Error())
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("Your content types was not found ", "Error", w)
w.Serve()
return
}
var elements []map[string]interface{}
for _, field := range ct.Form {
element := make(map[string]interface{})
element["type"] = field.Type
element["key"] = field.Key
element["label"] = field.TemplateOptions.Label
element["placeholder"] = field.TemplateOptions.Placeholder
element["rows"] = field.TemplateOptions.Rows
element["cols"] = field.TemplateOptions.Cols
element["options"] = ""
for _, opt := range field.TemplateOptions.Options {
element["options"] = fmt.Sprintf("%s%s|%s\n", element["options"], opt["name"], opt["value"])
}
elements = append(elements, element)
}
data := make(map[string]interface{})
data["elements"] = elements
data["content_type"] = ct.Type
f.FormData = data
} else {
data := make(map[string]interface{})
fd := make([]map[string]string, 0)
data["elements"] = fd
data["content_type"] = ""
f.FormData = data
}
f.AddText("content_type", "text").AddLabel("Content Type Name")
f.AddRepeatSection("elements", "Add another field", FieldFormGroup())
f.Register(w)
w.SetPayload("form", f)
w.SetTemplate("admin/form.html")
w.Serve()
return
}
示例6: GetAllContentTypes
func GetAllContentTypes(w *wrapper.Wrapper) {
c := w.DbSession.DB("").C("content_types")
var cts []ContentType
err := c.Find(nil).Limit(50).Iter().All(&cts)
if err != nil {
errmessage := fmt.Sprintf("Unable to retrieve a list of content types.")
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("Unable to retrieve a list of elements.", "Error", w)
w.Serve()
return
}
w.SetPayload("content_types", cts)
w.Serve()
return
}
示例7: AllElements
// Controller to list all elements
func AllElements(w *wrapper.Wrapper) {
c := w.DbSession.DB("").C("elements")
var es []elements.Element
err := c.Find(nil).Limit(50).Iter().All(&es)
if err != nil {
errmessage := fmt.Sprintf("Unable to retrieve a list of all elements: %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("There was a problem retrieving the element list.", "Error", w)
w.Serve()
return
}
w.SetPayload("elements", es)
w.Serve()
return
}
示例8: LoginUrls
func (lo *LoginMap) LoginUrls(w *wrapper.Wrapper) {
us := make(map[string]map[string]string)
oauthlogins := make(map[string]map[string]string)
w.SiteConfig.RawConfig.MarshalKey("OAuthLogins", &oauthlogins)
for k, l := range oauthlogins {
c := "http://" + w.Request.Host + "/" + w.SiteConfig.APIEndPoint + "/login/callback/" + k
login := lo.Logins[k]
login.SetConfig(l, c, lo.State)
u := login.GetUrl()
m := map[string]string{"url": u, "login_text": l["login_text"]}
us[k] = m
}
w.SetPayload("login_links", us)
w.Serve()
return
}
示例9: GetContentType
func GetContentType(w *wrapper.Wrapper) {
c := w.DbSession.DB("").C("content_types")
i := bson.M{"_id": bson.ObjectIdHex(w.APIParams[0])}
var ct ContentType
err := c.Find(i).One(&ct)
if err != nil {
errmessage := fmt.Sprintf("Content Type not found %s : %s", w.APIParams[0], err.Error())
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("Your content types was not found.", "Error", w)
w.Serve()
return
}
w.SetPayload("content_type", ct)
w.Serve()
return
}
示例10: PathValues
// The controller function to retrieve elements ids from the path
func PathValues(w *wrapper.Wrapper) {
// Request is never url based so we can Never cache this request.
// TODO: move no caching into a reusable function.
w.Writer.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
w.Writer.Header().Add("Pragma", "no-cache")
w.Writer.Header().Add("Expires", "0")
p := paths.NewPath()
u := w.Request.Header.Get("CurrentPath")
if u == "" {
http.Error(w.Writer, "Forbidden", 403)
w.Serve()
return
}
qp, err := p.PathMatch(u, "published", w)
if err != nil {
if err.Error() == "not found" {
if "/"+w.SiteConfig.FourOFour != u {
services.Redirect("/"+w.SiteConfig.FourOFour, w)
w.Serve()
return
} else {
services.AddMessage("There was a problem with the system.", "Error", w)
w.Serve()
return
}
}
}
var v []elements.Element
for _, eid := range p.Elements {
e := elements.NewElement()
err = elements.GetById(eid, &e, w)
if err != nil {
errmessage := fmt.Sprintf("Content not found %s : %s", eid, err.Error())
w.SiteConfig.Logger.Error(errmessage)
} else {
v = append(v, e)
}
}
w.SetPayload("mongolar_slug", qp)
w.SetContent(v)
w.SetTemplate(p.Template)
w.Serve()
return
}
示例11: Element
// 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()
}
示例12: PathElements
// 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()
}
}
示例13: ContentTypeEditorForm
// Controller to ddisplay form to change content type for conteent element
func ContentTypeEditorForm(w *wrapper.Wrapper) {
elementid := w.APIParams[0]
e, err := elements.LoadContentElement(elementid, w)
if err != nil {
errmessage := fmt.Sprintf("Element not found to edit for %s by %s", elementid, w.Request.Host)
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("This element was not found", "Error", w)
w.Serve()
return
}
cts := make([]contenttypes.ContentType, 0)
cts, err = contenttypes.AllContentTypes(w)
if err != nil {
errmessage := fmt.Sprintf("Unable to query all Content Types: %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("Unable to retrieve content types.", "Error", w)
w.Serve()
return
}
opts := make([]map[string]string, 0)
for _, ct := range cts {
opt := map[string]string{
"name": ct.Type,
"value": ct.Type,
}
opts = append(opts, opt)
}
f := form.NewForm()
f.AddSelect("type", opts)
data := map[string]string{"type": e.ContentValues.Type}
f.FormData = data
f.Register(w)
w.SetTemplate("admin/form.html")
w.SetPayload("form", f)
w.Serve()
return
}
示例14: AddExistingChildForm
// Controller for adding existing element form.
func AddExistingChildForm(w *wrapper.Wrapper) {
elems, err := elements.ElementList(w)
if err != nil {
errmessage := fmt.Sprintf("Unable to retrieve a list of all elements: %s", err.Error())
w.SiteConfig.Logger.Error(errmessage)
services.AddMessage("There was a problem retrieving the element list.", "Error", w)
w.Serve()
return
}
options := make([]map[string]string, 0)
for _, element := range elems {
option := map[string]string{"name": element.Title, "value": element.MongoId.Hex(), "group": element.Controller}
options = append(options, option)
}
f := form.NewForm()
f.AddSelect("element", options).AddLabel("Element").Required()
f.Register(w)
w.SetTemplate("admin/form.html")
w.SetPayload("form", f)
w.Serve()
return
}
示例15: Logout
func (lo *LoginMap) Logout(w *wrapper.Wrapper) {
w.SetPayload("logout", "test logout")
w.Serve()
return
}