forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.go
34 lines (30 loc) · 769 Bytes
/
link.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
package display
import (
"github.com/plumk97/go-admin/template"
"github.com/plumk97/go-admin/template/types"
)
type Link struct {
types.BaseDisplayFnGenerator
}
func init() {
types.RegisterDisplayFnGenerator("link", new(Link))
}
func (l *Link) Get(args ...interface{}) types.FieldFilterFn {
prefix := ""
openInNewTabs := false
if len(args) > 0 {
prefix = args[0].(string)
}
if len(args) > 1 {
if openInNewTabsArr, ok := args[1].([]bool); ok {
openInNewTabs = openInNewTabsArr[0]
}
}
return func(value types.FieldModel) interface{} {
if openInNewTabs {
return template.Default().Link().SetURL(prefix + value.Value).OpenInNewTab().GetContent()
} else {
return template.Default().Link().SetURL(prefix + value.Value).GetContent()
}
}
}