forked from bakape/shamichan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
forms.go
62 lines (51 loc) · 1.41 KB
/
forms.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
// Renders various HTML forms
package templates
import (
"reflect"
"strings"
"meguca/config"
"meguca/lang"
)
type boardList struct {
Boards config.BoardTitles
Lang lang.Pack
}
type formSpecs struct {
Specs []inputSpec
Lang lang.Pack
}
// ConfigureBoard renders a form for setting board configurations
func ConfigureBoard(conf config.BoardConfigs, ln lang.Pack) string {
v := reflect.ValueOf(conf)
return configurationTable(v, "configureBoard", false, ln)
}
func configurationTable(
v reflect.Value,
key string,
needCaptcha bool,
ln lang.Pack,
) string {
// Copy over all spec structs, so the mutations don't affect them
noValues := specs[key]
withValues := make([]inputSpec, len(noValues))
copy(withValues, noValues)
// Assign values to all specs
for i, s := range withValues {
v := v.FieldByName(strings.Title(s.ID))
switch k := v.Kind(); k {
case reflect.Uint8, reflect.Uint16:
v = v.Convert(reflect.TypeOf(uint(0)))
}
withValues[i].Val = v.Interface()
}
return tableForm(withValues, needCaptcha, ln)
}
// ConfigureServer renders the form for changing server configurations
func ConfigureServer(conf config.Configs, ln lang.Pack) string {
v := reflect.ValueOf(conf)
return configurationTable(v, "configureServer", false, ln)
}
// ChangePassword renders a form for changing an account's password
func ChangePassword(ln lang.Pack) string {
return tableForm(specs["changePassword"], true, ln)
}