forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jump.go
66 lines (56 loc) · 1.63 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
55
56
57
58
59
60
61
62
63
64
65
66
package action
import (
"html/template"
"github.com/plumk97/go-admin/context"
"github.com/plumk97/go-admin/modules/utils"
)
type JumpAction struct {
BaseAction
Url string
Target string
Ext template.HTML
NewTabTitle string
}
func Jump(url string, ext ...template.HTML) *JumpAction {
url = utils.ReplaceAll(url, "{%id}", "{{.Id}}", "{%ids}", "{{.Ids}}")
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 = utils.ReplaceAll(url, "{%id}", "{{.Id}}", "{%ids}", "{{.Ids}}")
if len(ext) > 0 {
return &JumpAction{Url: url, NewTabTitle: title, Ext: ext[0]}
}
return &JumpAction{Url: url, NewTabTitle: title}
}
func JumpWithTarget(url, target string, ext ...template.HTML) *JumpAction {
url = utils.ReplaceAll(url, "{%id}", "{{.Id}}", "{%ids}", "{{.Ids}}")
if len(ext) > 0 {
return &JumpAction{Url: url, Target: target, Ext: ext[0]}
}
return &JumpAction{Url: url, Target: target}
}
func (jump *JumpAction) GetCallbacks() context.Node {
return context.Node{Path: jump.Url, Method: "GET"}
}
func (jump *JumpAction) BtnAttribute() template.HTML {
html := template.HTML(`href="` + jump.Url + `"`)
if jump.NewTabTitle != "" {
html += template.HTML(` data-title="` + jump.NewTabTitle + `"`)
}
if jump.Target != "" {
html += template.HTML(` target="` + jump.Target + `"`)
}
return html
}
func (jump *JumpAction) BtnClass() template.HTML {
if jump.NewTabTitle != "" {
return "new-tab-link"
}
return ""
}
func (jump *JumpAction) ExtContent() template.HTML {
return jump.Ext
}