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