Beispiel #1
0
//修改文章栏目页面
func (c *CategoryController) Edit() {
	CheckAdminLogin(&c.Controller, 0)
	myid := c.Ctx.Input.Param(":id")
	id, err := strconv.ParseInt(myid, 10, 64)
	if err != nil {
		EchoErrorPage(&c.Controller, "错误参数传递!", "/admin/category")
	}
	entity := models.GetCategory(id)
	if entity == nil {
		EchoErrorPage(&c.Controller, "系统找不到本记录!", "/admin/category")
	}
	//获取所有上级栏目
	PCategories := models.GetCategoryTree(0, -1, true, entity.Id)
	//获取模板目录
	skin := "default"
	templatesList, err := common.GetFolderFiles("views/"+skin, "")
	if err != nil {
		templatesList = nil
	}
	c.Data["Title"] = "修改栏目"
	c.Data["Entity"] = entity
	c.Data["Action"] = "edit"
	c.Data["TemplatesList"] = templatesList
	c.Data["PCategories"] = PCategories
	c.TplNames = "admin/category_add.tpl"
}
Beispiel #2
0
//删除文章
func (c *CategoryController) DoDel() {
	CheckAdminLogin(&c.Controller, 1)
	id, _ := strconv.ParseInt(c.GetString("id"), 10, 64)
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	if id <= 0 {
		tip.Message = "错误参数传递!"
		EchoTip(&c.Controller, tip)
	}
	entity := models.GetCategory(id)
	if entity == nil {
		tip.Message = "系统找不到本记录!"
		EchoTip(&c.Controller, tip)
	} else {
		if err := models.DelCategory(entity); err != nil {
			tip.Message = "删除出错:" + err.Error()
			EchoTip(&c.Controller, tip)
		} else {
			tip.Status = models.TipSuccess
			tip.Message = "删除成功!"
			tip.ReturnUrl = "/admin/category"
			EchoTip(&c.Controller, tip)
		}
	}
}
Beispiel #3
0
//执行添加
func (c *CategoryController) DoAdd() {
	CheckAdminLogin(&c.Controller, 1)
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	entity := &models.Category{}
	entity.Title = c.GetString("Title")
	entity.Ctype = 0
	entity.Content = c.GetString("Content")
	newPid, _ := strconv.ParseInt(c.GetString("Pid"), 10, 64)
	//如果PID大于0 则获取分类,本身级别增加1
	if newPid != entity.Pid {
		if newPid > 0 {
			pc := models.GetCategory(newPid)
			if pc != nil {
				entity.Level = pc.Level + 1
			} else {
				entity.Pid = 0
				entity.Level = 1
			}
		} else {
			entity.Pid = 0
			entity.Level = 1
		}
	}

	if entity.Title == "" {
		tip.Message = "分类名称不能为空"
		c.Data["json"] = tip
		c.ServeJson()
		c.StopRun()
	}

	if c.GetString("IsList") == "1" {
		entity.IsList = 1
	} else {
		entity.IsList = 0
	}
	if c.GetString("IsHide") == "1" {
		entity.IsHide = 1
	} else {
		entity.IsHide = 0
	}
	entity.PageSize, _ = strconv.ParseInt(c.GetString("PageSize"), 10, 64)
	entity.Rank, _ = strconv.ParseInt(c.GetString("Rank"), 10, 64)
	entity.Keyword = c.GetString("Keyword")
	entity.Description = c.GetString("Description")
	entity.Pic = c.GetString("Pic")
	entity.DetailTemplateFile = c.GetString("DetailTemplateFile")
	entity.TemplateFile = c.GetString("TemplateFile")
	entity.LinkUrl = c.GetString("LinkUrl")
	if id, err := models.AddCategory(entity); id > 0 && err == nil {
		//添加成功
		tip.Status = models.TipSuccess
		tip.Id = id
		tip.ReturnUrl = "/admin/category"
		tip.Message = "添加新分类成功"
	} else {
		tip.Id = id
		tip.Message = "添加新分类失败:" + err.Error()
	}
	c.Data["json"] = tip
	c.ServeJson()
	c.StopRun()

}