-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.go
103 lines (89 loc) · 2.09 KB
/
index.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
// Package tutorial contains the tutorial for learning about GoRADD.
package tutorial
import (
"context"
"github.com/goradd/goradd/pkg/config"
"github.com/goradd/goradd/pkg/page/action"
. "github.com/goradd/goradd/pkg/page/control/button"
. "github.com/goradd/goradd/pkg/page/control/dialog"
"path"
"strings"
"github.com/goradd/goradd/pkg/page"
. "github.com/goradd/goradd/pkg/page/control"
)
const IndexFormPath = "/goradd/tutorial.g"
const IndexFormId = "IndexForm"
const (
ViewSourceAction = iota + 1
)
type IndexForm struct {
FormBase
Cat string
Num int
}
func (f *IndexForm) Init(ctx context.Context, formID string) {
f.FormBase.Init(ctx, formID)
f.AddRelatedFiles()
f.AddControls(ctx,
PanelCreator{
ID: "detailPanel",
},
ButtonCreator{
ID: "viewSourceButton",
Text: "View Source",
OnClick: action.Ajax(f.ID(), ViewSourceAction),
},
)
}
func (f *IndexForm) AddRelatedFiles() {
f.FormBase.AddRelatedFiles()
f.AddStyleSheetFile(path.Join(config.AssetPrefix, "goradd", "welcome", "css", "welcome.css"), nil)
}
func (f *IndexForm) LoadControls(ctx context.Context) {
if pageID, ok := page.GetContext(ctx).FormValue("pageID"); ok {
// pageID is a category and integer id combined
parts := strings.Split(pageID, "-")
if len(parts) != 2 {
return
}
cat := parts[0]
id := parts[1]
pl, ok := pages[cat]
if !ok {
return
}
for i, pr := range pl {
if pr.id == id {
pr.f(ctx, GetPanel(f, "detailPanel"))
f.Cat = cat
f.Num = i
break
}
}
} else {
NewDefaultPanel(ctx, GetPanel(f, "detailPanel"))
}
}
func (f *IndexForm) ShowSourceDialog() {
d, isNew := GetDialogPanel(f, "sourceDialog")
if isNew {
d.SetTitle("Source")
d.AddCloseButton("Close", "close")
d.SetHasCloseBox(true)
NewSourcePanel(d, "sourcePanel")
}
d.Show()
}
func (f *IndexForm) DoAction(ctx context.Context, a action.Params) {
switch a.ID {
case ViewSourceAction:
if l, ok := pages[f.Cat]; ok {
pr := l[f.Num]
f.ShowSourceDialog()
GetSourcePanel(f).show(pr.files)
}
}
}
func init() {
page.RegisterForm(IndexFormPath, &IndexForm{}, IndexFormId)
}