Beispiel #1
0
/**
 * 提交评论并保存到数据库
 */
func link_ajax_comment(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.NewCommentSubmitForm()
	f.FillByRequest(ctx.Request)

	var success bool
	var errorMsgs, commentHTML string
	var commentId int64
	if ctx.RouteData.Params["id"] != f.Values()["link_id"] {
		errorMsgs = "参数错误"
	} else {
		var errors []string
		user := ctx.Data["user"].(*models.User)
		success, commentId, errors = models.Comment_SaveForm(f, user.Id)
		if errors != nil {
			errorMsgs = strings.Join(errors, "\n")
		} else {
			linkId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
			m := f.CleanValues()
			cn := models.CommentNode{}
			cn.Id = commentId
			cn.LinkId = linkId
			cn.UserId = user.Id
			cn.Status = 1
			cn.Content = m["content"].(string)
			cn.ParentId = m["parent_id"].(int64)
			cn.ChildrenCount = 0
			cn.VoteUp = 1
			cn.CreateTime = time.Now()
			cn.UserName = user.Name

			sortType := ""
			var b *bytes.Buffer = new(bytes.Buffer)
			cn.RenderSelfOnly(b, sortType)
			commentHTML = b.String()
			//models.GetPermalinkComment(linkId, commentId, "")
		}
	}
	r := map[string]interface{}{
		"success":     success,
		"errors":      errorMsgs,
		"commentHTML": commentHTML,
	}
	return ctx.Json(r)
}
Beispiel #2
0
		if success {
			return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
		} else {
			ctx.ViewData["Errors"] = errorMsgs
			ctx.ViewData["Values"] = f.Values()
		}
		return ctx.View(nil)

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

	/**
	 * 提交评论并保存到数据库
	 */
	Post("ajax-comment", func(ctx *goku.HttpContext) goku.ActionResulter {

		f := forms.NewCommentSubmitForm()
		f.FillByRequest(ctx.Request)

		var success bool
		var errorMsgs string
		if ctx.RouteData.Params["id"] != f.Values()["link_id"] {
			errorMsgs = "参数错误"
		} else {
			var errors []string
			success, errors = models.Comment_SaveForm(f, (ctx.Data["user"].(*models.User)).Id)
			if errors != nil {
				errorMsgs = strings.Join(errors, "\n")
			}
		}
		r := map[string]interface{}{
			"success": success,