X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=835e6463113dae536546a0124d96855f56763e75;hb=e59a6e2a6ebf4dbdd12d03cbd2ef91fd0acaad6d;hp=5e7132e169945579f4a3a88154dda4ad6fe99bd7;hpb=57b8376ada25742ac4d1078997bdeeeb20c56911;p=webpoll diff --git a/widgets.sh b/widgets.sh index 5e7132e..835e646 100755 --- a/widgets.sh +++ b/widgets.sh @@ -1,5 +1,20 @@ #!/bin/sh +export MD_HTML="false" +if [ "$(which awk)" ]; then + markdown() { awk -f "$_EXEC/cgilite/markdown.awk"; } +else + markdown() { busybox awk -f "$_EXEC/cgilite/markdown.awk"; } +fi + +dec(){ + local n + for n in "$@"; do + while [ "${n}" != "${n#0}" ]; do n="${n#0}"; done + printf %i\\n "$n" + done +} + checked(){ local check="$1"; shift 1; for comp in "$@"; do @@ -21,7 +36,7 @@ selected(){ w_month() { # Arguments: - # 1. (optional) select, multiple, none - default: select + # 1. (optional) select, multiple, submit, none - default: select # 2. (optional) Name of form field - default: "date" # 3. (optional) Month to display in format: YYYY-MM - default: current month # 4. (optional, multiple) Days to preselect in format: DD - default: none @@ -77,6 +92,11 @@ w_month() { printf '[td [input type=checkbox id="%s_%s" name="%s" value="%s" %s][label for="%s_%s" . %i]]' \ "$input" "$date" "$input" "$date" "$(checked $dom $selected)" "$input" "$date" "$dom" ;; + submit) + [ "$(checked $dom $selected)" ] \ + && printf '[td [submit "%s_remove" "%s" . %i][hidden "%s" "%s"]]' "$input" "$date" "$dom" "$input" "$date" \ + || printf '[td [submit "%s_add" "%s" . %i]]' "$input" "$date" "$dom" + ;; select|*) printf '[td [input type=radio id="%s_%s" name="%s" value="%s" %s][label for="%s_%s" . %i]]' \ "$input" "$date" "$input" "$date" "$(checked $dom $selected)" "$input" "$date" "$dom" @@ -94,3 +114,12 @@ w_month() { fi printf ']]' } + +dlist_timeofday() { + local step="${1:-15}" id="${2:-dlist_timeofday}" + printf '[datalist id="%s"\n' $id + for h in $(seq 0 23); do for m in $(seq 0 "$step" 59); do + printf '[option value="%i:%02i"]\n' $h $m + done; done + printf ']\n' +}