]> git.plutz.net Git - serve0/blob - widgets.sh
enabled complete filter reuse
[serve0] / widgets.sh
1 #!/bin/sh
2
3 [ -n "$include_widgets" ] && return 0
4 include_widgets="$0"
5
6 . "$_EXEC/cgilite/storage.sh"
7
8 w_refuri="$(HTML "$REQUEST_URI")"
9 w_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \
10         | xargs -r0 cut -f4 \
11         | cut -d= -f2- |tr , '\n' | sort -u)"
12 w_tags="$(UNSTRING "$w_tags")"
13
14 w_search(){
15   printf '
16   [form #search method=GET action=?
17     [select name=o size=1 
18       [option disabled=disabled Order By]
19       [option value=Name Name]
20       [option value=Date Date]
21       [option value=Length Length]
22     ]
23     [input name=s placeholder=Search value="%s"]
24   ]
25   ' \
26   "$(HTML "$SEARCH")"
27 }
28
29 w_prefs(){
30   local fakemp4 mode
31   fakemp4="$(COOKIE fakemp4)"
32   mode="$(COOKIE mode)"
33   printf '
34   [form #prefs method="POST" action="?a=setprefs"
35     [a href="#" x]
36     [hidden "ref" "%s"]
37     [label for=prefs_ps Pagesize]
38     [input #prefs_ps type=number name=pagesize value="%s"][br]
39     [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br]
40     [radio "mode" "index"  %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br]
41     [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br]
42     [submit "store" "store" Set Cookie]
43   ]
44   ' \
45   "$w_refuri" "$LISTSIZE" \
46   "$([ "$mode" = index ] || printf checked)" \
47   "$([ "$mode" = index ] && printf checked)" \
48   "$([ "$fakemp4" = yes    ] && printf checked)"
49 }
50
51 w_index(){
52   [ -d "$_DATA/$ITEM/.index" ] || printf '
53   [form #index method="POST" action="?a=spawnindex"
54     [hidden "ref" "%s"]
55     [label Set up for Index view: ]
56     [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories]
57     [submit "spawn" "spawn" Set up]
58   ]
59   ' "$w_refuri"
60 }
61
62 w_advsearch(){
63   local n lbid tag category tn filter f
64   filter="${FILTER}^"
65
66   printf '[form #advsearch action=?a=advsearch method=POST
67             [a href="#" Hide]
68             [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.[br]
69             Refine the search further by setting additional search tags using the [strong "+and"] button.]
70             [hidden "ref" "%s"]
71          ' "$w_refuri"
72
73   for n in 1 2 3 4 5 6 7 8 9 10; do
74     f="${filter%%^*}"; filter="${filter#*^}"
75
76     lbid="$(HTML "cat_${n}_(none)")"
77     printf '[input .and type=checkbox name=and id="and_%i" %s][label for="and_%i" +and
78             ][fieldset .select
79             [input .pol type="radio" name=pol_%i %s id="pol_pos_%i"][label for=pol_pos_%i Any]
80             [input .pol type="radio" name=pol_%i %s id="pol_neg_%i"][label for=pol_neg_%i None]
81             [label .head Category:]
82             [input .cat type=radio name="cat_%i" %s id="%s" ][label for="%s" %s]
83             [select name=tag_%s size=10 multiple="multiple"' \
84             $n "$([ "$f" ] && printf 'checked="checked"')" $n \
85             $n "$([ "$f" -a \! "${f%%~*}" ] || printf 'checked="checked"')" $n $n \
86             $n "$([ "$f" -a \! "${f%%~*}" ] && printf 'checked="checked"')" $n $n \
87             $n "$([ "$f" = "${f%:*}" ] && printf 'checked="checked"')" "$lbid" "$lbid" "(none)" \
88             $n
89
90     f="|${f#~}|"
91     printf %s "$w_tags" |grep -vF ":" \
92     | while read -r tag; do
93       [ ! "$tag" ] && continue
94       tg="$(HTML "$tag")"
95       printf '[option %s value="%s" %s]' \
96         "$([ "$f" != "${f%|${tag}|*}" ] && printf 'selected="selected"')" \
97         "$tg" "$tg"
98     done
99     printf ']'
100     printf %s "$w_tags" |cut -sd: -f1 |sort -u \
101     | while read -r category; do
102       lbid="$(HTML "cat_${n}_${category}")"
103       printf '[input .cat type=radio name="cat_%i" %s id="%s"][label for="%s" %s]
104               [select name=tag_%s size=10 multiple="multiple"' \
105               $n "$([ "$f" != "${f%|${category}:*}" ] && printf 'checked="checked"')" \
106               "$lbid" "$lbid" "$(HTML "$category")" $n
107       printf %s "$w_tags" |grep -wF "${category}" \
108       | while read -r tag; do
109         tg="$(HTML "$tag")"; tn="${tg#*:}"
110         printf '[option %s value="%s" %s]' \
111           "$([ "$f" != "${f%|${tag}|*}" ] && printf 'selected="selected"')" \
112           "$tg" "$tn"
113       done
114       printf ']'
115     done
116     printf ']'
117   done
118
119   printf ']'
120 }
121
122 w_tagging(){
123   local tag category
124   printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri"
125   printf '[a href="#" Hide][br]'
126
127   printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags"
128   printf %s "$w_tags" |grep -vF ":" \
129   | while read -r tag; do
130     [ ! "$tag" ] && continue
131     printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
132   done
133   printf ']]'
134
135   printf %s "$w_tags" |cut -sd: -f1 |sort -u \
136   | while read -r category; do
137     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")"
138     printf %s "$w_tags" |grep -wF "${category}" \
139     | while read -r tag; do
140       tag="$(HTML "$tag")"; tn="${tag#*:}"
141       printf '[option value="%s" %s]' "$tag" "$tn"
142     done
143     printf ']]'
144   done
145
146   printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]'
147 }