Compare commits

...

4 Commits

3 changed files with 23 additions and 9 deletions

View File

@ -36,9 +36,9 @@
</header>
<form method=post action="container?id={{ .Container.Id }}">
<textarea name=description rows=5>
{{ .Container.Description }}
</textarea>
<textarea name=description rows="{{ max 5 (lines .Container.Description) }}"
placeholder="Popis obalu nebo jeho obsahu">
{{ .Container.Description }}</textarea>
<footer>
<div>
<label for=series>Řada:</label>

View File

@ -1,6 +1,6 @@
{{ define "Title" }}Tisk štítku{{ end }}
{{ define "Content" }}
<h2>Tisk štítku pro {{ .Id }}</h2>
<h2>Tisk štítku pro <a href="container?id={{ .Id }}">{{ .Id }}</a></h2>
{{ if .UnknownId }}
<p>Neznámý obal.

View File

@ -11,6 +11,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"time"
"janouch.name/sklad/imgutil"
@ -73,9 +74,9 @@ func handleLogout(w http.ResponseWriter, r *http.Request) {
func handleContainerPost(r *http.Request) error {
id := ContainerId(r.FormValue("id"))
description := r.FormValue("description")
description := strings.TrimSpace(r.FormValue("description"))
series := r.FormValue("series")
parent := ContainerId(r.FormValue("parent"))
parent := ContainerId(strings.TrimSpace(r.FormValue("parent")))
_, remove := r.Form["remove"]
if container, ok := indexContainer[id]; ok {
@ -150,8 +151,8 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
}
func handleSeriesPost(r *http.Request) error {
prefix := r.FormValue("prefix")
description := r.FormValue("description")
prefix := strings.TrimSpace(r.FormValue("prefix"))
description := strings.TrimSpace(r.FormValue("description"))
_, remove := r.Form["remove"]
if series, ok := indexSeries[prefix]; ok {
@ -333,6 +334,18 @@ func handle(w http.ResponseWriter, r *http.Request) {
}
}
var funcMap = template.FuncMap{
"max": func(i, j int) int {
if i > j {
return i
}
return j
},
"lines": func(s string) int {
return strings.Count(s, "\n") + 1
},
}
func main() {
// Randomize the RNG for session string generation.
rand.Seed(time.Now().UnixNano())
@ -355,7 +368,8 @@ func main() {
log.Fatalln(err)
}
for _, name := range m {
templates[name] = template.Must(template.ParseFiles("base.tmpl", name))
templates[name] = template.Must(template.New("base.tmpl").
Funcs(funcMap).ParseFiles("base.tmpl", name))
}
http.HandleFunc("/", handle)