2022-10-31 09:18:36 +01:00
|
|
|
package screen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NewTask struct {
|
|
|
|
fields []*FormField
|
|
|
|
commands chan interface{}
|
2022-10-31 15:59:58 +01:00
|
|
|
show chan ShowRequest
|
2022-10-31 09:18:36 +01:00
|
|
|
root *fyne.Container
|
|
|
|
}
|
|
|
|
|
2022-10-31 15:59:58 +01:00
|
|
|
func NewNewTask(commands chan interface{}, show chan ShowRequest) *NewTask {
|
2022-10-31 09:18:36 +01:00
|
|
|
fields := []*FormField{}
|
|
|
|
for _, f := range [][2]string{
|
|
|
|
{"action", "action"},
|
|
|
|
{"project", "project"},
|
|
|
|
{"due", "due string"},
|
|
|
|
{"recur", "recur string"},
|
|
|
|
} {
|
|
|
|
fields = append(fields, NewFormField(f[0], f[1]))
|
|
|
|
}
|
|
|
|
|
|
|
|
newTask := &NewTask{
|
|
|
|
fields: fields,
|
|
|
|
commands: commands,
|
|
|
|
show: show,
|
|
|
|
}
|
|
|
|
newTask.Init()
|
|
|
|
|
|
|
|
return newTask
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nt *NewTask) Init() {
|
|
|
|
taskForm := widget.NewForm()
|
|
|
|
for _, f := range nt.fields {
|
|
|
|
w := widget.NewEntry()
|
|
|
|
w.Bind(f.Value)
|
|
|
|
taskForm.Append(f.Label, w)
|
|
|
|
}
|
|
|
|
|
|
|
|
taskForm.SubmitText = "save"
|
|
|
|
taskForm.OnSubmit = nt.Save
|
2022-10-31 15:59:58 +01:00
|
|
|
taskForm.CancelText = "cancel"
|
|
|
|
taskForm.OnCancel = nt.Cancel
|
2022-10-31 09:18:36 +01:00
|
|
|
taskForm.Enable()
|
|
|
|
nt.clearForm()
|
|
|
|
|
|
|
|
nt.root = container.NewBorder(
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
taskForm,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nt *NewTask) Save() {
|
|
|
|
req := SaveNewTaskRequest{
|
|
|
|
Fields: map[string]string{},
|
|
|
|
}
|
|
|
|
for _, f := range nt.fields {
|
|
|
|
req.Fields[f.Key] = f.GetValue()
|
|
|
|
}
|
|
|
|
nt.commands <- req
|
2022-10-31 15:59:58 +01:00
|
|
|
nt.show <- ShowRequest{Screen: "tasks"}
|
2022-10-31 09:18:36 +01:00
|
|
|
|
|
|
|
nt.clearForm()
|
|
|
|
}
|
|
|
|
|
2022-10-31 15:59:58 +01:00
|
|
|
func (nt *NewTask) Cancel() {
|
|
|
|
nt.show <- ShowRequest{Screen: "tasks"}
|
|
|
|
}
|
|
|
|
|
2022-10-31 09:18:36 +01:00
|
|
|
func (nt *NewTask) clearForm() {
|
|
|
|
for _, f := range nt.fields {
|
|
|
|
f.SetValue("")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nt *NewTask) Refresh(_ State) {}
|
|
|
|
|
|
|
|
func (nt *NewTask) Content() *fyne.Container {
|
|
|
|
return nt.root
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nt *NewTask) Hide() {
|
|
|
|
nt.root.Hide()
|
|
|
|
}
|
|
|
|
|
2022-10-31 15:59:58 +01:00
|
|
|
func (nt *NewTask) Show(_ Task) {
|
2022-10-31 09:18:36 +01:00
|
|
|
nt.root.Show()
|
|
|
|
}
|