-
Notifications
You must be signed in to change notification settings - Fork 6
/
form_base.go
87 lines (73 loc) · 2.57 KB
/
form_base.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
package control
import (
"context"
"fmt"
"github.com/goradd/goradd/pkg/orm/db"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/action"
"github.com/goradd/goradd/pkg/page/event"
"strings"
)
const (
databaseProfileAction = iota + 10000
)
// The FormBase is the control that all Form objects should include, and is the master container for all other goradd controls.
type FormBase struct {
page.ΩFormBase
}
// NewMockForm creates a form that should be used as a parent of a control when unit testing the control.
func NewMockForm() *FormBase {
f := &FormBase{}
f.ΩFormBase.Init(nil, f, "", "MockFormId")
return f
}
// Init initializes the FormBase. Call this before adding other controls.
func (f *FormBase) Init(ctx context.Context, self page.FormI, path string, id string) {
// Most of the FormBase code is in page.ΩFormBase. The code below specifically adds popup windows and controls
// to all standard forms, mostly for debug and development purposes.
f.ΩFormBase.Init(ctx, self, path, id)
if db.IsProfiling(ctx) {
btn := NewButton(f, "grProfileButton")
btn.SetText("SQL Profile <i class='fas fa-arrow-circle-down' ></i>")
btn.SetTextIsHtml(true)
btn.On(event.Click(), action.Ajax(f.ID(), databaseProfileAction))
btn.SetShouldAutoRender(true)
panel := NewPanel(f, "grProfilePanel")
panel.SetShouldAutoRender(true)
panel.SetTextIsHtml(true)
panel.SetVisible(false)
}
/* TODO: Add a dialog and designer click if in design mode
if (defined('QCUBED_DESIGN_MODE') && QCUBED_DESIGN_MODE == 1) {
// Attach custom event to dialog to handle right click menu items sent by form
$dlg = new Q\ModelConnector\EditDlg ($objClass, 'qconnectoreditdlg');
$dlg->addAction(
new Q\Event\On('qdesignerclick'),
new Q\Action\Ajax ('ctlDesigner_Click', null, null, 'ui')
);
}
*/
}
func (f *FormBase) Action(ctx context.Context, a page.ActionParams) {
switch a.ID {
case databaseProfileAction:
if f.Page().HasControl("grProfilePanel") {
c := f.Page().GetControl("grProfilePanel")
if c.IsVisible() {
c.SetVisible(false)
} else {
c.SetVisible(true)
var s string
if profiles := db.GetProfiles(ctx); profiles != nil {
for _, profile := range profiles {
dif := profile.EndTime.Sub(profile.BeginTime)
sql := strings.Replace(profile.Sql, "\n", "<br />", -1)
s += fmt.Sprintf(`<p class="profile"><div>Time: %s Begin: %s End: %s</div><div>%s</div></p>`,
dif.String(), profile.BeginTime.Format("3:04:05.000"), profile.EndTime.Format("3:04:05.000"), sql)
}
}
c.SetText(s)
}
}
}
}