-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
form.go
122 lines (106 loc) · 1.91 KB
/
form.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package form
import (
"github.com/GoAdminGroup/go-admin/modules/db"
)
type Type uint8
const (
Default Type = iota
Text
SelectSingle
Select
IconPicker
SelectBox
File
Password
RichText
Datetime
Radio
Email
Url
Ip
Color
Currency
Number
TextArea
)
func (t Type) String() string {
switch t {
case Default:
return "default"
case Text:
return "text"
case SelectSingle:
return "select_single"
case Select:
return "select"
case IconPicker:
return "iconpicker"
case SelectBox:
return "selectbox"
case File:
return "file"
case Password:
return "password"
case RichText:
return "richtext"
case Datetime:
return "datetime"
case Radio:
return "radio"
case Email:
return "email"
case Url:
return "url"
case Ip:
return "ip"
case Color:
return "color"
case Currency:
return "currency"
case Number:
return "number"
case TextArea:
return "textarea"
default:
panic("wrong form type")
}
}
func (t Type) IsSelect() bool {
return t == Select || t == SelectSingle || t == SelectBox
}
func (t Type) IsRadio() bool {
return t == Radio
}
func GetFormTypeFromFieldType(typeName db.DatabaseType, fieldName string) string {
if fieldName == "password" {
return "form.Password"
}
if fieldName == "id" {
return "form.Default"
}
if fieldName == "ip" {
return "form.Ip"
}
if fieldName == "Url" {
return "form.Url"
}
if fieldName == "email" {
return "form.Email"
}
if fieldName == "color" {
return "form.Color"
}
if fieldName == "money" {
return "form.Currency"
}
switch typeName {
case db.Int, db.Tinyint, db.Int4, db.Integer, db.Mediumint, db.Smallint,
db.Numeric, db.Smallserial, db.Serial, db.Bigserial, db.Money, db.Bigint:
return "form.Number"
case db.Text, db.Longtext, db.Mediumtext, db.Tinytext:
return "form.RichText"
case db.Datetime, db.Date, db.Time, db.Timestamp, db.Timestamptz, db.Year:
return "form.Datetime"
}
return "form.Text"
}