func (this *Sites) Info() { id := this.GetString(":id") var o *models.Site o, _ = models.NewSite().Find(id) data := make(map[string]interface{}) data["site"] = o this.JsonOut(data, "0") }
// 菜单列表 func (this *Sites) List() { var condition bson.M data := make(map[string]interface{}) page, rows := this.GetPageSize() m := models.NewSite() items := m.FindBy(condition, page, rows) records := m.Count(condition) data["sites"] = items data["pagination"] = models.Pageinate{ Records: records, Page: page, Rows: rows, } this.JsonOut(data, "0") }
func (this *Sites) Edit() { id := this.GetString(":id") fm := models.SiteForm{} if err := this.ParseForm(&fm); err != nil { this.JsonOut(nil, "1", err.Error()) } valid := validation.Validation{} valid.Required(fm.Name, "name").Message("名称不能为空") valid.Required(fm.Link, "link").Message("网址不能为空") valid.Required(fm.Status, "status").Message("状态不能为空") if errmsg, ok := this.HasErrMsgs(valid); ok { this.JsonOut(nil, "1", errmsg) } o := models.NewSite() if "" != id { o, _ = o.Find(id) } o.Name = fm.Name o.Link = fm.Link o.Desc = fm.Desc o.Status = fm.Status err := o.Persist() if nil == err { this.JsonOut(nil, "0") } else if o.Id.Valid() { this.JsonOut(nil, "1", "修改网址失败") } else { this.JsonOut(nil, "1", "添加网址失败") } }