-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.go
120 lines (107 loc) · 2.89 KB
/
dialog.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package components
import (
mgc "github.com/mh-cbon/mdl-go-components"
base "github.com/mh-cbon/mdl-go-components/components_common"
)
type Dialog struct {
mgc.ViewComponent
base.Node
Title string
BgClasses base.ClassList
ContainerClasses base.ClassList
Content mgc.ViewComponentRenderer
Ok *Button
Cancel *Button
Close *Button
}
func NewDialog() *Dialog {
ret := &Dialog{}
ret.SetOverlayColor("grey")
ret.SetBgContainerColor("white")
ret.Ok = NewButton()
ret.SetOkText("Ok", "")
ret.Ok.Classes.Add("custom-dialog-confirm")
ret.Cancel = NewButton()
ret.SetCancelText("Cancel", "")
ret.Cancel.Classes.Add("custom-dialog-cancel")
ret.Close = NewButton()
ret.SetCloseText("", "close")
ret.Close.Classes.Add("custom-dialog-close")
ret.SetBlock("mgc/component_dialog")
return ret
}
func (view *Dialog) SetOverlayColor(colorname string) {
view.BgClasses.RemoveStartingWith("mdl-color--")
view.BgClasses.Add("mdl-color--" + colorname)
}
func (view *Dialog) SetBgContainerColor(colorname string) {
view.ContainerClasses.RemoveStartingWith("mdl-color--")
view.ContainerClasses.Add("mdl-color--" + colorname)
}
func (view *Dialog) Translate(t base.Translator) {
view.Ok.Translate(t)
view.Cancel.Translate(t)
view.Close.Translate(t)
if view.Content != nil {
if v, ok := view.Content.(base.NodeTranslator); ok {
v.Translate(t)
}
}
}
func (view *Dialog) SetErrors(p base.ErrorProvider) {
if view.Content != nil {
if v, ok := view.Content.(base.NodeErrorsSetter); ok {
v.SetErrors(p)
}
}
}
func (view *Dialog) SetTitle(t string) {
view.Title = t
}
func (view *Dialog) GetTitle() string {
return view.Title
}
func (view *Dialog) SetContent(t string) {
text := NewText()
text.SetContent(t)
view.Content = text
}
func (view *Dialog) SetOkText(t string, icon string) {
if icon == "" {
view.Ok.SetLabel(t)
} else {
view.Ok.SetSafeLabel(t + "<i class='material-icons'>" + icon + "</i>")
}
}
func (view *Dialog) SetOkAttr(t string, v string) {
view.Ok.Attr.Set(t, v)
}
func (view *Dialog) SetCancelText(t string, icon string) {
if icon == "" {
view.Cancel.SetLabel(t)
} else {
view.Cancel.SetSafeLabel(t + "<i class='material-icons'>" + icon + "</i>")
}
}
func (view *Dialog) SetCancelAttr(t string, v string) {
view.Cancel.Attr.Set(t, v)
}
func (view *Dialog) SetCloseText(t string, icon string) {
if icon == "" {
view.Close.SetLabel(t)
} else {
view.Close.SetSafeLabel(t + "<i class='material-icons'>" + icon + "</i>")
}
}
func (view *Dialog) SetCloseAttr(t string, v string) {
view.Close.Attr.Set(t, v)
}
func (view *Dialog) Render(args ...interface{}) (string, error) {
view.GetRenderContext().SetDefaultTo(view.Ok)
view.GetRenderContext().SetDefaultTo(view.Cancel)
view.GetRenderContext().SetDefaultTo(view.Close)
if view.Content != nil {
view.GetRenderContext().SetDefaultTo(view.Content)
}
return view.GetRenderContext().RenderComponent(view, args)
}