-
Notifications
You must be signed in to change notification settings - Fork 34
/
group.go
54 lines (47 loc) · 1.32 KB
/
group.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
package forms
import (
"reflect"
)
type Group struct {
Namespace string `yaml:"namespace" json:"namespace"`
Elements []ElementInterface `yaml:"elements" json:"elements"`
HTML string `yaml:"html" json:"html"`
IsComposed bool `yaml:"isComposed" json:"isComposed"`
ComposedAttrs map[string]string `yaml:"composedAttrs" json:"composedAttrs"`
}
func (this *Group) Add(element ElementInterface) {
s := element.Super()
s.Namespace = this.Namespace
s.ClassType = reflect.TypeOf(element).Elem().Name()
this.Elements = append(this.Elements, element)
}
func (this *Group) Compose() {
this.HTML = ""
for _, e := range this.Elements {
element := e.Super()
if element.IsComposed {
for k, v := range this.ComposedAttrs {
element.Attr(k, v)
}
this.HTML += e.Compose()
this.IsComposed = true
} else {
this.HTML += "<tr>\n"
this.HTML += " <td class=\"title\">" + element.Title
if len(element.Subtitle) > 0 {
this.HTML += " (" + element.Subtitle + ")"
}
if element.IsRequired {
this.HTML += " *"
}
this.HTML += "</td>\n"
this.HTML += " <td>\n"
this.HTML += e.Compose()
if len(element.Comment) > 0 {
this.HTML += "\n<p class=\"comment\">" + element.Comment + "</p>"
}
this.HTML += "\n</td>"
this.HTML += "</tr>"
}
}
}