forked from GoAdminGroup/go-admin
/
update.go
47 lines (37 loc) · 940 Bytes
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package guard
import (
"net/http"
"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
)
type UpdateParam struct {
Panel table.Table
Prefix string
Value form.Values
}
func (g *Guard) Update(ctx *context.Context) {
panel, prefix := g.table(ctx)
pname := panel.GetPrimaryKey().Name
id := ctx.FormValue("pk")
if id == "" {
ctx.JSON(http.StatusBadRequest, map[string]interface{}{
"msg": "wrong " + pname,
})
ctx.Abort()
return
}
var f = make(form.Values)
f.Add(form.PostIsSingleUpdateKey, "1")
f.Add(pname, id)
f.Add(ctx.FormValue("name"), ctx.FormValue("value"))
ctx.SetUserValue(updateParamKey, &UpdateParam{
Panel: panel,
Prefix: prefix,
Value: f,
})
ctx.Next()
}
func GetUpdateParam(ctx *context.Context) *UpdateParam {
return ctx.UserValue[updateParamKey].(*UpdateParam)
}