]> git.plutz.net Git - confetti/blob - templates/categories.html.sh
75223bb856eb50242442287ae8386ec1312ead2b
[confetti] / templates / categories.html.sh
1 # Copyright 2015, 2017, 2018 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   <input type="submit" class="fakeorder" name="add" value="add" />
46   <h1>$(l10n categories_label)</h1>
47   <input type="hidden" name="page" value="categories"/>
48   <ul>
49     $(cat_listing)
50     <li>
51       <input type="text" name="newcat" placeholder="$(l10n cat_newlabel)">
52       <button type="submit" name="add" value="add">$(l10n cat_add)</button>
53     </li>
54   </ul>
55 </form>
56
57 <form class="namelist" action="?action=update_categories" method="POST">
58   <fieldset>
59     <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
60   </fieldset>
61   <ul class="namelist">
62 EOF
63 listcards \
64 | while read card; do
65   display_catsel "$card"
66 done
67 cat <<EOF
68   </ul>
69   <fieldset>
70     <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
71   </fieldset>
72 </form>
73 EOF
74