swirl/controller/common.go

36 lines
695 B
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package controller
import (
2017-11-08 10:36:13 +00:00
"github.com/cuigh/auxo/data"
2017-09-26 12:50:09 +00:00
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/model"
)
2017-11-08 10:36:13 +00:00
func newModel(ctx web.Context) data.Map {
return data.Map{
2017-09-26 12:50:09 +00:00
"ContextUser": ctx.User(),
}
}
2017-11-08 10:36:13 +00:00
func newPagerModel(ctx web.Context, totalCount, size, page int) data.Map {
2017-09-26 12:50:09 +00:00
pager := model.NewPager(ctx.Request().RequestURI, totalCount, size, page)
2017-11-08 10:36:13 +00:00
return newModel(ctx).Set("Pager", pager)
2017-09-26 12:50:09 +00:00
}
func ajaxResult(ctx web.Context, err error) error {
if err != nil {
return err
}
2017-11-08 10:36:13 +00:00
return ctx.JSON(data.Map{
2017-09-26 12:50:09 +00:00
"success": err == nil,
})
}
2017-11-08 10:36:13 +00:00
func ajaxSuccess(ctx web.Context, value interface{}) error {
return ctx.JSON(data.Map{
2017-09-26 12:50:09 +00:00
"success": true,
2017-11-08 10:36:13 +00:00
"data": value,
2017-09-26 12:50:09 +00:00
})
}