-
Notifications
You must be signed in to change notification settings - Fork 6
/
list_checkbox.go
93 lines (81 loc) · 2.19 KB
/
list_checkbox.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
package generator
import (
"fmt"
"github.com/goradd/goradd/codegen/generator"
"github.com/goradd/goradd/pkg/orm/db"
)
func init() {
generator.RegisterControlGenerator(CheckboxList{}, "github.com/goradd/goradd/pkg/page/control/CheckboxList")
}
// This structure describes the CheckboxList to the connector dialog and code generator
type CheckboxList struct {
}
func (d CheckboxList) NewFunc() string {
return "NewCheckboxList"
}
func (d CheckboxList) SupportsColumn(ref interface{}) bool {
if rr,ok := ref.(*db.ReverseReference); ok {
if rr.IsUnique() {
return false
}
return true
}
if _,ok := ref.(*db.ManyManyReference); ok {
return true
}
return false
}
func (d CheckboxList) GenerateCreator(ref interface{}, desc *generator.ControlDescription) (s string) {
s = fmt.Sprintf(
`%s.CheckboxListCreator{
ID: p.ID() + "-%s",
DataProvider: p,
ControlOptions: page.ControlOptions{
DataConnector: %s{},
},
}`, desc.Package, desc.ControlID, desc.Connector)
return
}
func (d CheckboxList) GenerateRefresh(ref interface{}, desc *generator.ControlDescription) string {
switch ref.(type) {
case *db.ReverseReference:
return `
var values []string
for _,obj := range objects {
values = append(values, fmt.Sprint(obj.PrimaryKey()))
}
ctrl.SetSelectedValues(values)`
case *db.ManyManyReference:
return ``
}
return ``
}
func (d CheckboxList) GenerateUpdate(ref interface{}, desc *generator.ControlDescription) string {
/* switch col := ref.(type) {
case *db.ReverseReference:
return fmt.Sprintf(`
values := ctrl.SelectedValues()
model.Unasso
`,
col.GoPlural)
case *db.ManyManyReference:
return fmt.Sprintf(`
values := []string
for _,obj := range model.Load%s(ctx) {
values = append(values, obj.PrimaryKey())
}
ctrl.SetSelectedValues(values)`,
col.GoPlural)
}
*/
return ``
}
func (d CheckboxList) GenerateProvider(ref interface{}, desc *generator.ControlDescription) string {
switch col := ref.(type) {
case *db.ReverseReference:
return fmt.Sprintf(`return model.Query%s(ctx).LoadI()`, col.AssociatedTable.GoPlural)
case *db.ManyManyReference:
return fmt.Sprintf(`return model.Query%s(ctx).LoadI()`, col.AssociatedTableName)
}
return ``
}