forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.go
76 lines (64 loc) · 1.78 KB
/
select.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
67
68
69
70
71
72
73
74
75
76
package types
import (
"github.com/wowucco/go-admin/modules/language"
"github.com/wowucco/go-admin/modules/utils"
"html/template"
"strconv"
)
type DefaultSelection struct {
*BaseButton
Options FieldOptions
Placeholder string
Width int
}
func btnUUID() string {
return "info-btn-" + utils.Uuid(10)
}
func GetDefaultSelection(placeholder string, options FieldOptions, action Action, widths ...int) *DefaultSelection {
id := btnUUID()
action.SetBtnId(id)
var width = 100
if len(widths) > 0 {
width = widths[0]
}
node := action.GetCallbacks()
return &DefaultSelection{
BaseButton: &BaseButton{
Id: id,
Action: action,
Url: node.Path,
Method: node.Method,
},
Placeholder: placeholder,
Width: width,
Options: options,
}
}
func (b *DefaultSelection) Content() (template.HTML, template.JS) {
optionsHtml := `<option value='__go_admin_all__'>` + language.Get("All") + `</option>`
for _, op := range b.Options {
optionsHtml += `<option value='` + op.Value + `'>` + op.Text + `</option>`
}
h := template.HTML(`<div class="btn-group pull-right" style="margin-right: 10px">
<div style="width:`+strconv.Itoa(b.Width)+`px;">
<select style="width:100%;height:30px;" class="`+b.Id+` select2-hidden-accessible" name="`+b.Id+`"
data-multiple="false" data-placeholder="`+b.Placeholder+`" tabindex="-1" aria-hidden="true">
<option></option>
`+optionsHtml+`
</select>
</div>
</div>
<style type="text/css">
.box-header .select2-container .select2-selection--single {
height: 30px;
line-height: 24px;
}
.box-header .select2-container--default .select2-selection--single .select2-selection__rendered
{
line-height: 24px;
}
</style>`) + b.Action.ExtContent()
return h, b.Action.Js() + template.JS(`
$(".`+b.Id+`").select2();
`)
}