/
FileEchoCreateAction.go
82 lines (55 loc) · 1.69 KB
/
FileEchoCreateAction.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
package action
import (
"fmt"
widgets2 "github.com/vit1251/golden/internal/site/widgets"
"net/http"
)
type FileEchoCreateAction struct {
Action
}
func NewFileEchoCreateAction() *FileEchoCreateAction {
return new(FileEchoCreateAction)
}
func (self *FileEchoCreateAction) ServeHTTP(w http.ResponseWriter, r *http.Request) {
/* Render */
bw := widgets2.NewBaseWidget()
vBox := widgets2.NewVBoxWidget()
bw.SetWidget(vBox)
mmw := self.makeMenu()
vBox.Add(mmw)
container := widgets2.NewDivWidget()
container.SetClass("container")
containerVBox := widgets2.NewVBoxWidget()
container.AddWidget(containerVBox)
vBox.Add(container)
setupForm := widgets2.NewFormWidget().
SetMethod("POST").
SetAction("/file/create/complete")
/* Add custom param field */
setupFormBox := widgets2.NewVBoxWidget()
self.createInputField(setupFormBox, "fileecho", "File area name", "?")
setupFormBox.Add(widgets2.NewFormButtonWidget().SetTitle("Save").SetType("submit"))
setupForm.SetWidget(setupFormBox)
containerVBox.Add(setupForm)
if err := bw.Render(w); err != nil {
status := fmt.Sprintf("%+v", err)
http.Error(w, status, http.StatusInternalServerError)
return
}
}
func (self *FileEchoCreateAction) createInputField(box *widgets2.VBoxWidget, name string, summary string, value string) {
mainDiv := widgets2.NewDivWidget().
SetClass("form-group row")
mainDivBox := widgets2.NewVBoxWidget()
mainDiv.AddWidget(mainDivBox)
mainTitle := widgets2.NewDivWidget().
SetClass("col-sm-2 col-form-label").
SetContent(name)
mainDivBox.Add(mainTitle)
mainInput := widgets2.NewFormInputWidget().
SetTitle(summary).
SetName(name).
SetValue(value)
mainDivBox.Add(mainInput)
box.Add(mainDiv)
}