func (a *Category) Edit() error { id := com.Int(a.Form(`id`)) m, has, err := a.cateM.Get(id) if err != nil { return err } else if !has { return a.NotFoundData().Display() } if a.IsPost() { err = a.Bind(m) if err != nil { return err } if a.validOk(m) { affected, err := a.cateM.Edit(m.Id, m) if err != nil { a.SetErr(err.Error()) } else if affected < 1 { a.NotModified() } else { a.Done() } } } a.Assign(`Detail`, m) a.Assign(`Breadcrumbs`, a.cateM.Dir(m.Pid)) return a.Display() }
func (a *Category) Index() error { pid := com.Int(a.Query(`pid`)) nid := com.Int(a.Query(`ignore`)) sel := a.cateM.NewSelect(&D.Category{}) sel.Condition = `pid=?` sel.AddParam(pid) if nid > 0 { sel.Condition += ` AND id!=?` sel.AddParam(nid) } sel.FromClient(true, "Name") countFn, data, _ := a.cateM.List(sel) sel.Client.SetCount(countFn).Data(data) a.Assign(`Breadcrumbs`, a.cateM.Dir(pid)) return a.Display() }
func (a *Setting) Edit() error { id := com.Int(a.Form(`id`)) m, has, err := a.confM.Get(id) if err != nil { return err } else if !has { return a.NotFoundData().Display() } if a.IsPost() { err = a.Bind(m) if err != nil { return err } affected, err := a.confM.Edit(m.Id, m) if err != nil { a.SetErr(err.Error()) } else if affected < 1 { a.NotModified() } else { a.Done() } } a.Assign(`Detail`, m) return a.Display() }
func (a *Post) Edit() error { id := com.Int(a.Form(`id`)) m, has, err := a.postM.Get(id) if err != nil { return err } else if !has { return a.NotFoundData().Display() } if a.IsPost() { err = a.Bind(m) if err != nil { return err } if a.validOk(m) { affected, err := a.postM.Edit(m.Id, m) if err != nil { a.SetErr(err.Error()) } else if affected < 1 { a.NotModified() } else { a.Done() } } } other, _, err := a.postM.GetOtherContent(m.Id) if err != nil { return err } a.Assign(`Detail`, m) a.Assign(`Other`, other) cateM := model.NewCategory(a.Context) a.Assign(`Breadcrumbs`, cateM.Dir(m.Catid)) return a.Display() }
func (a *Category) Delete() error { id := com.Int(a.Form(`id`)) if id < 1 { return a.NotFoundData().Redir(a.NextURL(`Index`)) } affected, err := a.cateM.Delete(id) if err != nil { return err } if affected < 1 { return a.NotFoundData().Redir(a.NextURL(`Index`)) } a.Done() return a.Redir(a.NextURL(`Index`)) }
func (a *Link) Delete() error { id := com.Int(a.Form(`id`)) if id < 1 { return a.NotFoundData().Display() } affected, err := a.lnkM.Delete(id) if err != nil { return err } if affected < 1 { return a.NotFoundData().Display() } a.Done() return a.Display() }
func (a *Category) Index_HTML() error { pid := com.Int(a.Query(`pid`)) a.Assign(`Breadcrumbs`, a.cateM.Dir(pid)) return a.Display() }
func (a *DataTable) Init(c *X.Context, orm *database.Orm, m interface{}) client.Client { a.Context = c a.Orm = orm a.pageSize = com.Int64(c.Form(`length`)) a.offset = com.Int64(c.Form(`start`)) if a.pageSize < 1 || a.pageSize > 1000 { a.pageSize = 10 } if a.offset < 0 { a.offset = 0 } a.fields = make([]string, 0) a.tableFields = make([]string, 0) a.searches = make(map[string]string) a.page = (a.offset + a.pageSize) / a.pageSize a.orders = Sorts{} a.fieldsInfo = make(map[string]*core.Column) a.search = c.Form(`search[value]`) a.draw = c.Form(`draw`) a.totalRows = com.Int64(a.Context.Form(`totalrows`)) if a.totalRows < 1 && a.countFn != nil { a.totalRows = a.countFn() } table := orm.TableInfo(m) if table == nil { return a } pks := table.PKColumns() if len(pks) > 0 { for _, col := range pks { if col.IsPrimaryKey && col.IsAutoIncrement { a.idFieldName = col.Name break } } } var fm []string = strings.Split(`columns[0][data]`, `0`) for k, _ := range c.Request().Form().All() { if !strings.HasPrefix(k, fm[0]) || !strings.HasSuffix(k, fm[1]) { continue } idx := strings.TrimSuffix(k, fm[1]) idx = strings.TrimPrefix(idx, fm[0]) //要查询的所有字段 field := c.Form(k) column := table.GetColumn(field) if column != nil && column.FieldName == field { a.fields = append(a.fields, field) field = column.Name a.tableFields = append(a.tableFields, field) //搜索本字段 kw := c.Form(`columns[` + idx + `][search][value]`) if kw != `` { a.searches[field] = kw } a.fieldsInfo[field] = column } //要排序的字段 fidx := c.Form(`order[` + idx + `][column]`) if fidx == `` { continue } field = c.Form(fm[0] + fidx + fm[1]) if field == `` { continue } column = table.GetColumn(field) if column != nil && column.FieldName == field { sort := c.Form(`order[` + idx + `][dir]`) if sort != `asc` { sort = `desc` } a.orders.Insert(com.Int(idx), field, column.Name, sort) } } //a.Form(`search[regex]`)=="false" //columns[0][search][regex]=false / columns[0][search][value] return a }