]> git.plutz.net Git - serve0/blob - widgets.sh
minor optimisations
[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_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \
9         | xargs -r0 cut -f4 \
10         | cut -d= -f2- |tr , '\n' | sort -u)"
11 w_tags="$(UNSTRING "$w_tags")"
12
13 w_search(){
14   printf '
15   [form #search method=GET action=?
16     [select name=o size=1 
17       [option disabled=disabled Order By]
18       [option value=Name Name]
19       [option value=Date Date]
20       [option value=Length Length]
21     ]
22     [input name=s placeholder=Search value="%s"]
23   ]
24   ' \
25   "$(HTML "$SEARCH")"
26 }
27
28 w_prefs(){
29   local fakemp4 mode
30   fakemp4="$(COOKIE fakemp4)"
31   mode="$(COOKIE mode)"
32   printf '
33   [form #prefs method="POST" action="?a=setprefs"
34     [a href="#" x]
35     [hidden "ref" "%s"]
36     [label for=prefs_ps Pagesize]
37     [input #prefs_ps type=number name=pagesize value="%s"][br]
38     [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br]
39     [radio "mode" "index"  %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br]
40     [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br]
41     [submit "store" "store" Set Cookie]
42   ]
43   ' \
44   "$(HTML "$REQUEST_URI")" "$LISTSIZE" \
45   "$([ "$mode" = index ] || printf checked)" \
46   "$([ "$mode" = index ] && printf checked)" \
47   "$([ "$fakemp4" = yes    ] && printf checked)"
48 }
49
50 w_index(){
51   [ -d "$_DATA/$ITEM/.index" ] || printf '
52   [form #index method="POST" action="?a=spawnindex"
53     [hidden "ref" "%s"]
54     [label Set up for Index view: ]
55     [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories]
56     [submit "spawn" "spawn" Set up]
57   ]
58   ' "$(HTML "$REQUEST_URI")"
59 }
60
61 w_tagging(){
62   local tag category
63   printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$(HTML "$REQUEST_URI")"
64   printf '[a href="#" Hide][br]'
65
66   printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags"
67   printf %s "$w_tags" |grep -vF ":" |grep -vxF '' \
68   | while read -r tag; do
69     printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
70   done
71   printf ']]'
72
73   printf %s "$w_tags" |cut -sd: -f1 |sort -u \
74   | while read -r category; do
75     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")"
76     printf %s "$w_tags" |grep -wF "${category}" \
77     | while read -r tag; do
78       printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")"
79     done
80     printf ']]'
81   done
82
83   printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]'
84 }