Exemple #1
0
func (this *PostRouter) NewSubmit() {
	this.TplNames = "post/new.html"

	if this.CheckActiveRedirect() {
		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)

			models.FilterMentions(&this.user, models.RenderPostContent(content))
			result["success"] = true
		}
		this.Data["json"] = result
		this.ServeJson()
		return
	}

	form := models.PostForm{Locale: this.Locale}
	slug := this.GetString("topic")
	if len(slug) > 0 {
		topic := models.Topic{Slug: slug}
		topic.Read("Slug")
		form.Topic = topic.Id
		this.Data["Topic"] = &topic
	}

	models.ListCategories(&form.Categories)
	models.ListTopics(&form.Topics)
	if !this.ValidFormSets(&form) {
		return
	}

	var post models.Post
	if err := form.SavePost(&post, &this.user); err == nil {
		this.JsStorage("deleteKey", "post/new")
		this.Redirect(post.Link(), 302)
	}
}
Exemple #2
0
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)
}
Exemple #3
0
// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Home() {
	this.Data["IsHome"] = true
	this.TplNames = "post/home.html"

	var cats []models.Category
	this.setCategories(&cats)

	var posts []models.Post
	qs := models.Posts().OrderBy("-Created").Limit(25).RelatedSel()
	qs = this.postsFilter(qs)

	models.ListObjects(qs, &posts)
	this.Data["Posts"] = posts

	this.Data["CategorySlug"] = "hot"

	var topics []models.Topic
	models.ListTopics(&topics)
	this.Data["Topics"] = topics
}
Exemple #4
0
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)
	}
}
Exemple #5
0
func (this *PostRouter) New() {
	this.TplNames = "post/new.html"

	if this.CheckActiveRedirect() {
		return
	}

	form := models.PostForm{Locale: this.Locale}
	form.Lang = this.Locale.Index()

	slug := this.GetString("topic")
	if len(slug) > 0 {
		topic := models.Topic{Slug: slug}
		topic.Read("Slug")
		form.Topic = topic.Id
		this.Data["Topic"] = &topic
	}

	models.ListCategories(&form.Categories)
	models.ListTopics(&form.Topics)
	this.SetFormSets(&form)
}
Exemple #6
0
func (this *PostAdminRouter) GetForm(create bool) models.PostAdminForm {
	form := models.PostAdminForm{Create: create}
	models.ListCategories(&form.Categories)
	models.ListTopics(&form.Topics)
	return form
}