]> git.plutz.net Git - lobster/commitdiff
interface for combined filters
authorpaul <paul@plutz.net>
Fri, 13 Oct 2017 10:34:37 +0000 (10:34 +0000)
committerpaul <paul@plutz.net>
Fri, 13 Oct 2017 10:34:37 +0000 (10:34 +0000)
svn path=/trunk/; revision=157

actions/filter_card.sh
pages/cards.sh
static/cards.css
templates/cards.html.sh
templates/text_cards.sh

index b5ce333aa85c91db928833abb94f6347ca7efdc7..cc0f9127e404fbbaf52ba752ad97d4545dc70ddc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/zsh
 
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2017 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 
 cgi_post
 
-case "${_POST[choice]}"; in
-  new_filter)
-    for n in '' {0..100}; do
-      debug "N: $n; ${_POST[filter$n]}"
-      [ -z "${_POST[filter$n]+x}" ] && break
-      filterval="${_POST[filter$n]}"
-      filtertype="${_POST[filtertype$n]}"
-      filter="${filtertype}:${filterval}${filter+^${filter}}"
-    done
-    order="${_POST[order]}"
-    echo -n "Location: ?p=cards&filter=$filter&filtertype=advanced&order=$order\n\n"
-    ;;
-  #new_filter)
-  #  filter="${_POST[filter]}"
-  #  filtertype="${_POST[filtertype]}"
-  #  order="${_POST[order]}"
-  #  echo -n "Location: ?p=cards&filter=$filter&filtertype=$filtertype&order=$order\n\n"
-  #  ;;
-  *)
-    echo -n "Location: ?p=cards\n\n"
-    ;;
-esac
+if [ "${_POST[choice]}" = new_filter ]; then
+  filter="$(
+    for n in filter{0..100}; do
+      # [ -z "${_POST[$n]:+x}" ] && break
+      printf %s "${_POST[$n]}"
+    done \
+    | sed -r 's;\|+;\|;g; s;\^+;\^;g; s;:\|;:;g; :X; s;\^[^:]*:\^;\^;g; /\^[^:]*:\^/bX; s;^\^;;; s;\^[^:]*:$;;;'
+  )"
+  printf 'Location: ?p=cards&order=%s&filter=%s\n\n' "${_POST[order]}" "$filter"
+else
+  printf 'Location: ?p=cards\n\n'
+fi
index 506022ff727bcd9ba0507f9945806c093394456a..b836f6b63cd450db45f7704fc0151e2dcfe1be24 100755 (executable)
@@ -76,7 +76,7 @@ listcards() {
            *:*) expr="${each%%:*}"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
              *) expr="(${each})";;
     esac
-    filterex='/(^|\n)'"${expr}"'/{'"${filterex}"'}'
+    filterex='/(^|\n)'"${expr}"'/I{'"${filterex}"'}'
   done
 
   for file in "${_DATA}/vcard/"*.vcf; do
index 002e66b7edd691992204d34108dcf9e90a117b1e..981a667e217e69876d4f24170ddabedefff137c4 100644 (file)
@@ -1,5 +1,5 @@
 /*
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
@@ -66,7 +66,8 @@
 
 .filter fieldset.item { padding-left: 0; }
 .filter fieldset.item legend { display: none; }
-.filter fieldset.item input[type=text] {
+.filter fieldset.item input[type=text],
+.filter fieldset.item fieldset.categories {
   background-color: #FFF;
   border: 1px solid #000;
   margin-top: -1px;
   border: 1px solid #000;
   border-bottom-color: #FFF;
 }
+.filter fieldset.item input[type=radio][value="CATEGORIES:"]:checked + label + input[type=text],
+.filter fieldset.item input[type=radio][value="CATEGORIES:"] + label + input[type=text] + fieldset.categories {
+  display: none;
+}
+.filter fieldset.item input[type=radio][value="CATEGORIES:"]:checked + label + input[type=text] + fieldset.categories {
+  display: block;
+}
+.filter fieldset.item fieldset.categories a {
+  font-size: .875em;
+  line-height: 1.625em;
+  color: #44C;
+}
 
 .newcard {
   display: block;
index 377ccf8ebe478e39e3083e699cfed30dcc6014a8..bf84eee2eb4109452354c111421c817eef84a495 100755 (executable)
@@ -1,4 +1,4 @@
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
 #
 # 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/>. 
 
+setchecked() {
+  printf 'checked="checked"'
+}
 check_type(){
-  #[ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"'
-  [ "${_GET[filter]%%:*}" = "$1" ] && echo 'checked="checked"'
+  [ "${_GET[filter]%%:*}" = "$1" ] && setchecked
 }
 check_order(){
-  [ "${_GET[order]}" = "$1" ] && echo 'checked="checked"'
+  [ "${_GET[order]}" = "$1" ] && setchecked
 }
 
+filter_item() {
 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">
-  <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>
     }
--->
-
-    <input type="text" name="filter" value="${_GET[filter]#*:}" placeholder="$(l10n filter_placeholder)"/>
+    -->
   </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>
index be2efa77541bfb214d04add7d1c5e23cf34734e2..aaa68324160b99054317eb5ba98590c56b3718ee 100755 (executable)
@@ -93,6 +93,7 @@ item_name[label_join]="Anm."
 item_name[label_leave]="Abm."
 
 item_name[edit]="Bearbeiten"
+item_name[edit_categories]="Kategorien Bearbeiten"
 item_name[vcf_export]="Vcard Exportieren"
 item_name[control]="Aktionen"
 item_name[edit_update]="Daten übernehmen"