Ejemplo n.º 1
0
func favorite_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		user := ctx.Data["user"].(*models.User)

		links := models.FavoriteLink_ByUser(user.Id, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "参数错误"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
Ejemplo n.º 2
0
)

type FavoriteResult struct {
	Success bool   `json:"success"`
	Errors  string `json:"errors"`
}

var _ = goku.Controller("favorite").
	/**
	 * 用户收藏link的首页
	 */
	Get("index", func(ctx *goku.HttpContext) goku.ActionResulter {

		u, _ := ctx.Data["user"]
		user := u.(*models.User)
		links := models.FavoriteLink_ByUser(user.Id, 1, golink.PAGE_SIZE)
		ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
		ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
		ctx.ViewData["UserMenu"] = "um-favorite"

		return ctx.Render("/favorite/show", nil)

	}).Filters(filters.NewRequireLoginFilter()).

	/**
	 * load more
	 */
	Get("loadmorelink", favorite_loadMoreLink).
	Filters(filters.NewRequireLoginFilter(), filters.NewAjaxFilter()).

	/**