github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/routers/root/RUpdateCategory.go (about)

     1  package root
     2  
     3  import (
     4  	"github.com/insionng/makross"
     5  	
     6  	"strconv"
     7  	"github.com/insionng/yougam/helper"
     8  	"github.com/insionng/yougam/models"
     9  )
    10  
    11  func GetRUpdateCategoryHandler(self *makross.Context) error {
    12  	self.Set("catpage", "RUpdateCategoryHandler")
    13  	TplNames := "root/update_category"
    14  
    15  	cid := self.Param("cid").MustInt64()
    16  
    17  	category, _ := models.GetCategory(cid)
    18  
    19  	self.Set("category", category)
    20  	if nds, err := models.GetNodes(0, 0, "id"); nds != nil && err == nil {
    21  		self.Set("nodes", nds)
    22  
    23  	}
    24  
    25  	return self.Render(TplNames)
    26  
    27  }
    28  
    29  func PostRUpdateCategoryHandler(self *makross.Context) error {
    30  	
    31  
    32  	self.Set("catpage", "RUpdateCategoryHandler")
    33  	//TplNames := "root/update_category"
    34  
    35  	cid := self.Param("cid").MustInt64()
    36  	nid := self.Args("nodeid").MustInt64()
    37  
    38  	images := self.FormValue("images")
    39  	title := self.FormValue("title")
    40  
    41  	policy := helper.ObjPolicy()
    42  	content := policy.Sanitize(self.FormValue("content"))
    43  
    44  	if nds, err := models.GetNodes(0, 0, "id"); nds != nil && err == nil {
    45  		self.Set("nodes", nds)
    46  	}
    47  
    48  	if len(title) > 0 && cid > 0 {
    49  		cat, _ := models.GetCategory(cid)
    50  
    51  		cat.Title = title
    52  		cat.Content = content
    53  		cat.Attachment = images
    54  		//nd, _ := models.GetNode(nid)
    55  		cat.Pid = nid
    56  		models.PutCategory(cid, cat)
    57  		self.Set("cat", cat)
    58  
    59  		self.Flash.Success("更新分类成功!")
    60  		return self.Redirect("/root/update/category/" + strconv.FormatInt(cid, 10) + "/")
    61  	} else {
    62  		self.Flash.Error("更新分类失败,标题为空或非法请求!")
    63  		return self.Redirect("/root/read/category/")
    64  	}
    65  
    66  }