]> git.plutz.net Git - serve0/blobdiff - widgets.sh
some restructuring
[serve0] / widgets.sh
index fd9e72e938a165b0087559528010b672985382a7..dc16b30e0396f5244d8446b630b06b3dd6f5bcc9 100644 (file)
@@ -1,5 +1,14 @@
 #!/bin/sh
 
+[ -n "$include_widgets" ] && return 0
+include_widgets="$0"
+
+. "$_EXEC/cgilite/storage.sh"
+
+w_tags="$(find "$_DATA/" -path '*/.index/meta' -exec cut -f4 '{}' + \
+        | cut -d= -f2- |tr , '\n' | sort -u)"
+w_tags="$(UNSTRING "$w_tags")"
+
 w_search(){
   printf '
   [form #search method=GET action=?
@@ -12,20 +21,61 @@ w_search(){
     [input name=s placeholder=Search value="%s"]
   ]
   ' \
-  "$(HTML "$search")"
+  "$(HTML "$SEARCH")"
 }
 
 w_prefs(){
+  fakemp4="$(COOKIE fakemp4)"
+  mode="$(COOKIE mode)"
   printf '
   [form #prefs method="POST" action="?a=setprefs"
+    [a href="#" x]
     [hidden "ref" "%s"]
     [label for=prefs_ps Pagesize]
     [input #prefs_ps type=number name=pagesize value="%s"][br]
+    [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br]
+    [radio "mode" "index"  %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br]
     [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br]
     [submit "store" "store" Set Cookie]
   ]
   ' \
-  "$(HTML "$REQUEST_URI")" \
-  "$(COOKIE pagesize |grep -m1 -xE '[0-9]+' || printf 50)" \
-  "$(COOKIE fakemp4 |grep -m1 -qx yes && printf checked)"
+  "$(HTML "$REQUEST_URI")" "$LISTSIZE" \
+  "$([ "$mode" = index ] || printf checked)" \
+  "$([ "$mode" = index ] && printf checked)" \
+  "$([ "$fakemp4" = yes    ] && printf checked)"
+}
+
+w_index(){
+  [ -d "$_DATA/$ITEM/.index" ] || printf '
+  [form #index method="POST" action="?a=spawnindex"
+    [hidden "ref" "%s"]
+    [label Set up for Index view: ]
+    [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories]
+    [submit "spawn" "spawn" Set up]
+  ]
+  ' "$(HTML "$REQUEST_URI")"
+}
+
+w_tagging(){
+  printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$(HTML "$REQUEST_URI")"
+  printf '[a href="#" Hide][br]'
+
+  printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags"
+  printf %s "$w_tags" |grep -vF ":" |grep -vxF '' \
+  | while read -r tag; do
+    printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
+  done
+  printf ']]'
+
+  printf %s "$w_tags" |cut -sd: -f1 |sort -u \
+  | while read -r category; do
+    printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")"
+    printf %s "$w_tags" |grep -wF "${category}" \
+    | while read -r tag; do
+      printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")"
+    done
+    printf ']]'
+  done
+
+  printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]'
 }