]> git.plutz.net Git - serve0/blob - widgets.sh
starting interface for advanced search
[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   printf '[form #advsearch action=?a=advsearch method=POST
64             [a href="#" Hide]
65             [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.[br]
66             Refine the search further by setting additional search tags using the [strong "+and"] button.]
67             [hidden "ref" "%s"]
68          ' "$w_refuri"
69
70   for n in 1 2 3 4 5 6 7 8 9 10; do
71     lbid="$(HTML "cat_${n}_(none)")"
72     printf '[input .and type=checkbox name=and id="and_%i"][label for="and_%i" +and
73             ][fieldset .select
74             [input .pol type="radio" name=pol_%i id="pol_pos_%i"][label for=pol_pos_%i Any]
75             [input .pol type="radio" name=pol_%i id="pol_neg_%i"][label for=pol_neg_%i None]
76             [label .head Category:]
77             [input .cat type=radio name="cat_%i" id="%s" ][label for="%s" %s]
78             [select name=tag_%s size=10 multiple' \
79             $n $n $n $n $n $n $n $n \
80             $n "$lbid" "$lbid" "(none)" $n
81     printf %s "$w_tags" |grep -vF ":" \
82     | while read -r tag; do
83       [ ! "$tag" ] && continue
84       printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
85     done
86     printf ']'
87     printf %s "$w_tags" |cut -sd: -f1 |sort -u \
88     | while read -r category; do
89       lbid="$(HTML "cat_${n}_${category}")"
90       printf '[input .cat type=radio name="cat_%i" id="%s" [label for="%s" %s]]
91               [select name=tag_%s size=10 multiple' $n "$lbid" "$lbid" "$(HTML "$category")" $n
92       printf %s "$w_tags" |grep -wF "${category}" \
93       | while read -r tag; do
94         tag="$(HTML "$tag")"; tn="${tag#*:}"
95         printf '[option value="%s" %s]' "$tag" "$tn"
96       done
97       printf ']'
98     done
99     printf ']'
100   done
101
102   printf ']'
103 }
104
105 w_tagging(){
106   local tag category
107   printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri"
108   printf '[a href="#" Hide][br]'
109
110   printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags"
111   printf %s "$w_tags" |grep -vF ":" \
112   | while read -r tag; do
113     [ ! "$tag" ] && continue
114     printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
115   done
116   printf ']]'
117
118   printf %s "$w_tags" |cut -sd: -f1 |sort -u \
119   | while read -r category; do
120     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")"
121     printf %s "$w_tags" |grep -wF "${category}" \
122     | while read -r tag; do
123       tag="$(HTML "$tag")"; tn="${tag#*:}"
124       printf '[option value="%s" %s]' "$tag" "$tn"
125     done
126     printf ']]'
127   done
128
129   printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]'
130 }