From 503565a7be2813fcf8eba25c542b8e21d29c8d1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 16 Jul 2018 20:14:21 +0200 Subject: [PATCH] enabled complete filter reuse --- style.css | 2 ++ widgets.sh | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/style.css b/style.css index 05d278f..d735b8b 100644 --- a/style.css +++ b/style.css @@ -17,6 +17,8 @@ select { border: 1px solid; padding: .125em .5em; } +select[multiple] { padding: 0; } +select[multiple] option { padding: .25em .5em; } body { color: white; diff --git a/widgets.sh b/widgets.sh index 81807c0..158df4b 100644 --- a/widgets.sh +++ b/widgets.sh @@ -60,6 +60,9 @@ w_index(){ } w_advsearch(){ + local n lbid tag category tn filter f + filter="${FILTER}^" + printf '[form #advsearch action=?a=advsearch method=POST [a href="#" Hide] [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.[br] @@ -68,31 +71,45 @@ w_advsearch(){ ' "$w_refuri" for n in 1 2 3 4 5 6 7 8 9 10; do + f="${filter%%^*}"; filter="${filter#*^}" + lbid="$(HTML "cat_${n}_(none)")" - printf '[input .and type=checkbox name=and id="and_%i"][label for="and_%i" +and + printf '[input .and type=checkbox name=and id="and_%i" %s][label for="and_%i" +and ][fieldset .select - [input .pol type="radio" name=pol_%i id="pol_pos_%i"][label for=pol_pos_%i Any] - [input .pol type="radio" name=pol_%i id="pol_neg_%i"][label for=pol_neg_%i None] + [input .pol type="radio" name=pol_%i %s id="pol_pos_%i"][label for=pol_pos_%i Any] + [input .pol type="radio" name=pol_%i %s id="pol_neg_%i"][label for=pol_neg_%i None] [label .head Category:] - [input .cat type=radio name="cat_%i" id="%s" ][label for="%s" %s] - [select name=tag_%s size=10 multiple' \ - $n $n $n $n $n $n $n $n \ - $n "$lbid" "$lbid" "(none)" $n + [input .cat type=radio name="cat_%i" %s id="%s" ][label for="%s" %s] + [select name=tag_%s size=10 multiple="multiple"' \ + $n "$([ "$f" ] && printf 'checked="checked"')" $n \ + $n "$([ "$f" -a \! "${f%%~*}" ] || printf 'checked="checked"')" $n $n \ + $n "$([ "$f" -a \! "${f%%~*}" ] && printf 'checked="checked"')" $n $n \ + $n "$([ "$f" = "${f%:*}" ] && printf 'checked="checked"')" "$lbid" "$lbid" "(none)" \ + $n + + f="|${f#~}|" printf %s "$w_tags" |grep -vF ":" \ | while read -r tag; do [ ! "$tag" ] && continue - printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")" + tg="$(HTML "$tag")" + printf '[option %s value="%s" %s]' \ + "$([ "$f" != "${f%|${tag}|*}" ] && printf 'selected="selected"')" \ + "$tg" "$tg" done printf ']' printf %s "$w_tags" |cut -sd: -f1 |sort -u \ | while read -r category; do lbid="$(HTML "cat_${n}_${category}")" - printf '[input .cat type=radio name="cat_%i" id="%s" [label for="%s" %s]] - [select name=tag_%s size=10 multiple' $n "$lbid" "$lbid" "$(HTML "$category")" $n + printf '[input .cat type=radio name="cat_%i" %s id="%s"][label for="%s" %s] + [select name=tag_%s size=10 multiple="multiple"' \ + $n "$([ "$f" != "${f%|${category}:*}" ] && printf 'checked="checked"')" \ + "$lbid" "$lbid" "$(HTML "$category")" $n printf %s "$w_tags" |grep -wF "${category}" \ | while read -r tag; do - tag="$(HTML "$tag")"; tn="${tag#*:}" - printf '[option value="%s" %s]' "$tag" "$tn" + tg="$(HTML "$tag")"; tn="${tg#*:}" + printf '[option %s value="%s" %s]' \ + "$([ "$f" != "${f%|${tag}|*}" ] && printf 'selected="selected"')" \ + "$tg" "$tn" done printf ']' done -- 2.39.2