github.com/kotovmak/go-admin@v1.1.1/template/types/action/jump.go (about) 1 package action 2 3 import ( 4 "html/template" 5 6 "github.com/kotovmak/go-admin/context" 7 "github.com/kotovmak/go-admin/modules/utils" 8 ) 9 10 type JumpAction struct { 11 BaseAction 12 Url string 13 Target string 14 Ext template.HTML 15 NewTabTitle string 16 } 17 18 func Jump(url string, ext ...template.HTML) *JumpAction { 19 url = utils.ReplaceAll(url, "{%id}", "{{.Id}}", "{%ids}", "{{.Ids}}") 20 if len(ext) > 0 { 21 return &JumpAction{Url: url, Ext: ext[0]} 22 } 23 return &JumpAction{Url: url, NewTabTitle: ""} 24 } 25 26 func JumpInNewTab(url, title string, ext ...template.HTML) *JumpAction { 27 url = utils.ReplaceAll(url, "{%id}", "{{.Id}}", "{%ids}", "{{.Ids}}") 28 if len(ext) > 0 { 29 return &JumpAction{Url: url, NewTabTitle: title, Ext: ext[0]} 30 } 31 return &JumpAction{Url: url, NewTabTitle: title} 32 } 33 34 func JumpWithTarget(url, target string, ext ...template.HTML) *JumpAction { 35 url = utils.ReplaceAll(url, "{%id}", "{{.Id}}", "{%ids}", "{{.Ids}}") 36 if len(ext) > 0 { 37 return &JumpAction{Url: url, Target: target, Ext: ext[0]} 38 } 39 return &JumpAction{Url: url, Target: target} 40 } 41 42 func (jump *JumpAction) GetCallbacks() context.Node { 43 return context.Node{Path: jump.Url, Method: "GET"} 44 } 45 46 func (jump *JumpAction) BtnAttribute() template.HTML { 47 html := template.HTML(`href="` + jump.Url + `"`) 48 if jump.NewTabTitle != "" { 49 html += template.HTML(` data-title="` + jump.NewTabTitle + `"`) 50 } 51 if jump.Target != "" { 52 html += template.HTML(` target="` + jump.Target + `"`) 53 } 54 return html 55 } 56 57 func (jump *JumpAction) BtnClass() template.HTML { 58 if jump.NewTabTitle != "" { 59 return "new-tab-link" 60 } 61 return "" 62 } 63 64 func (jump *JumpAction) ExtContent() template.HTML { 65 return jump.Ext 66 }