Partialy add new motion creation
parent
57e3d53245
commit
471daf12ea
@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var validDueDurations = map[string]time.Duration{
|
||||
"+3 days": time.Hour * 24 * 3,
|
||||
"+7 days": time.Hour * 24 * 7,
|
||||
"+14 days": time.Hour * 24 * 14,
|
||||
"+28 days": time.Hour * 24 * 28,
|
||||
}
|
||||
|
||||
type NewDecisionForm struct {
|
||||
Title string
|
||||
Content string
|
||||
VoteType string
|
||||
Due string
|
||||
Errors map[string]string
|
||||
}
|
||||
|
||||
func (f *NewDecisionForm) Validate() (bool, *Decision) {
|
||||
f.Errors = make(map[string]string)
|
||||
|
||||
data := &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)
|
||||
}
|
||||
|
||||
return len(f.Errors) == 0, data
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
{{ template "header" . }}
|
||||
<form action="/newmotion/" method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<td>ID:</td>
|
||||
<td>(generated on submit)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Proponent:</td>
|
||||
<td>{{ .Voter.Name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Proposed date/time:</td>
|
||||
<td>(auto filled to current date/time)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Title:</td>
|
||||
<td><input name="Title" value="{{ .Form.Title }}"/>
|
||||
{{ with .Form.Errors.Title }}
|
||||
<span class="error">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Text:</td>
|
||||
<td><textarea name="Content">{{ .Form.Content }}</textarea>
|
||||
{{ with .Form.Errors.Content }}
|
||||
<span class="error">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Vote type:</td>
|
||||
<td>
|
||||
<select name="VoteType">
|
||||
<option value="0"
|
||||
{{ if eq "0" .Form.VoteType }}selected{{ end }}>
|
||||
Motion
|
||||
</option>
|
||||
<option value="1"
|
||||
{{ if eq "1" .Form.VoteType }}selected{{ end }}>Veto
|
||||
</option>
|
||||
</select>
|
||||
{{ with .Form.Errors.VoteType }}
|
||||
<span class="error">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="2">Due:</td>
|
||||
<td>(autofilled from option below)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<select name="Due">
|
||||
<option value="+3 days">In 3 Days</option>
|
||||
<option value="+7 days">In 1 Week</option>
|
||||
<option value="+14 days">In 2 Weeks</option>
|
||||
<option value="+28 days">In 4 Weeks</option>
|
||||
</select>
|
||||
{{ with .Form.Errors.Due }}
|
||||
<span class="error">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td><input type="submit" value="Propose"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<a href="/motions/">Back to motions</a>
|
||||
{{ template "footer" . }}
|
Loading…
Reference in New Issue