X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=248749535423255dba66c7144dffb1d6f9061f8b;hb=2cfdff52842b5c1ac1a4c42289f5bc67328d01d1;hp=02f7cb2a9fe86f21f05540a49dfee59150158b89;hpb=856d7b3c7823e768e4ad468ff2203fde3838e861;p=webpoll diff --git a/widgets.sh b/widgets.sh index 02f7cb2..2487495 100755 --- a/widgets.sh +++ b/widgets.sh @@ -12,7 +12,12 @@ selected(){ } w_month() { - local month="$1" selected="$2" + # Arguments: + # 1. (optional) Name of select box, default "date" + # 2. (optional) Month to display in format: YYYY-MM, default current month + # 3. (optional) Day to preselect in format: DD, default none + + local input="${1:-date}" month="$2" selected="$3" local dow dom days n=1 Y m d V w B if [ $month ]; then read Y m d V w B<<-EOF @@ -52,9 +57,15 @@ w_month() { dow=$(( (w - d + 35 + dom ) % 7)) [ $dow = 1 -o $dom = 1 ] && printf '[tr [th .weekno . %i]' $V [ $dom = 1 ] && while [ $n -lt $(( ($dow + 6) % 7 + 1)) ]; do printf '[td ]'; n=$((n + 1)); done - printf '[td [label [input type=radio name=date value="%04i-%02i-%02i" %s] %i]]' $Y $m $dom "$(checked $dom $selected)" $dom + date="$(printf "%04i-%02i-%02i" $Y $m $dom)" + 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" [ $dow = 0 ] && printf ']\n' [ $dow = 0 ] && V=$(( V % 53 + 1)) done + if [ $dow -le 6 ]; then + while [ $dow -le 6 ]; do printf '[td ]'; dow=$((dow + 1)) ; done + printf ']\n' + fi printf ']]' }