-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_add_field.go
45 lines (38 loc) · 1.03 KB
/
view_add_field.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
package main
import (
"github.com/rivo/tview"
"log"
)
// TODO: Implement coming back by pressing Esc
var addFieldForm *tview.Form
var fieldTemplate string
var fieldValue string
var fieldsTemplNames []string
func GetAddFieldScreen() (form *tview.Form) {
fieldsTemplNamesStr, err := oxi.GetTemplatesItems()
if err != nil {
log.Println(err.Error())
}
for _, templItem := range fieldsTemplNamesStr {
fieldsTemplNames = append(fieldsTemplNames, templItem.Name)
}
fieldsTemplNames = append(fieldsTemplNames, "Empty (without template)")
addFieldForm = tview.NewForm().
AddDropDown("Field template", fieldsTemplNames, 0, func(_ string, ind int) {
FieldTemplateChanged(ind)
}).
AddInputField("Field value", "", 16, nil, FieldValueChanged).
AddButton("Save Field", func() {
NavToMain(cViewFields)
}).
AddButton("Back", func() {
NavToMain(cViewFields)
})
return addFieldForm
}
func FieldTemplateChanged(ind int) {
fieldTemplate = fieldsTemplNames[ind]
}
func FieldValueChanged(fValue string) {
fieldValue = fValue
}