forked from ungerik/go-start
/
button.go
40 lines (37 loc) · 1.14 KB
/
button.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
package view
type Button struct {
ViewBaseWithId
Name string
Class string
Disabled bool
TabIndex int
OnClick string
OnClickConfirm string // Will add a confirmation dialog for onclick
Content View // Only used when Submit is false
}
func (self *Button) IterateChildren(callback IterateChildrenCallback) {
if self.Content != nil {
callback(self, self.Content)
}
}
func (self *Button) Render(ctx *Context) (err error) {
ctx.Response.XML.OpenTag("button")
ctx.Response.XML.AttribIfNotDefault("id", self.id)
ctx.Response.XML.AttribIfNotDefault("class", self.Class)
ctx.Response.XML.Attrib("type", "button")
ctx.Response.XML.AttribIfNotDefault("name", self.Name)
if self.Disabled {
ctx.Response.XML.Attrib("disabled", "disabled")
}
ctx.Response.XML.AttribIfNotDefault("tabindex", self.TabIndex)
if self.OnClickConfirm != "" {
ctx.Response.XML.Attrib("onclick", "return confirm('", self.OnClickConfirm, "');")
} else {
ctx.Response.XML.AttribIfNotDefault("onclick", self.OnClick)
}
if self.Content != nil {
err = self.Content.Render(ctx)
}
ctx.Response.XML.ForceCloseTag()
return err
}