func (this *PostRouter) Edit() { this.TplNames = "post/edit.html" if this.CheckActiveRedirect() { return } var post models.Post if this.loadPost(&post, &this.user) { return } form := models.PostForm{} form.SetFromPost(&post) models.ListCategories(&form.Categories) models.ListTopics(&form.Topics) this.SetFormSets(&form) }
func (this *PostRouter) EditSubmit() { this.TplNames = "post/edit.html" if this.CheckActiveRedirect() { return } var post models.Post if this.loadPost(&post, &this.user) { return } if this.IsAjax() { result := map[string]interface{}{ "success": false, } action := this.GetString("action") switch action { case "preview": content := this.GetString("content") result["preview"] = models.RenderPostContent(content) result["success"] = true } this.Data["json"] = result this.ServeJson() return } form := models.PostForm{} form.SetFromPost(&post) models.ListCategories(&form.Categories) models.ListTopics(&form.Topics) if !this.ValidFormSets(&form) { return } if err := form.UpdatePost(&post, &this.user); err == nil { this.JsStorage("deleteKey", "post/edit") this.Redirect(post.Link(), 302) } }