]> git.plutz.net Git - confetti/blob - templates/categories.html.sh
e266e1f24e18b704208433cc843619b0614e8bc0
[confetti] / templates / categories.html.sh
1 # Copyright 2015, 2017 Paul Hänsch
2 #
3 # This file is part of Confetti.
4
5 # Confetti is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9
10 # Confetti is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Affero General Public License for more details.
14
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
17
18 cat_listing(){
19   list_categories | while read cat; do
20     printf '<li>%s<button type="submit" name="remove" value="%s">%s</button></li>\n' \
21            "$(htmlsafe "$cat")" "$(attribsafe "$cat")" "$(l10n cat_remove)"
22   done
23 }
24
25 list_catsel(){
26   card="$1"
27   cats="$(get_categories "$card")"
28
29   list_categories |while read cat; do
30     printf '<li><label><input %s type="checkbox" name="%s" value="%s">%s</label></li>' \
31            "$(printf %s "$cats" |grep -qF "$cat" && printf 'checked="checked"')" \
32            "$(attribsafe "$card")" "$(attribsafe "$cat")" "$(htmlsafe "$cat")" 
33   done
34 }
35
36 display_catsel(){
37   card="$1"
38   printf '<li><h2>%s</h2><ul>' "$(htmlsafe "$(get_name "$card")")"
39   list_catsel "$card"
40   printf '</ul></li>'
41 }
42
43 cat <<EOF
44 <form class="categories" action="?action=edit_categories" method="POST">
45   <h1>$(l10n categories_label)</h1>
46   <input type="hidden" name="page" value="categories"/>
47   <ul>
48     $(cat_listing)
49     <li>
50       <input type="text" name="newcat" placeholder="$(l10n cat_newlabel)">
51       <button type="submit" name="add" value="add">$(l10n cat_add)</button>
52     </li>
53   </ul>
54 </form>
55
56 <form class="namelist" action="?action=update_categories" method="POST">
57   <fieldset>
58     <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
59   </fieldset>
60   <ul class="namelist">
61 EOF
62 listcards \
63 | while read card; do
64   display_catsel "$card"
65 done
66 cat <<EOF
67   </ul>
68   <fieldset>
69     <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
70   </fieldset>
71 </form>
72 EOF
73