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