-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
jump.go
54 lines (46 loc) · 1.3 KB
/
jump.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
package action
import (
"github.com/GoAdminGroup/go-admin/context"
"html/template"
"strings"
)
type JumpAction struct {
BaseAction
Url string
Ext template.HTML
NewTabTitle string
}
func Jump(url string, ext ...template.HTML) *JumpAction {
url = strings.Replace(url, "{%id}", "{{.Id}}", -1)
url = strings.Replace(url, "{%ids}", "{{.Ids}}", -1)
if len(ext) > 0 {
return &JumpAction{Url: url, Ext: ext[0]}
}
return &JumpAction{Url: url, NewTabTitle: ""}
}
func JumpInNewTab(url, title string, ext ...template.HTML) *JumpAction {
url = strings.Replace(url, "{%id}", "{{.Id}}", -1)
url = strings.Replace(url, "{%ids}", "{{.Ids}}", -1)
if len(ext) > 0 {
return &JumpAction{Url: url, NewTabTitle: title, Ext: ext[0]}
}
return &JumpAction{Url: url, NewTabTitle: title}
}
func (jump *JumpAction) GetCallbacks() context.Node {
return context.Node{Path: jump.Url, Method: "GET"}
}
func (jump *JumpAction) BtnAttribute() template.HTML {
if jump.NewTabTitle != "" {
return template.HTML(`href="` + jump.Url + `" data-title="` + jump.NewTabTitle + `"`)
}
return template.HTML(`href="` + jump.Url + `"`)
}
func (jump *JumpAction) BtnClass() template.HTML {
if jump.NewTabTitle != "" {
return "new-tab-link"
}
return ""
}
func (jump *JumpAction) ExtContent() template.HTML {
return jump.Ext
}