-
Notifications
You must be signed in to change notification settings - Fork 6
/
dialogs.go
96 lines (87 loc) · 2.68 KB
/
dialogs.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
package panels
import (
"context"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/action"
. "github.com/goradd/goradd/pkg/page/control"
. "github.com/goradd/goradd/pkg/page/control/button"
. "github.com/goradd/goradd/pkg/page/control/dialog"
. "github.com/goradd/goradd/pkg/page/control/textbox"
)
type DialogsPanel struct {
Panel
}
const (
ButtonAlert = iota + 11010
ButtonMessage
MessageAction
)
func NewDialogsPanel(ctx context.Context, parent page.ControlI) {
p := new(DialogsPanel)
p.Init(p, ctx, parent, "dialogsPanel")
}
func (p *DialogsPanel) Init(self any, ctx context.Context, parent page.ControlI, id string) {
p.Panel.Init(self, parent, id)
p.AddControls(ctx,
PanelCreator{
ID: "result",
},
ButtonCreator{
ID: "alertButton",
Text: "Alert",
OnSubmit: action.Do().ControlID("dialogsPanel").ID(ButtonAlert),
},
ButtonCreator{
ID: "messageButton",
Text: "Message",
OnSubmit: action.Do().ControlID("dialogsPanel").ID(ButtonMessage).Post(),
},
)
// This is really specific to this demo because we are switching back and forth between this and bootstrap dialogs.
// You do not normally need to do this.
RestoreNewDialogFunction()
}
func (p *DialogsPanel) DoAction(ctx context.Context, a action.Params) {
switch a.ID {
case ButtonAlert:
Alert(p, "Alert", "Look out!", true)
case ButtonMessage:
// GetDialogPanel here will create a new one if one is not already in the form, or will retrieve an old
// one if its just hidden
dp, isNew := GetDialogPanel(p, "msg-dlg")
if isNew {
// Set up the dialog since it was just created.
dp.SetTitle("What do you want for Christmas?")
tb := NewTextbox(dp, "msg-txt")
tb.SetIsRequired(true)
dp.AddButton("For Me", "forme", &ButtonOptions{
IsPrimary: true,
Validates: true,
//OnClick:action.Do(p.ID(), ForMeAction), // You can handle button actions this way
})
dp.AddButton("For You", "foryou", &ButtonOptions{
Validates: true,
//OnClick:action.Do(p.ID(), ForYouAction),
})
dp.AddCloseButton("Cancel", "cancel")
dp.OnButton(action.Do().ID(MessageAction)) // or handle button actions this way
} else {
GetTextboxI(p, "msg-txt").SetText("") // reset the text in case it was just hidden
}
dp.Show()
case MessageAction:
// A dialog button was pressed
btnID := a.EventValueString()
switch btnID {
case "forme":
GetPanel(p, "result").SetText("You want to get a " + GetTextboxI(p, "msg-txt").Text())
case "foryou":
GetPanel(p, "result").SetText("You want to give a " + GetTextboxI(p, "msg-txt").Text())
}
dp, _ := GetDialogPanel(p, "msg-dlg")
dp.Hide()
}
}
func init() {
page.RegisterControl(&DialogsPanel{})
}