interface for combined filters
[confetti] / templates / cards.html.sh
index 377ccf8..bf84eee 100755 (executable)
@@ -1,4 +1,4 @@
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 #
 # This file is part of Confetti.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
+setchecked() {
+  printf 'checked="checked"'
+}
 check_type(){
 check_type(){
-  #[ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"'
-  [ "${_GET[filter]%%:*}" = "$1" ] && echo 'checked="checked"'
+  [ "${_GET[filter]%%:*}" = "$1" ] && setchecked
 }
 check_order(){
 }
 check_order(){
-  [ "${_GET[order]}" = "$1" ] && echo 'checked="checked"'
+  [ "${_GET[order]}" = "$1" ] && setchecked
 }
 
 }
 
+filter_item() {
 cat <<EOF
 cat <<EOF
-<form class="filter" action="?action=filter_card" method="POST">
-  <h1>$(l10n filter_label)</h1>
-  <input type="hidden" name="page" value="cards"/>
   <fieldset class="item">
   <fieldset class="item">
-  <legend>$(l10n filter_item):</legend>
-    <input  id="any" type="radio" name="filtertype" value="any" $(check_type any)>
-    <label for="any" >$(l10n filter_all)</label>
+    <legend>$(l10n filter_item):</legend>
+    <input type="hidden" name="filter${n}" value="^"/>
 
 
-    <input  id="name" type="radio" name="filtertype" value="name" $(check_type name)>
-    <label for="name">$(l10n filter_name)</label>
+    <input  id="any$n" type="radio" name="filter$((n + 1))" value="any:" $([ "$1" = any ] && setchecked)>
+    <label for="any$n" >$(l10n filter_all)</label>
 
 
-    <input  id="street" type="radio" name="filtertype" value="street" $(check_type street)>
-    <label for="street">$(l10n filter_street)</label>
+    <input  id="name$n" type="radio" name="filter$((n + 1))" value="name:" $([ "$1" = name ] && setchecked)>
+    <label for="name$n">$(l10n filter_name)</label>
 
 
-    <input  id="zip" type="radio" name="filtertype" value="zip" $(check_type zip)>
-    <label for="zip">$(l10n filter_zip)</label>
+    <!--
+    <input  id="adr$n" type="radio" name="filter$((n + 1))" value="ADR:" $([ "$1" = ADR ] && setchecked)>
+    <label for="adr$n">$(l10n ADR)</label>
+    -->
 
 
-    <input  id="telephone" type="radio" name="filtertype" value="TEL" $(check_type TEL)>
-    <label for="telephone">$(l10n filter_phone)</label>
+    <input  id="street$n" type="radio" name="filter$((n + 1))" value="street:" $([ "$1" = street ] && setchecked)>
+    <label for="street$n">$(l10n filter_street)</label>
 
 
-    <input  id="birth" type="radio" name="filtertype" value="BDAY" $(check_type BDAY)>
-    <label for="birth">$(l10n filter_birthyear)</label>
+    <input  id="zip$n" type="radio" name="filter$((n + 1))" value="zip:" $([ "$1" = zip ] && setchecked)>
+    <label for="zip$n">$(l10n filter_zip)</label>
 
 
-<!--
+    <input  id="telephone$n" type="radio" name="filter$((n + 1))" value="TEL:" $([ "$1" = TEL ] && setchecked)>
+    <label for="telephone$n">$(l10n filter_phone)</label>
+
+    <input  id="birth$n" type="radio" name="filter$((n + 1))" value="BDAY:" $([ "$1" = BDAY ] && setchecked)>
+    <label for="birth$n">$(l10n filter_birthyear)</label>
+
+    <input  id="cat$n" type="radio" name="filter$((n + 1))" value="CATEGORIES:" $([ "$1" = CATEGORIES ] && setchecked)>
+    <label for="cat$n">$(l10n CATEGORIES)</label>
+    <input type="text" name="filter$((n + 2))" value="$([ "$1" = CATEGORIES ] || attribsafe "$2")" placeholder="$(l10n filter_placeholder)"/>
+    <fieldset class="categories">
+      $(m=3
+        list_categories \
+        | while read cat; do
+          printf '<label><input type="checkbox" name="filter%i" value="|%s" %s/>%s</label>' \
+                 "$((n + m))" "$(attribsafe "$cat")" "$(printf %s "$cat" |grep -qEx "$2" && setchecked)" "$(htmlsafe "$cat")"
+          m=$((m + 1))
+        done
+      )
+      <a href="?p=categories">$(l10n edit_categories)</a>
+    </fieldset>
+
+    <!--
     ${profile_circus:+
     <input  id="course" type="radio" name="filtertype" value="course" $(check_type course)>
     <label for="course">$(l10n filter_course)</label>
     }
     ${profile_circus:+
     <input  id="course" type="radio" name="filtertype" value="course" $(check_type course)>
     <label for="course">$(l10n filter_course)</label>
     }
--->
-
-    <input type="text" name="filter" value="${_GET[filter]#*:}" placeholder="$(l10n filter_placeholder)"/>
+    -->
   </fieldset>
   </fieldset>
+EOF
+}
+
+cat <<EOF
+<form class="filter" action="?action=filter_card" method="POST">
+  <h1>$(l10n filter_label)</h1>
+  <input type="hidden" name="page" value="cards"/>
+
+  $(
+  n=0; m="$(list_categories |wc -l)"
+  printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \
+  | while read filter; do
+    [ -n "$filter" ] && filter_item "${filter%%:*}" "${filter#*:}" "$n"
+    n=$((n + 3 + m))
+  done
+  filter_item any '' "$n"
+  )
 
   <fieldset class="order">
     <legend>$(l10n filter_order):</legend>
 
   <fieldset class="order">
     <legend>$(l10n filter_order):</legend>