コード例 #1
0
ファイル: admin.go プロジェクト: jango2015/Blog-3
func (this *AdminController) Entry() {
	checkLogin(this)
	this.TplNames = "admin/entry.tpl"

	eid := this.Ctx.Input.Param(":id")
	fmt.Println(eid)
	if eid != "new" {
		entry, _ := models.EntryById(eid)
		if entry == nil {
			this.Abort("404")
			return
		} else {
			this.Data["Entry"] = entry
			this.Data["PostId"] = "update/" + entry.Id
		}
	}

	this.Data["EntryActive"] = true
	this.Data["MarkdownEnabled"] = true

	collections, err := models.CollectionsByUser(this.GetSession("user").(string))
	if err != nil {
		panic(err)
	}
	this.Data["Collections"] = collections
	fmt.Println(this.Data["Entry"])

	renderTemplate(this.Ctx, "views/admin/entry.amber", this.Data)
}
コード例 #2
0
ファイル: admin.go プロジェクト: jango2015/Blog-3
func (this *AdminController) PostNewEntry() {
	this.TplNames = "admin/entry.tpl"

	entry := models.Entry{}
	err := this.ParseForm(&entry)
	if err != nil {
		panic(err)
	}
	entry.Author = this.GetSession("user").(string)
	entry.Collection = this.Input().Get("collection")
	nid, err := models.AddEntry(entry)
	if err != nil {
		this.Data["PostId"] = "new"
		this.Data["Message"] = err.Error()
	} else {
		this.Data["PostId"] = "update/" + nid
		this.Data["Message"] = "Post Successful"

		collections, err := models.CollectionsByUser(this.GetSession("user").(string))
		if err != nil {
			panic(err)
		}
		this.Data["Collections"] = collections
	}
	this.Data["Entry"] = entry
	this.Data["MarkdownEnabled"] = true
	this.Data["EntryActive"] = true

	renderTemplate(this.Ctx, "views/admin/entry.amber", this.Data)
}
コード例 #3
0
ファイル: admin.go プロジェクト: jango2015/Blog-3
func (this *AdminController) UpdateEntry() {
	entry := models.Entry{}
	err := this.ParseForm(&entry)
	if err != nil {
		panic(err)
	}

	entry.Id = this.Ctx.Input.Param(":id")
	entry.Author = this.GetSession("user").(string)
	entry.Collection = this.Input().Get("collection")
	err = models.UpdateEntry(entry)
	if err != nil {
		panic(err)
	}

	this.TplNames = "admin/entry.tpl"
	this.Data["EntryActive"] = true
	this.Data["PostId"] = "update/" + entry.Id
	this.Data["Entry"] = entry
	this.Data["MarkdownEnabled"] = true
	collections, err := models.CollectionsByUser(this.GetSession("user").(string))
	if err != nil {
		panic(err)
	}
	this.Data["Collections"] = collections
	this.Data["Message"] = "Update Successful"

	renderTemplate(this.Ctx, "views/admin/entry.amber", this.Data)
}
コード例 #4
0
ファイル: admin.go プロジェクト: jango2015/Blog-3
func (this *AdminController) Collections() {
	checkLogin(this)
	this.TplNames = "admin/collection-list.tpl"

	collections, err := models.CollectionsByUser(this.GetSession("user").(string))
	if err != nil {
		panic(err)
	}

	this.Data["CollectionActive"] = true
	this.Data["Collections"] = collections

	renderTemplate(this.Ctx, "views/admin/collection-list.amber", this.Data)
}
コード例 #5
0
ファイル: admin.go プロジェクト: jango2015/Blog-3
func (this *AdminController) NewEntry() {
	checkLogin(this)
	this.TplNames = "admin/entry.tpl"

	this.Data["PostId"] = "new"
	this.Data["EntryActive"] = true
	this.Data["MarkdownEnabled"] = true
	collections, err := models.CollectionsByUser(this.GetSession("user").(string))
	if err != nil {
		panic(err)
	}
	this.Data["Collections"] = collections

	renderTemplate(this.Ctx, "views/admin/entry.amber", this.Data)
}