]> git.plutz.net Git - confetti/blob - courses/widgets.sh
stubs for rewrite of courses section
[confetti] / courses / widgets.sh
1 # Copyright 2014, 2019 Paul Hänsch
2 #
3 # This file is part of Confetti.
4
5 # Confetti is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9
10 # Confetti is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Affero General Public License for more details.
14
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
17
18 check(){
19   [ "$1" = "$2" ] && printf 'checked="checked"'
20 }
21
22 edit="$(GET e)"
23 order="$(GET o |grep -m1 -xE 'DOW|TOD')"
24
25 w_sort_courses(){
26   cat <<-EOF
27         [form .sort .search action="?" method="GET"
28           [span .label $(l10n sort_order):]
29           [radio "order" "DOW" $(check $order DOW) $(l10n order_DOW)]
30           [radio "order" "TOD" $(check $order TOD) $(l10n order_TOD)]
31           [submit "" "" $(l10n order_apply)]
32         ]
33         EOF
34 }
35
36 cal_date(){
37   { [ $# -eq 0 ] && cat || printf %s "$*"; } |sed -rnE '
38     2q
39     s/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/\1-\2-\3 \4:\5:\6 UTC/p;t
40     s/^TZID=(.+)\:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$/TZ="\1" \2-\3-\4 \5:\6:\7/p;t
41     s/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$/\1-\2-\3 \4:\5:\6/p;t
42   '
43 }
44
45 cal_item(){
46   local course="$1"
47   local item cnt c
48   shift 1
49
50   for item in $@; do
51     cnt="$(pdi_count "$course" "$item")"
52
53     case $item in
54       SUMMARY)
55         printf '[h2 &shy%s]' "$(pdi_value "$course" SUMMARY)"
56         ;;
57       DTSTART)
58         printf '[span .text .DTSTART %s %s ]' \
59                "$(date -d "$(pdi_value "$course" DTSTART |cal_date)" '+%A %B %d, %Y - %H:%M')" \
60                "$(l10n t_oclock)"
61         ;;
62       RRULE)
63         dts_date="$(pdi_value "$course" DTSTART |cal_date)"
64         rrule=" $(pdi_value "$course" RRULE)"
65         rr_int="${rrule##*INTERVAL=}"; rr_int="${rr_int%%;*}"
66         rr_count="${rrule##*COUNT=}"; rr_count="${rr_count%%;*}"
67         rr_freq="${rrule##*FREQ=}"; rr_freq="${rr_freq%%;*}"
68         rr_until="${rrule##*UNTIL=}"; rr_until="${rr_until%%;*}"
69         rr_until="$(cal_date "${rr_until}")"
70
71         [ "$rr_int" -eq 1 ] \
72         && printf '[span .text .RRULE %s]' "$(l10n "s$rr_freq")" \
73         || printf '[span .text .RRULE %s %s %s]' "$(l10n t_every)" "${rr_int}" "$(l10n $rr_freq)"
74         case "$rrule $rr_freq" in
75           *COUNT*DAILY*)
76             printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) day" "+%A %B %d, %Y - %H:%M")"
77             ;;
78           *COUNT*WEEKLY*)
79             printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) week" "+%A %B %d, %Y - %H:%M")"
80             ;;
81           *COUNT*MONTHLY*)
82             printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) month" "+%A %B %d, %Y - %H:%M")"
83             ;;
84           *COUNT*YEARLY*)
85             printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) year" "+%A %B %d, %Y - %H:%M")"
86             ;;
87           *UNTIL*)
88             printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$rr_until" "+%A %B %d, %Y - %H:%M")"
89             ;;
90         esac
91         ;;
92       attendance);;
93       COMMENT)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
94         seq 1 $cnt |while read c; do
95           printf '[p .item .%s &shy;%s]' "$item" \
96                  "$(pdi_value "$course" "$item" $c |unescape |HTML)"
97         done
98         ;;
99       *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
100         seq 1 $cnt |while read c; do
101           printf '[span .item .%s &shy;%s]' "$item" \
102                  "$(pdi_value "$course" "$item" $c |unescape |HTML)"
103         done
104         ;;
105     esac
106   done
107 }
108
109 edit_item(){
110   local card="$1"
111   local item cnt c
112   shift 1
113
114   for item in $@; do
115     cnt="$(pdi_count "$card" "$item")"
116     [ $cnt -lt 1 ] && cnt=1
117
118     case $item in
119       N)N="$(pdi_value "$card" N)"
120         if [ "$N" ]; then
121           IFS=\; read n1 n2 n3 n4 n5 <<-EOF
122                 $N
123                 EOF
124         else
125           N="$(pdi_value "$card" FN |unescape)"
126           n1="${N%%[a-z]*}" n1="${N#$n1}"
127           [ "$n1" ] || n1="${N##* }"
128           n2="${N%$n1}"
129         fi
130         printf '
131         [h3 %s]
132         [input .item .N name="4N" placeholder="%s" value="%s"]
133         [input .item .N name="2N" placeholder="%s" value="%s"]
134         [input .item .N name="1N" placeholder="%s" value="%s"]
135         [input .item .N name="5N" placeholder="%s" value="%s"]
136         ' "$(l10n "$item")" \
137         "$(l10n n_pre)"   "$(HTML "$n4")" \
138         "$(l10n n_first)" "$(HTML "$n2" "$n3")" \
139         "$(l10n n_last)"  "$(HTML "$n1")" \
140         "$(l10n n_post)"  "$(HTML "$n5")"
141         ;;
142       GENDER)
143         gender="$(pdi_value "$card" GENDER)"
144         printf '
145         [select .item .GENDER name="GENDER"
146           [option value="" disabled="disabled" %s %s]
147           [option value="female" %s %s]
148           [option value="male"   %s %s]
149           [option value="other"  %s %s]
150           [option value="none"   %s %s]
151         ]\n' \
152         "$([ "$gender" = ''       ] && printf 'selected="selected"')" "$(l10n GENDER)" \
153         "$([ "$gender" = 'female' ] && printf 'selected="selected"')" "$(l10n gender_female)" \
154         "$([ "$gender" = 'male'   ] && printf 'selected="selected"')" "$(l10n gender_male)" \
155         "$([ "$gender" = 'other'  ] && printf 'selected="selected"')" "$(l10n gender_other)" \
156         "$([ "$gender" = 'none'   ] && printf 'selected="selected"')" "$(l10n gender_none)"
157         ;;
158       BDAY|X-ZACK-JOINDATE|X-ZACK-LEAVEDATE)
159         printf '[h3 %s]
160         [input .item .%s name="%s" value="%s" placeholder="YYYY-MM-DD"]' \
161         "$(l10n "$item")" "$item" "$item" "$(pdi_value "$card" "$item" |grep -xE '[0-9-]+')"
162         ;;
163       ADR|NOTE)
164         printf '[h3 %s]' "$(l10n "$item")"
165         seq 1 $cnt |while read c; do
166           printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
167             "$item" $c "$item" $c "$item" $c "$(l10n delete)"
168           printf '<textarea class="item %s" name="%s">%s</textarea>' \
169             "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)"
170         done
171         printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
172         ;;
173       TEL) printf '[h3 %s]' "$(l10n "$item")"
174         seq 1 $cnt |while read c; do
175           printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
176             "$item" $c "$item" $c "$item" $c "$(l10n delete)"
177           teltype="$(pdi_attrib "$card" TEL $c TYPE)"
178           printf '[select .item .teltype name="teltype"
179                     [option value="" disabled="disabled" %s %s]
180                     [option value="HOME" %s %s]
181                     [option value="WORK" %s %s]
182                     [option value="CELL" %s %s]
183                     [option value="FAX"  %s %s]
184                   ]\n' \
185                   "$([ "$teltype" = ''     ] && printf 'selected="selected"')" "$(l10n teltype)" \
186                   "$([ "$teltype" = 'HOME' ] && printf 'selected="selected"')" "$(l10n TYPE=HOME)" \
187                   "$([ "$teltype" = 'WORK' ] && printf 'selected="selected"')" "$(l10n TYPE=WORK)" \
188                   "$([ "$teltype" = 'CELL' ] && printf 'selected="selected"')" "$(l10n TYPE=CELL)" \
189                   "$([ "$teltype" = 'FAX'  ] && printf 'selected="selected"')" "$(l10n TYPE=FAX)"
190
191           printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
192             "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
193         done
194         printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
195         ;;
196       *)printf '[h3 %s]' "$(l10n "$item")"
197         seq 1 $cnt |while read c; do
198           printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
199             "$item" $c "$item" $c "$item" $c "$(l10n delete)"
200           printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
201             "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
202         done
203         printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
204         ;;
205     esac
206   done
207 }