Example #1
0
// 内链管理
func (this *AdminController) External() {
	if this.Ctx.Request.Method == "POST" {
		caption := this.GetString("caption")
		link := this.GetString("link")

		redirect := &models.SC_Redirect{
			Caption: caption,
			Link:    link,
		}

		redirect.Save()

		this.Redirect("/admin/redirect", 302)
	}

	var links []models.SC_Redirect

	models.GetAllByQuery(models.DbRedirect, nil, &links)

	this.Data["Lists"] = links

	ids := this.Ctx.Input.Param(":id")
	if ids != "" {
		id := bson.ObjectIdHex(ids)

		var link models.SC_Redirect

		models.GetOneById(models.DbRedirect, id, &link)

		this.Data["Id"] = link.Id
		this.Data["Caption"] = link.Caption
		this.Data["Link"] = link.Link
	}

	this.TplNames = "admin/redirect.html"
}
Example #2
0
// 接受提交数据
func (this *AdminController) Edit() {
	if this.Ctx.Request.Method == "POST" {
		ids := this.GetString("id")
		id := bson.NewObjectId()
		if ids != "" {
			id = bson.ObjectIdHex(ids)
		}
		caption := this.GetString("caption")
		slug := this.GetString("slug")
		atype := this.GetString("type")
		markdown := this.GetString("editor-markdown-doc")
		html := this.GetString("html")
		cover := this.GetString("cover")
		tag := this.GetString("tag")
		splits := strings.Split(tag, ",")
		var tags []string

		if len(splits) > 0 && splits[0] != "" {
			for _, v := range splits {
				tags = append(tags, strings.TrimSpace(v))
				s := common.GetSlug(v, false)
				models.Tag(strings.TrimSpace(v), strings.TrimSpace(s))
			}
		} else {
			tags = splits
		}

		scpost := &models.SC_Post{
			Id:       id,
			Caption:  caption,
			Slug:     slug,
			Tags:     tags,
			Markdown: markdown,
			Html:     html,
			Cover:    cover,
			Type:     atype,
		}

		err := scpost.Save()
		if err != nil {
			beego.Error(err)
		}

		this.Redirect("/admin", 302)
	}

	ids := this.Ctx.Input.Param(":id")
	if ids == "" {
		this.Abort("404")
	}

	id := bson.ObjectIdHex(ids)

	var scpost models.SC_Post

	models.GetOneById(models.DbPost, id, &scpost)

	this.Data["Id"] = id.Hex()
	this.Data["Caption"] = scpost.Caption
	this.Data["Slug"] = scpost.Slug

	if scpost.Type == "page" {
		this.Data["IsPage"] = true
	} else {
		this.Data["IsPost"] = true
	}

	this.Data["Markdown"] = scpost.Markdown
	this.Data["Cover"] = scpost.Cover
	this.Data["Tags"] = scpost.Tags

	this.TplNames = "admin/new.html"
}