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

     1  package root
     2  
     3  import (
     4  	"github.com/insionng/makross"
     5  	
     6  	"github.com/insionng/yougam/models"
     7  )
     8  
     9  func GetRReadCategoryHandler(self *makross.Context) error {
    10  	
    11  
    12  	TplNames := ""
    13  	self.Set("catpage", "RReadCategoryHandler")
    14  	switch cid := self.Param("cid").MustInt64(); {
    15  	//单独模式
    16  	case cid > 0:
    17  		{
    18  			TplNames = "root/create_category"
    19  
    20  			if cat, err := models.GetCategory(cid); cat != nil && err == nil {
    21  				self.Set("category", *cat)
    22  
    23  				if nodes, err := models.GetNodes(0, 0, "id"); nodes != nil && err == nil {
    24  					self.Set("nodes", *nodes)
    25  				}
    26  
    27  			} else {
    28  				self.Flash.Error(err.Error())
    29  				return self.Render(TplNames)
    30  			}
    31  		}
    32  	//列表模式
    33  	case cid <= 0:
    34  		{
    35  			TplNames = "root/category_table"
    36  			offset := self.Args("offset").MustInt64()
    37  			limit := self.Args("limit").MustInt64()
    38  			field := self.FormValue("field")
    39  
    40  			if limit == 0 {
    41  				limit = 1000 //默认限制显示最近1000条,需要显示全部请在提交请求的时候设置limit字段为-1
    42  			}
    43  
    44  			if field == "" {
    45  				field = "id"
    46  			}
    47  
    48  			if cats, err := models.GetCategories(int(offset), int(limit), field); err == nil && cats != nil {
    49  				self.Set("categories", *cats)
    50  			}
    51  		}
    52  	}
    53  
    54  	return self.Render(TplNames)
    55  
    56  }