user/setting: simplify code

This commit is contained in:
Unknwon
2017-04-07 00:49:30 -04:00
parent ac43eab51f
commit fda4b1106e
4 changed files with 280 additions and 270 deletions

View File

@@ -41,6 +41,23 @@ type Context struct {
Org *Organization
}
// Title sets "Title" field in template data.
func (c *Context) Title(locale string) {
c.Data["Title"] = c.Tr(locale)
}
// PageIs sets "PageIsxxx" field in template data.
func (c *Context) PageIs(name string) {
c.Data["PageIs"+name] = true
}
// FormErr sets "Err_xxx" field in template data.
func (c *Context) FormErr(names ...string) {
for i := range names {
c.Data["Err_"+names[i]] = true
}
}
// UserID returns ID of current logged in user.
// It returns 0 if visitor is anonymous.
func (c *Context) UserID() int64 {
@@ -96,6 +113,12 @@ func (c *Context) JSONSuccess(data interface{}) {
c.JSON(http.StatusOK, data)
}
// SubURLRedirect responses redirection wtih given location and status.
// It prepends setting.AppSubURL to the location string.
func (c *Context) SubURLRedirect(location string, status ...int) {
c.Redirect(setting.AppSubURL + location)
}
// RenderWithErr used for page has form validation but need to prompt error to users.
func (ctx *Context) RenderWithErr(msg, tpl string, f interface{}) {
if f != nil {