-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
base.go
57 lines (48 loc) · 1.69 KB
/
base.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
48
49
50
51
52
53
54
55
56
57
package action
import (
"encoding/json"
"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/modules/utils"
"github.com/GoAdminGroup/go-admin/template/types"
"html/template"
"strings"
)
type AjaxData map[string]interface{}
func NewAjaxData() AjaxData {
return AjaxData{"ids": "{{.Ids}}"}
}
func (a AjaxData) Add(m map[string]interface{}) AjaxData {
for k, v := range m {
a[k] = v
}
return a
}
func (a AjaxData) JSON() string {
b, _ := json.Marshal(a)
s := strings.Replace(string(b), `"{%id}"`, "{{.Id}}", -1)
s = strings.Replace(s, `"{%ids}"`, "{{.Ids}}", -1)
s = strings.Replace(s, `"{{.Ids}}"`, "{{.Ids}}", -1)
s = strings.Replace(s, `"{{.Id}}"`, "{{.Id}}", -1)
return s
}
type BaseAction struct {
BtnId string
BtnData interface{}
JS template.JS
}
func (base *BaseAction) SetBtnId(btnId string) { base.BtnId = btnId }
func (base *BaseAction) Js() template.JS { return base.JS }
func (base *BaseAction) BtnClass() template.HTML { return "" }
func (base *BaseAction) BtnAttribute() template.HTML { return "" }
func (base *BaseAction) GetCallbacks() context.Node { return context.Node{} }
func (base *BaseAction) ExtContent() template.HTML { return template.HTML(``) }
func (base *BaseAction) FooterContent() template.HTML { return template.HTML(``) }
func (base *BaseAction) SetBtnData(data interface{}) { base.BtnData = data }
var _ types.Action = (*AjaxAction)(nil)
var _ types.Action = (*PopUpAction)(nil)
var _ types.Action = (*JumpAction)(nil)
var _ types.Action = (*JumpSelectBoxAction)(nil)
func URL(id string) string {
return config.Url("/operation/" + utils.WrapURL(id))
}