From 5736fc8f634020a8a32635e955c3a0d823499f42 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 14 Nov 2016 09:59:37 +0000 Subject: [PATCH] unification of card editing functions svn path=/trunk/; revision=145 --- pages/cards.sh | 11 +++ templates/edit_attendee.sh | 190 +++++++++++++++++++++++-------------- templates/edit_client.sh | 116 +++++++++++----------- 3 files changed, 187 insertions(+), 130 deletions(-) diff --git a/pages/cards.sh b/pages/cards.sh index f6142df..2d1d4e2 100755 --- a/pages/cards.sh +++ b/pages/cards.sh @@ -20,8 +20,16 @@ BR=' ' +force_items(){ + for each in "$@"; do + [ -z "${values[$each]+x}" ] && values[${each}]='' + done +} + case $PROFILE in medical) + SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL) + FORCE_ITEMS=(ADR TEL EMAIL NOTE X-CLIENT-REFERRAL) view_card="$_EXEC/templates/view_client.sh" edit_card="$_EXEC/templates/edit_client.sh" _GET[order]="${_GET[order]:-lastname}" @@ -29,6 +37,8 @@ medical) profile_medical=x ;; circus) + SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE) + FORCE_ITEMS=(BDAY X-ZACK-JOINDATE TEL EMAIL ADR NOTE) view_card="$_EXEC/templates/view_attendee.sh" edit_card="$_EXEC/templates/edit_attendee.sh" _GET[order]="${_GET[order]:-firstname}" @@ -258,5 +268,6 @@ edit_card() { #Parameter: Cardfile declare -A values vcf_parse "$cardfile" + force_items $FORCE_ITEMS . $edit_card } diff --git a/templates/edit_attendee.sh b/templates/edit_attendee.sh index e27592c..820bce8 100755 --- a/templates/edit_attendee.sh +++ b/templates/edit_attendee.sh @@ -15,14 +15,70 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . +setchecked() { + printf 'checked="checked"' +} +setselected() { + printf 'selected="selected"' +} check_gen() { - [ "$values[GENDER]" = "$1" ] && echo 'selected="selected"' + [ "$values[GENDER]" = "$1" ] && setselected } check_a() { - egrep -q "^${1}.${id}$" "$_DATA/mappings/attendance" && echo 'checked="checked"' + egrep -q "^${1}.${id}$" "$_DATA/mappings/attendance" && setchecked +} +teltype() { + cat <<-EOF + + EOF } -SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE) +list_items(){ + item="$1" + placeholder="$2" + [ -n "${values[$item]+x}" ] && printf '

%s

\n' "$(l10n $item)" + for n in "$item" "$item"{0..100}; do + if [ -n "${values[$n]+x}" ]; then + case "$item" in + (ADR|NOTE) + printf '\n' \ + "$item" "$item" "$(htmlsafe ${values[$n]})" + ;; + (TEL) + teltype "${values[${n}_TYPE]}" + printf '\n' \ + "$item" "$item" "$(attribsafe ${values[$n]})" + ;; + (*) + printf '\n' \ + "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder" + ;; + esac + else + break + fi + done +} + +list_section(){ + printf '
' "$1" + shift 1 + for each in $@; do + list_items "$each" + done + printf '
' +} + +hi_company="${values[X-HEALTH-INSURANCE+1]}" + hi_number="${values[X-HEALTH-INSURANCE+2]}" + hi_status="${values[X-HEALTH-INSURANCE+3]}" [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)" @@ -44,82 +100,78 @@ cat <$(l10n gender_other) +END_HTML - $(for n in NICKNAME NICKNAME{0..10}; do - echo "${values[$n]+}" - done) - -

$(l10n BDAY)

- - -

$(l10n X-ZACK-JOINDATE)

- - $(if [ -n "$values[X-ZACK-LEAVEDATE]" ]; then - echo '

'$(l10n X-ZACK-LEAVEDATE)'

' - echo ' ' - fi) - - $(if [ -n "$values[SOUND]" ]; then - echo ' ' - fi) - ${values[PHOTO]+} - ${values[LOGO]+} - + for n in NICKNAME NICKNAME{0..100}; do + [ -z "${values[$n]+x}" ] && break \ + || printf ' + + ' "$(attribsafe ${values[$n]})" "$(l10n NICKNAME)" + done -
-

$(l10n TEL)

- - $(for n in TEL{0..10}; do - echo "${values[$n]+}" - done) -
+ list_items BDAY YYYY-MM-DD + list_items X-ZACK-JOINDATE YYYY-MM-DD + list_items X-ZACK-LEAVEDATE YYYY-MM-DD -
-

$(l10n EMAIL)

- - $(for n in EMAIL{0..10}; do - echo "${values[$n]+}" - done) - ${values[IMPP]+

$(l10n IMPP)

} - $(for n in IMPP IMPP{0..10}; do - echo "${values[$n]+}" - done) -
+ [ -n "$values[SOUND]" ] && printf ' + ' "$values[SOUND]" -
-

$(l10n ADR)

- - $(for n in ADR{0..10}; do - echo "${values[$n]+}" - done) - ${values[URL]+

$(l10n URL)

} - $(for n in URL URL{0..10}; do - echo "${values[$n]+}" - done) -
+ [ -n "$values[PHOTO]" ] && printf ' + + ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}" -
-

$(l10n NOTE)

- - $(for n in NOTE{0..10}; do - echo "${values[$n]+}" - done) -
+ [ -n "$values[LOGO]" ] && printf ' + + ' "${values[LOGO_TYPE]}" "${values[LOGO]}" -
-

$(l10n course_attendance)

- $(listcourses |while read each; do - cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")" - echo '' - done) -
+printf '' + +if [ "$PROFILE" = circus ]; then + list_section phone TEL + list_section message EMAIL IMPP URL + list_section address ADR + list_section note NOTE X-CLIENT-REFERRAL + cat <<-END_HTML +
+

$(l10n course_attendance)

+ $(listcourses |while read each; do + cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")" + printf '' \ + "$(attribsafe "$each")" "$(check_a "$each")" "$(htmlsafe "$cname")" + done) +
+ END_HTML +elif [ "$PROFILE" = medical ]; then + list_section address ADR + list_section phone TEL EMAIL IMPP URL + cat <<-END_HTML +
+

$(l10n X-HEALTH-INSURANCE)

+ + + + + +
+ END_HTML + list_section note NOTE X-CLIENT-REFERRAL +fi + +cat < diff --git a/templates/edit_client.sh b/templates/edit_client.sh index b2331aa..f2c5afb 100755 --- a/templates/edit_client.sh +++ b/templates/edit_client.sh @@ -40,17 +40,36 @@ teltype() { EOF } -n_last="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){0} *([^;]*).*$:\2:p')" -n_first="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){1} *([^;]*).*$:\2:p')" -n_middle="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){2} *([^;]*).*$:\2:p')" -n_pre="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){3} *([^;]*).*$:\2:p')" -n_post="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){4} *([^;]*)*$:\2:p')" - -hi_company="$(printf %s "${values[X-HEALTH-INSURANCE]}" |cut -d\; -f1)" -hi_number="$(printf %s "${values[X-HEALTH-INSURANCE]}" |cut -d\; -f2)" -hi_status="$(printf %s "${values[X-HEALTH-INSURANCE]}" |cut -d\; -f3)" +list_items(){ + item="$1" + placeholder="$2" + [ -n "${values[$item]+x}" ] && printf '

%s

\n' "$(l10n $item)" + for n in "$item" "$item"{0..100}; do + if [ -n "${values[$n]+x}" ]; then + case "$item" in + (ADR|NOTE) + printf '\n' \ + "$item" "$item" "$(htmlsafe ${values[$n]})" + ;; + (TEL) + teltype "${values[${n}_TYPE]}" + printf '\n' \ + "$item" "$item" "$(attribsafe ${values[$n]})" + ;; + (*) + printf '\n' \ + "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder" + ;; + esac + else + break + fi + done +} -SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL) +hi_company="${values[X-HEALTH-INSURANCE+1]}" +hi_number= "${values[X-HEALTH-INSURANCE+2]}" +hi_status= "${values[X-HEALTH-INSURANCE+3]}" [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)" @@ -59,11 +78,11 @@ cat <

$(l10n N)

- - - - - + + + + + }" + printf %s\\n "${values[$n]+}" done) -

$(l10n BDAY)

- + $(list_items BDAY YYYY-MM-DD) + + $(list_items X-ZACK-JOINDATE YYYY-MM-DD) + $(list_items X-ZACK-LEAVEDATE YYYY-MM-DD) - $(if [ -n "$values[SOUND]" ]; then - echo ' ' - fi) - ${values[PHOTO]:+} - ${values[LOGO]:+} + $([ -n "$values[SOUND]" ] && printf ' + ' "$values[SOUND]" + ) + ${values[PHOTO]+} + ${values[LOGO]+}
-

$(l10n ADR)

- - $(for n in ADR{0..10}; do - echo "${values[$n]:+}" - done) - ${values[URL]:+

$(l10n URL)

} - $(for n in URL URL{0..10}; do - echo "${values[$n]:+}" - done) + $(list_items ADR)
-

$(l10n TEL)

- $(teltype "${values[TEL_TYPE]}") - $(for n in TEL{0..10}; do - printf "${values[$n]:+$(teltype "${values[${n}_TYPE]}")}" - done) - -

$(l10n EMAIL)

- - $(for n in EMAIL{0..10}; do - printf "${values[$n]:+}" - done) - ${values[IMPP]:+

$(l10n IMPP)

} - $(for n in IMPP IMPP{0..10}; do - echo "${values[$n]:+}" - done) + $(list_items TEL) + $(list_items EMAIL) + $(list_items IMPP) + $(list_items URL)
@@ -138,27 +140,19 @@ cat <
-

$(l10n NOTE)

- - $(for n in NOTE{0..10}; do - echo "${values[$n]:+}" - done) -

$(l10n X-CLIENT-REFERRAL)

- - $(for n in X-CLIENT-REFERRAL{0..10}; do - echo "${values[$n]:+}" - done) + $(list_items NOTE) + $(list_items X-CLIENT-REFERRAL)
- +
-- 2.39.2