]> git.plutz.net Git - serve0/blob - widgets.sh
some restructuring
[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   fakemp4="$(COOKIE fakemp4)"
29   mode="$(COOKIE mode)"
30   printf '
31   [form #prefs method="POST" action="?a=setprefs"
32     [a href="#" x]
33     [hidden "ref" "%s"]
34     [label for=prefs_ps Pagesize]
35     [input #prefs_ps type=number name=pagesize value="%s"][br]
36     [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br]
37     [radio "mode" "index"  %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br]
38     [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br]
39     [submit "store" "store" Set Cookie]
40   ]
41   ' \
42   "$(HTML "$REQUEST_URI")" "$LISTSIZE" \
43   "$([ "$mode" = index ] || printf checked)" \
44   "$([ "$mode" = index ] && printf checked)" \
45   "$([ "$fakemp4" = yes    ] && printf checked)"
46 }
47
48 w_index(){
49   [ -d "$_DATA/$ITEM/.index" ] || printf '
50   [form #index method="POST" action="?a=spawnindex"
51     [hidden "ref" "%s"]
52     [label Set up for Index view: ]
53     [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories]
54     [submit "spawn" "spawn" Set up]
55   ]
56   ' "$(HTML "$REQUEST_URI")"
57 }
58
59 w_tagging(){
60   printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$(HTML "$REQUEST_URI")"
61   printf '[a href="#" Hide][br]'
62
63   printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags"
64   printf %s "$w_tags" |grep -vF ":" |grep -vxF '' \
65   | while read -r tag; do
66     printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
67   done
68   printf ']]'
69
70   printf %s "$w_tags" |cut -sd: -f1 |sort -u \
71   | while read -r category; do
72     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")"
73     printf %s "$w_tags" |grep -wF "${category}" \
74     | while read -r tag; do
75       printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")"
76     done
77     printf ']]'
78   done
79
80   printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]'
81 }