]> git.plutz.net Git - serve0/blob - templates/advfilter.html.sh
split up functions in filter box generator
[serve0] / templates / advfilter.html.sh
1 # Copyright 2014,2015 Paul Hänsch
2 #
3 # This file is part of Serve0
4
5 # Serve0 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 # Serve0 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 Serve0  If not, see <http://www.gnu.org/licenses/>. 
17
18 quicklinks(){
19   output=''
20   tac ${_DATA}/meta/recent |while [ "$(echo "$output" |wc -l)" -lt 10 ] && read line; do
21     line="<a href="$line">$line</a>"
22     echo "$output" |grep -qF "$line" || output="$output$line\n"
23   done
24   echo $output
25 }
26
27 list_categories(){
28   echo none
29   printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u
30 }
31
32 category_selected(){
33   cat="$1"
34   filter="$2"
35
36   printf %s "$taglist" \
37   | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \
38   | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \
39   | sed 's;^0 ;<option>;;s;^1 ;<option selected>;;s;$;</option>;'
40 }
41
42 category_tabs(){
43   for cat in "$@"; do
44   cat <<EOF
45     <div class="tab">
46     <input class="tabhandle" type="radio" name="category$n" id="cat${n}_$cat" value="$cat" $([ "$cat" = "$fcat" ] && echo checked)>
47     <label class="category tabhandle" for="cat${n}_$cat">$([ "$cat" = none ] && printf %s general || printf %s "$cat")</label>
48     <select class="category tabcontent" class="input tagfilter" name="cfilter${n}_" size="12" multiple>
49       $([ "$cat" = none ] && category_selected "" "$filter" || category_selected "${cat}:" "$filter")
50     </select>
51     </div>
52 EOF
53   done
54 }
55
56 filterbox(){
57   n=$1
58   filter="$(printf '%s^' "$filters" |cut -d^ -f$(($n+1)))"
59   fneg="${filter%%[a-zA-Z]*}"
60   filter="${filter#!}"
61   fcat="${filter%%:*}"
62   [ "$fcat" = "$filter" ] && fcat=none
63   
64   debug "fneg: $fneg    fcat: $fcat     filter: $filter"
65   
66   cat <<EOF
67   <input class="tabhandle" type="checkbox" id="filter$n" $([ $n = 0 -o -n "$filter" ] && echo checked) >
68   <label class="tabhandle filter" for="filter$n">+ and</label>
69   <div class="tabcontent filter">
70     <input type="radio" name="type$n" value="pos" id="pos$n" ${fneg:-checked} ><label for="pos$n" class="conjunction">Any</label>
71     <input type="radio" name="type$n" value="neg" id="neg$n" ${fneg:+checked} ><label for="neg$n" class="conjunction">None</label>
72     <span class="help">of the items selected here:</span>
73   
74     <label class="category">Category:</label>
75     <div class="category tabcontainer">
76       $(category_tabs $(list_categories) )
77     </div>
78   </div>
79 EOF
80 }
81
82 cat <<EOF
83   <form class="panel" id="advfilter"
84         action="?action=filter" method="post" accept-charset="UTF-8">
85     <input disabled type="text" name="s" value="$search" placeholder="Search">
86     <label for="o2" class="order">Order by:</label>
87     <select disabled class="order" size="1" name="o" id="o2">
88       <option>Name</option>
89       <option>Date</option>
90       <option>Length</option>
91     </select>
92     <input disabled type="submit" name="submit" value="Find">
93
94     <a class="panel clearsearch" href="?">Clear All</a>
95     <a class="panel advanced hide" href="#">Hide</a>
96     <hr>
97
98     <p class="help">Up to <strong>10</strong> filter boxes will appear as you start selecting tags. You can select <strong>multiple</strong> tags in each box by holding down the <strong>Ctrl</strong>-key. Click the "<strong>Filter!</strong>" button when you are ready.</p>
99     $(for n in {0..9}; do filterbox "$n"; done)
100
101     <p class="filter final">
102       <label for="o3" class="order">Order by:</label>
103       <select class="edit order" size="1" name="o" id="o3">
104         <option $([ "$_GET[\"o\"]" = Name ] && echo selected) >Name</option>
105         <option $([ "$_GET[\"o\"]" = Date ] && echo selected) >Date</option>
106         <option $([ "$_GET[\"o\"]" = Length ] && echo selected) >Length</option>
107       </select>
108       <input type="submit" value="Filter!">
109     </p>
110
111     <p class="quicklinks">
112       <label class="quicklinks">Most recent</label>
113       $(quicklinks)
114     </p>
115   </form>
116 EOF
117
118 # vi:set filetype=html: