summaryrefslogtreecommitdiff
path: root/forms.go
diff options
context:
space:
mode:
authorJan Dittberner <jan@dittberner.info>2017-04-19 00:05:42 +0200
committerJan Dittberner <jan@dittberner.info>2017-04-22 00:12:38 +0200
commitbc194e8943bdec58ef462e393ef2a8a59d928718 (patch)
tree1d0ecdfe5c2eb131437ced9dfd2ec44484ad3763 /forms.go
parentcc0f5c0b7b931440704bc31a858d52ae92585616 (diff)
downloadcacert-boardvoting-bc194e8943bdec58ef462e393ef2a8a59d928718.tar.gz
cacert-boardvoting-bc194e8943bdec58ef462e393ef2a8a59d928718.tar.xz
cacert-boardvoting-bc194e8943bdec58ef462e393ef2a8a59d928718.zip
Implement motion editing
Diffstat (limited to 'forms.go')
-rw-r--r--forms.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/forms.go b/forms.go
index f3cd942..503e7e5 100644
--- a/forms.go
+++ b/forms.go
@@ -54,3 +54,45 @@ func (f *NewDecisionForm) Validate() (bool, *Decision) {
return len(f.Errors) == 0, data
}
+
+type EditDecisionForm struct {
+ Title string
+ Content string
+ VoteType string
+ Due string
+ Decision *Decision
+ Errors map[string]string
+}
+
+func (f *EditDecisionForm) Validate() (bool, *Decision) {
+ f.Errors = make(map[string]string)
+
+ data := f.Decision
+
+ data.Title = strings.TrimSpace(f.Title)
+ if len(data.Title) < 3 {
+ f.Errors["Title"] = "Please enter at least 3 characters."
+ }
+
+ data.Content = strings.TrimSpace(f.Content)
+ if len(strings.Fields(data.Content)) < 3 {
+ f.Errors["Content"] = "Please enter at least 3 words."
+ }
+
+ if voteType, err := strconv.ParseUint(f.VoteType, 10, 8); err != nil || (voteType != 0 && voteType != 1) {
+ f.Errors["VoteType"] = fmt.Sprint("Please choose a valid vote type", err)
+ } else {
+ data.VoteType = VoteType(uint8(voteType))
+ }
+
+ if dueDuration, ok := validDueDurations[f.Due]; !ok {
+ f.Errors["Due"] = "Please choose a valid due date"
+ } else {
+ year, month, day := time.Now().UTC().Add(dueDuration).Date()
+ data.Due = time.Date(year, month, day, 23, 59, 59, 0, time.UTC)
+ }
+
+ data.Modified = time.Now().UTC()
+
+ return len(f.Errors) == 0, data
+}