Compare commits
3 Commits
04e66d7888
...
81927e9017
Author | SHA1 | Date | |
---|---|---|---|
81927e9017 | |||
88560a8fbf | |||
301d035425 |
@ -36,18 +36,19 @@
|
||||
</form>
|
||||
</header>
|
||||
<form method=post action="container?id={{ .Container.Id }}">
|
||||
<textarea name=description
|
||||
rows="{{ max 5 (lines .Container.Description) }}"
|
||||
{{- $description := or .NewDescription .Container.Description }}
|
||||
<textarea name=description rows="{{ max 5 (lines $description) }}"
|
||||
placeholder="Popis obalu nebo jeho obsahu">
|
||||
{{- .Container.Description -}}
|
||||
{{- $description -}}
|
||||
</textarea>
|
||||
<footer>
|
||||
<div>
|
||||
<label for=series>Řada:</label>
|
||||
<select name=series id=series>
|
||||
{{- $preselect := or .NewSeries .Container.Series }}
|
||||
{{- range $prefix, $desc := .AllSeries }}
|
||||
<option value="{{ $prefix }}"
|
||||
{{ if eq $prefix $.Container.Series }}selected{{ end -}}
|
||||
{{ if eq $prefix $preselect }}selected{{ end -}}
|
||||
>{{ $prefix }} — {{ $desc }}</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
@ -55,7 +56,7 @@
|
||||
<div>
|
||||
<label for=parent>Nadobal:</label>
|
||||
<input type=text name=parent id=parent
|
||||
value="{{ .Container.Parent }}">
|
||||
value="{{ or .NewParent .Container.Parent }}">
|
||||
</div>
|
||||
<input type=submit value="Uložit">
|
||||
</footer>
|
||||
@ -69,21 +70,27 @@
|
||||
<h2>Nový obal</h2>
|
||||
</header>
|
||||
<form method=post action="container">
|
||||
<textarea name=description rows=5
|
||||
placeholder="Popis obalu nebo jeho obsahu"></textarea>
|
||||
{{- $description := or .NewDescription "" }}
|
||||
<textarea name=description rows="{{ max 5 (lines $description) }}"
|
||||
placeholder="Popis obalu nebo jeho obsahu">
|
||||
{{- $description -}}
|
||||
</textarea>
|
||||
<footer>
|
||||
<div>
|
||||
<label for=series>Řada:</label>
|
||||
<select name=series id=series>
|
||||
{{- $preselect := or .NewSeries "" }}
|
||||
{{- range $prefix, $desc := .AllSeries }}
|
||||
<option value="{{ $prefix }}"
|
||||
{{ if eq $prefix $preselect }}selected{{ end -}}
|
||||
>{{ $prefix }} — {{ $desc }}</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for=parent>Nadobal:</label>
|
||||
<input type=text name=parent id=parent value="">
|
||||
<input type=text name=parent id=parent
|
||||
value="{{ or .NewParent "" }}">
|
||||
</div>
|
||||
<input type=submit value="Uložit">
|
||||
</footer>
|
||||
|
@ -205,6 +205,13 @@ func dbContainerCreate(c *Container) error {
|
||||
}
|
||||
|
||||
func dbContainerUpdate(c *Container, updated Container) error {
|
||||
if _, ok := indexSeries[updated.Series]; !ok {
|
||||
return errNoSuchSeries
|
||||
}
|
||||
if updated.Parent != "" && indexContainer[updated.Parent] == nil {
|
||||
return errNoSuchContainer
|
||||
}
|
||||
|
||||
newID := updated.Id()
|
||||
if updated.Series != c.Series && len(c.Children()) > 0 {
|
||||
return errCannotChangeSeriesNotEmpty
|
||||
|
@ -116,14 +116,13 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
if r.Method == http.MethodPost {
|
||||
if err = handleContainerPost(r); err == nil {
|
||||
redirect := "container"
|
||||
redirect := r.URL.EscapedPath()
|
||||
if shownId != "" {
|
||||
redirect += "?id=" + url.QueryEscape(shownId)
|
||||
}
|
||||
http.Redirect(w, r, redirect, http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
// TODO: Use the last data as a prefill.
|
||||
} else if r.Method != http.MethodGet {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
@ -134,14 +133,6 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
|
||||
allSeries[s.Prefix] = s.Description
|
||||
}
|
||||
|
||||
var container *Container
|
||||
children := indexChildren[""]
|
||||
|
||||
if c, ok := indexContainer[ContainerId(shownId)]; ok {
|
||||
children = c.Children()
|
||||
container = c
|
||||
}
|
||||
|
||||
params := struct {
|
||||
Error error
|
||||
ErrorNoSuchSeries bool
|
||||
@ -152,6 +143,9 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
|
||||
ErrorWouldContainItself bool
|
||||
ErrorContainerInUse bool
|
||||
Container *Container
|
||||
NewDescription *string
|
||||
NewSeries string
|
||||
NewParent *string
|
||||
Children []*Container
|
||||
AllSeries map[string]string
|
||||
}{
|
||||
@ -163,10 +157,24 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
|
||||
ErrorCannotChangeNumber: err == errCannotChangeNumber,
|
||||
ErrorWouldContainItself: err == errWouldContainItself,
|
||||
ErrorContainerInUse: err == errContainerInUse,
|
||||
Container: container,
|
||||
Children: children,
|
||||
Children: indexChildren[""],
|
||||
AllSeries: allSeries,
|
||||
}
|
||||
if c, ok := indexContainer[ContainerId(shownId)]; ok {
|
||||
params.Children = c.Children()
|
||||
params.Container = c
|
||||
}
|
||||
if description, ok := r.Form["description"]; ok {
|
||||
params.NewDescription = &description[0]
|
||||
}
|
||||
if series, ok := r.Form["series"]; ok {
|
||||
// It seems impossible to dereference strings in text/template so that
|
||||
// `eq` can be used, and we don't actually need a null value here.
|
||||
params.NewSeries = series[0]
|
||||
}
|
||||
if parent, ok := r.Form["parent"]; ok {
|
||||
params.NewParent = &parent[0]
|
||||
}
|
||||
|
||||
executeTemplate("container.tmpl", w, ¶ms)
|
||||
}
|
||||
@ -198,7 +206,7 @@ func handleSeries(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
if r.Method == http.MethodPost {
|
||||
if err = handleSeriesPost(r); err == nil {
|
||||
http.Redirect(w, r, "series", http.StatusSeeOther)
|
||||
http.Redirect(w, r, r.URL.EscapedPath(), http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
// XXX: This is rather ugly.
|
||||
|
Loading…
x
Reference in New Issue
Block a user